我正在使用以下代码在 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 中发送正确的信息等,它应该仍然可以工作。
