我尝试在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
救命? :)
(对不起,如果我的英语不好)
好的,我确实让它成功了。如果有人遇到同样的问题,我会发布适合我的代码:
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))
也许是因为我使用'而不是'。