pydub.AudioSegment.from_file 找不到文件

pydub.AudioSegment.from_file not finding file

您好,我正在尝试使用 Google 网络语音 API 进行语音识别,我想将音频文件转换为文本。我已经能够在我的 raspberry pi 4 上编译这段代码,但是当我在我的 Windows 计算机上编译它时,我得到一个文件未找到的错误。

这里是错误:

File "C:/Users/pc/Desktop/py_scripts/omg.py", line 15, in <module>
    sound = pydub.AudioSegment.from_file('sample.mp3')
File "C:\Users\pc\AppData\Local\Programs\Python\Python38\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\pc\AppData\Local\Programs\Python\Python38\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: 'sample.mp3'

这是我一直在使用的代码:

import ffmpy, urllib, pydub

sound = pydub.AudioSegment.from_file('sample.mp3')    
sound.export('sample.wav', format="wav")
sample_audio = sr.AudioFile('sample.wav')
print("audio saved")

r = sr.Recognizer()
   
r.energy_threshold = 500  

   
with sample_audio as source:
    r.adjust_for_ambient_noise(source, 0.25)
    audio = r.record(source)

key = r.recognize_google(audio)
   
print("key is : ", end="")
print(key)

代码工作目录下是sample.mp3文件吗?