【问题标题】:How can you stop a program from listening as soon as you stop talking?一旦你停止说话,你怎么能阻止程序收听?
【发布时间】:2020-05-31 13:59:03
【问题描述】:

我正在制作一个简单的程序来收听我的麦克风并使用谷歌的 api 将其转换为文本。 一切正常,但我的问题是,当我停止说话时,程序会继续收听,并且在我停止说话几秒钟后它就停止了。

我知道这可能是我的背景噪音有问题,虽然我有 Blue Yeti 麦克风,所以它不应该发生反弹,但我仍然尝试调整噪音,但它显示了相同的结果。

import speech_recognition as sr

# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone(device_index = 1) as source:
    print("Say something!")
    #audio = r.adjust_for_ambient_noise(source) - Tried also that
    audio = r.listen(source)
    print('Stopped listening!')
try:
    print("Google Speech Recognition thinks you said " + r.recognize_google(audio, language="he-HE"))
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))

正如预期的那样,即使我几秒钟没有说话,程序也会继续收听,这使得它真的很慢而且很糟糕.. 感谢您的帮助!

【问题讨论】:

    标签: python-3.x speech-recognition


    【解决方案1】:

    您可以尝试调整Recognizerclass 的pause_threshold 属性。 默认设置为0.8 通过查看Recognizer 源代码找到信息:https://github.com/Uberi/speech_recognition/blob/350397d2fb5db318c877f29ee3dc6e6cbf4a393d/speech_recognition/init.py#L508

    【讨论】:

      【解决方案2】:

      如果所有代码都正确,请尝试连接到 PC 的耳机,并请在打开麦克风的情况下进行耳机设置.....所以基本上程序正在运行,但有时麦克风是问题......这就是程序没有显示的原因任何错误..因为它试图听但无法理解,因为麦克风或源是问题....

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-11-21
        • 1970-01-01
        • 2021-10-18
        • 1970-01-01
        • 2017-12-02
        • 2010-10-17
        • 2011-08-08
        相关资源
        最近更新 更多