我正在尝试基于 [this website][1] 将 .mp3 文件转换为 .wav 文件。
我已将工作目录设置为存储 python 脚本和 .mp3 文件的位置,并尝试运行以下代码:
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)
但是,当我运行它时,我收到以下错误:
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'
我不仅提供了音频文件,还尝试了:
src = DIRECTORY+'Interview-part2.mp3'
但这也导致了 FileNotFoundError 。
是什么导致了这个错误,我能做些什么来克服它?[1]:https ://pythonbasics.org/convert-mp3-to-wav/