我尝试将语音转换为WAV文件,但是我被卡在这里。许多教程都给出了相同的代码,但对我而言不起作用。在这里:
import speech_recognition as sr
r = sr.Recognizer()
with sr.AudioFile("hello_world.wav") as source:
audio = r.record(source)
try:
s = r.recognize_google(audio)
print("Text: "+s)
except Exception as e:
print("Exception: "+str(e))
“ hello_world.wav”文件与代码位于同一目录中。我没有任何错误。控制台:
C:\Users\python.exe "D:/voice_recognition.py"
Exception:
Process finished with exit code 0
有帮助吗? :)
(对不起,如果我的英语不好)
答案 0 :(得分:0)
好的,我实际上做到了。如果有人遇到相同的问题,我会发布对我有用的代码:
import speech_recognition as sr
r = sr.Recognizer()
hellow=sr.AudioFile('hello_world.wav')
with hellow as source:
audio = r.record(source)
try:
s = r.recognize_google(audio)
print("Text: "+s)
except Exception as e:
print("Exception: "+str(e))
也许是因为我用'代替了'。