0

I am attempting to convert an .mp3 testaudio.mp3 into .wav testaudio.wav by using Python's subprocess module and ffmpeg.

I am on Windows, and when I use command prompt to run the following command, it works and converts my .mp3 into .wav successfully:

C:\PATH_programs\ffmpeg-4.4-full_build\ffmpeg-4.4-full_build\bin>ffmpeg -i testaudio.mp3 testaudio.wav

However, when I attempt to use a Python script to do the same thing, I get a "No such file or directory" error:

import subprocess

subprocess.call(['ffmpeg', '-i', 'testaudio.mp3', 'testaudio.wav'])

The ffmpeg.exe, convertmp3towav.py, and audiotest.mp3 files all live in the same directory C:\PATH_programs\ffmpeg-4.4-full_build\ffmpeg-4.4-full_build\bin.

Lasagna Cat
  • 297
  • 3
  • 24
  • make sure that ```testaudio.mp3``` is on the same directory of the code file. – ELAi Oct 07 '21 at 10:13
  • if ```testaudio.mp3``` is in the same directory try ```.\\testaudio.mp3``` instead and the same for the output – ELAi Oct 07 '21 at 10:15

1 Answers1

0

I think pydub is more flexible than subprocess

from pydub import AudioSegment

audio_file = AudioSegment.from_file("testaudio.mp3")
audio_file.export("testaudio.wav", "wav")
ELAi
  • 170
  • 2
  • 8
  • Thanks for the suggestion. I too have had issues with PyDub, I received `FileNotFoundError: [WinError 2] The system cannot find the file specified` despite the files again being in the same directory. Question: Are these files supposed to sit in the same folder as Python is being ran from? I'm getting an impression I need to move ALL files to where `pip` installs modules like `subprocess` and `pydub` and so forth. – Lasagna Cat Oct 07 '21 at 10:38
  • you can write ".\\" before the filename witch will point to the same directory of the code file – ELAi Oct 07 '21 at 10:46
  • or if that didn't help, you could use `os.path` function see [this](https://stackoverflow.com/questions/5137497/find-the-current-directory-and-files-directory) article to know more. – ELAi Oct 07 '21 at 10:49