gpt4 book ai didi

python - python 中的语音识别 api "bing"非常慢

转载 作者:太空宇宙 更新时间:2023-11-04 02:49:22 32 4
gpt4 key购买 nike

我正在使用以下代码在 python 中使用语音识别

import speech_recognition as sr

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


BING_KEY = 'KEY' # Microsoft Bing Voice Recognition API keys 32-character lowercase hexadecimal strings
try:
print(type(r.recognize_bing(audio, key=BING_KEY)))
except sr.UnknownValueError:
print("Microsoft Bing Voice Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Microsoft Bing Voice Recognition service; {0}".format(e))

但是很慢,甚至会滞后20秒!这很慢,你能推荐任何 python 中的实时语音识别 api 吗?或对该代码的任何建议修改

最佳答案

我使用 Bing Speech API,但不像您那样使用客户端库。我使用 REST API。我使用 PyAudio 实时获取音频,当我检测到噪音水平升高时,我开始将声音录制到 wav 文件中,然后在完成后将音频数据发送到 api 文档为您提供的端点。它给我的响应相当快,最多 3 秒,但这有点取决于你的 wifi 速度。我的方法比你的更复杂,但它是值得的。

here是文档的链接。他们在示例中使用 C#,但由于它是一个在线 API,如果您在 header 中发送正确的信息等,它应该仍然可以工作。

关于python - python 中的语音识别 api "bing"非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44319253/

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