繁体   English   中英

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

[英]How to perform realtime speech recognition using google speech recognition

我有一个关于我的项目面临的问题的问题。 它应该通过语音与使用进行交流。 我正在使用谷歌语音 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))

我是一名学生,正在做一个学术项目。 任何帮助都受到高度赞赏。 非常感谢。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM