2017-06-02 43 views
2

我使用下面的代码使用语音识别在Python语音识别API“兵”是很慢

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?或任何建议修改该代码

回答

2

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

here是链接到文档。他们在他们的例子中使用C#,但由于它是一个在线api,如果你在标题中发送正确的信息,它应该仍然有效。

+0

我使用Python,所以如果你有一个代码示例的Python中的REST api我会非常感激 –