我正在使用Google Speech API嘗試以下語音識別代碼。Google語音識別API不在監聽
#!/usr/bin/env python3
# Requires PyAudio and PySpeech.
import speech_recognition as sr
# Record Audio
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
audio = r.listen(source)
# Speech recognition using Google Speech Recognition
try:
# for testing purposes, we're just using the default API key
# to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
# instead of `r.recognize_google(audio)`
print("You said: " + r.recognize_google(audio))
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
但我得到的只是這個。
[email protected]:~/scr$ python3 scr.py
Say something!
即使我說了些什麼,沒有任何反應。
我沒有外接麥克風。我認爲這個腳本將與我的筆記本電腦的內置麥克風一起工作。
我測試了我的筆記本電腦的麥克風here。它工作正常。
我錯過了什麼?
不錯的標題...;) – BlackBear