python-3.x - 一旦你停止说话,你怎么能阻止程序收听?
问题描述
我正在制作一个简单的程序来收听我的麦克风并使用谷歌的 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))
正如预期的那样,即使我几秒钟没有说话,程序也会继续收听,这使得它真的很慢而且很糟糕。谢谢你的帮助!
解决方案
您可以尝试调整类的pause_threshold
属性Recognizer
。默认情况下,它设置为0.8
通过查看Recognizer
此处的源代码找到信息:https ://github.com/Uberi/speech_recognition/blob/350397d2fb5db318c877f29ee3dc6e6cbf4a393d/speech_recognition/init .py# L508
推荐阅读
- c++ - 使用线程和互斥锁在主线程外保持阻塞 fwrite
- wordpress - 尝试在某些 woocommerce 产品的价格下方添加自定义可编辑字段
- python - 将下一行的值附加到当前行 pandas groupby id
- javascript - JavaScript 测验应用程序工作正常但有未捕获的类型错误
- flutter - 如何预加载颤动的 webview 小部件
- php - E/flutter(16663):[错误:flutter/lib/ui/ui_dart_state.cc(177)]未处理的异常:FormatException:意外字符(在字符33处)
- javascript - 难倒练习 Javascript 制作 D20 骰子滚轮
- javascript - Firefox CSS过渡在mouseleave上跳过动画
- flutter - 颤振 - 图标主题数据。深色模式的图标颜色会更改,但 Drawer() 中的浅色模式不会更改
- git - 执行 git 命令时出错