IsADirectoryError: [Errno 21] Is a directory ( in AudioSegment)

Saurabh Chandra Patel picture Saurabh Chandra Patel · Jan 11, 2018 · Viewed 13k times · Source

Script :

from pydub import AudioSegment
sound = AudioSegment.from_mp3("/srv/python/welcome.mp3")
sound.export("/srv/python/test", format="wav")

ERROR:

IsADirectoryError: [Errno 21] Is a directory: '/srv/python/test'

path /srv/python/test is exits with write permission (777) and /srv/python/welcome.mp3 is also exits

Answer

paxdiablo picture paxdiablo · Jan 11, 2018

As per the pydub docstring for the method you're using (my emphasis):

Export an AudioSegment to a file with given options

out_f (string): Path to destination audio file

the parameter is supposed to be a file.

You appear to have provided a directory as the argument, so you may want to change it to something like:

sound.export("/srv/python/test/actual_file_name.wav", format="wav")