|
機器學習與深度學習特訓班 第二版 第九章
在這個程式執行
import speech_recognition as sr
r = sr.Recognizer() #建立語音辨識物件 with sr.WavFile("record1.wav") as source: #讀取語音檔 audio = r.record(source)
print('開始翻譯...') try: text = r.recognize_google(audio, language="zh-TW") #辨識結果 print(text) except sr.UnknownValueError: print("Google Speech Recognition 無法辨識此語音!") except sr.RequestError as e: print("無法由 Google Speech Recognition 取得結果; {0}".format(e)) print('翻譯結束!')
他跑出了這樣的錯誤 FileNotFoundError Traceback (most recent call last) <ipython-input-1-e39edd4fbc55> in <module> 2 3 r = sr.Recognizer() #建立語音辨識物件 ----> 4 with sr.WavFile("record1.wav") as source: #讀取語音檔 5 audio = r.record(source) 6
C:\ProgramData\Anaconda3\lib\site-packages\speech_recognition\__init__.py in __enter__(self) 201 try: 202 # attempt to read the file as WAV --> 203 self.audio_reader = wave.open(self.filename_or_fileobject, "rb") 204 self.little_endian = True # RIFF WAV is a little-endian format (most ``audioop`` operations assume that the frames are stored in little-endian form) 205 except (wave.Error, EOFError):
C:\ProgramData\Anaconda3\lib\wave.py in open(f, mode) 508 mode = 'rb' 509 if mode in ('r', 'rb'): --> 510 return Wave_read(f) 511 elif mode in ('w', 'wb'): 512 return Wave_write(f)
C:\ProgramData\Anaconda3\lib\wave.py in __init__(self, f) 158 self._i_opened_the_file = None 159 if isinstance(f, str): --> 160 f = builtins.open(f, 'rb') 161 self._i_opened_the_file = f 162 # else, assume it is an open file object already
FileNotFoundError: [Errno 2] No such file or directory: 'record1.wav'
他說找不到檔案 但我不管在本書範例的路徑以及下載的地方都有放了record1.wav的語音檔了 但他還是說找不到 |