首页 > 解决方案 > 一旦你停止说话,你怎么能阻止程序收听?

问题描述

我正在制作一个简单的程序来收听我的麦克风并使用谷歌的 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.xspeech-recognition

解决方案


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


推荐阅读