【发布时间】:2017-06-30 07:21:15
【问题描述】:
我正在使用 Google Speech 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))
但我只得到这个。
jobin@jobin-Satellite-A665:~/scr$ python3 scr.py
Say something!
即使我说了什么,什么也没有发生。
我没有外接麦克风。我认为这个脚本可以与我笔记本电脑的内置麦克风一起使用。
我已经测试了我笔记本电脑的麦克风here。它工作正常。
我错过了什么吗?
【问题讨论】:
标签: python python-3.x speech-recognition google-speech-api