gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 07:39:51 42 4
gpt4 key购买 nike

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

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

最佳答案

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

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

关于python - 如何使用谷歌语音识别进行实时语音识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46835899/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com