即使我停止讲话,Speech_recognition“ .listen(source)” func也会尝试“监听”。问题仅在第二次出现时出现

时间:2019-05-12 16:23:32

标签: python windows speech-recognition google-speech-api

第二个“音频= r.listen(源)”命令继续“监听” 即使我停止说话,也没有其他声音。有时第二次识别有效(完成收听并打印结果),有时没有(无限听),尽管我以相同的音量和相同的设置讲话。首次识别始终有效。

试图根据作者在GitHub官方页面上的建议提高阈值-结果相同,或差异很小,以至于我没有注意到: r.dynamic_energy_threshold = 6000 在我的情况下,时间限制不是一个好的解决方案。可以,但是演讲结束后我需要停止收听

import speech_recognition as sr
text = ""
audio = None
r = sr.Recognizer()
r.dynamic_energy_threshold = 6000
with sr.Microphone() as source:

    print("Listening...")
    audio = r.listen(source)
    print("ok")
    try:
        text = r.recognize_google(audio, language="ru-RU")
        print("You said : {}".format(text))
    except sr.UnknownValueError:
        print("Google Speech Recognition could not understand audio")
    except sr.RequestError as e:
        print("Could not request results from Google Speech Recognition service; {0}".format(e))

#**********************************
# Trying to do the same second time
#**********************************

text = ""
audio = None
with sr.Microphone() as source:
    print("Listening...")
    audio = r.listen(source)
    print("ok")
    try:
        text = r.recognize_google(audio, language="ru-RU")
        print("You said : {}".format(text))
    except sr.UnknownValueError:
        print("Google Speech Recognition could not understand audio")
    except sr.RequestError as e:
        print("Could not request results from Google Speech Recognition service; {0}".format(e))

我希望第二次识别能在第一次使用时起作用,但实际上,它会在收听源代码时冻结。

0 个答案:

没有答案