0

I have been trying to create a desktop application that converts mp3 files to wav. However, when ever I choose a file I always receive the a filename error. Can someone help me?

file_path = askopenfilenames()

p = str(file_path)
os.path.normpath(p)


os.chdir(p)

audio_files = os.listdir()

for file in audio_files:
    #spliting the file into the name and the extension
    name, ext = os.path.splitext(file)
    if ext == ".mp3":
       mp3_sound = AudioSegment.from_mp3(file)
       mp3_sound = mp3_sound.set_channels(1)
       mp3_sound = mp3_sound.set_frame_rate(8000)
       #rename them using the old name + ".wav"
       mp3_sound.export("{0}.wav".format(name), format="wav",codec='pcm_mulaw')

print("Completed!")
Bob Doe
  • 1
  • 1
  • What is an example of an actual filename you are trying to use? (The output of `"{0}.wav".format(name)`) – CherryDT Feb 20 '22 at 17:53
  • An example would be sky.mp3 --> sky.wav however I get an issue stating that the filename, directory name or volume label syntax is incorrect: "('C:/Users/sid12/Desktop/Convert/sky.mp3',)" – Bob Doe Feb 20 '22 at 18:03
  • Please add the full error stack and an exact output of `print("{0}.wav".format(name))` into your question - and make sure the code you showed is 100% the same as is currently failing. The thing is that the error shows a tuple passed as name, but not only that but instead we also see `mp3` in there. So I would assume this happens if you pass some variable _other_ than `name` here, but that's not what the code shows. – CherryDT Feb 20 '22 at 18:08
  • If you actually LOOKED at the full traceback message, you'd see that the code is failing long before anything related to .MP3 conversion - you're taking a tuple of filenames (that's what `askopenfilenames()` returns), converting that to a string, and then calling `os.cwd()` on that string (which does not represent a directory at all). You should be looping over `file_path`, rather than calling `os.listdir()` at all. – jasonharper Feb 20 '22 at 18:17

0 Answers0