如何使用谷歌语音识别进行实时语音识别

时间:2017-10-19 17:44:49

标签: python speech-recognition

关于我的项目遇到的问题,我有一个问题。它应该通过语音与使用进行通信。我正在使用google speech api向系统发出命令。处理命令然后响应需要一些时间。问题是,它需要比预期更长的暂停(6-8秒),然后继续回答。

对于我的程序,我需要实时语音识别,因此系统一完成问题就会响应。我的问题是,无论如何都要将每个单词发送给API,而不是在完成后发送整个句子。我的代码如下:

import speech_recognition as sr

# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
    print("Say something!")
    audio = r.listen(source)

try:
    print("You said " + r.recognize_google(audio))
except sr.UnknownValueError:
    print("Ooops! Could not understand audio")
except sr.RequestError as e:
    print("Could not request results from Google Speech Recognition service; {0}".format(e))

我是一名学生并正在做一个学术项目。任何帮助都非常感谢。非常感谢你。

1 个答案:

答案 0 :(得分:0)

您可以将 interimResults 参数设置为 True https://cloud.google.com/speech-to-text/docs/basics

如果您正在寻找可以克隆并开始使用 Speech API 的环境,您可以查看 realtime-transcription-playground 存储库。