2017-06-02 172 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我會非常感激 –