Reputation: 1722
I am trying to convert a .mp3 file into a .wav file based on [this website][1].
I have set my working directory to the location that stores both the python script and the .mp3 file, and tried running the code below:
from os import path
from pydub import AudioSegment
#files
src = 'Interview-part2.mp3'
dst = 'Interview-part2.wav'
#Convert mp3 to wav
sound = AudioSegment.from_mp3(src)
However, when I run this, I get the following error:
Traceback (most recent call last):
File "<ipython-input-19-f647e282d13d>", line 1, in <module>
sound = AudioSegment.from_mp3(src)
File "C:\Users\20200016\Anaconda3\lib\site-packages\pydub\audio_segment.py", line 796, in from_mp3
return cls.from_file(file, 'mp3', parameters=parameters)
File "C:\Users\20200016\Anaconda3\lib\site-packages\pydub\audio_segment.py", line 651, in from_file
file, close_file = _fd_or_path_or_tempfile(file, 'rb', tempfile=False)
File "C:\Users\20200016\Anaconda3\lib\site-packages\pydub\utils.py", line 60, in _fd_or_path_or_tempfile
fd = open(fd, mode=mode)
FileNotFoundError: [Errno 2] No such file or directory: 'Interview-part2.mp3'
Instead of only providing the audio file, I have also tried:
src = DIRECTORY+'Interview-part2.mp3'
But this resulted in a FileNotFoundError as well.
What causes this error, and what can I do to overcome it? [1]: https://pythonbasics.org/convert-mp3-to-wav/
Upvotes: 0
Views: 1820
Reputation: 11
use "." for absolute path in windows.
example: I have audio ext .mp3 in folder audio ./audio/1-18 TOEFL Exercise 4.mp3
.
Upvotes: 0
Reputation: 316
A good start for debugging this would be to expand src
to an absolute path, and make sure it resolves to what you expect.
>>> src = 'Interview-part2.mp3'
>>> import os
>>> os.path.abspath(src) # Result might strongly vary
'C:\\WINDOWS\\system32\\Interview-part2.mp3'
Upvotes: 0