python - recogniser.listen(source) 不会停止收听
问题描述
我正在制作一个 python 脚本,它会听你的声音,然后根据你所说的执行功能。
我刚刚开始制作“唤醒词”,代码如下所示:
while True:
try:
with sr.Microphone() as source1:
SpeakText("one")
r.adjust_for_ambient_noise(source1)
print("Set minimum energy threshold to {}".format(r.energy_threshold))
SpeakText("two")
audio1 = r.listen(source)
SpeakText("three")
MyText = r.recognize_google(audio1)
print(MyText)
SpeakText("four")
MyText = MyText.lower()
if MyText == "oink" or "ink" or "link":
playsound("oink_boop.mp3")
detect_command()
except sr.UnknownValueError:
print("No Speech or No Internet")
现在我放入 SpeakText 部分(使用 pyttsx3)只是为了调试目的,但它说“两个”然后卡在 audio1 = r.listen(source) 上听我的演讲
它似乎并没有停止听我说话,我什至尝试将麦克风静音,但这也没有用。
解决方案
我试过这个:
with sr.Microphone() as source1:
r.adjust_for_ambient_noise(source1)
r.pause_threshold = 1
audio1 = r.listen(source1)
try:
MyText = r.recognize_google(audio1, language='en-en')
MyText = MyText.lower()
if "oink" in MyText or "ink" in MyText or "link" in MyText:
playsound("oink_boop.mp3")
detect_command()
except sr.UnknownValueError:
print("No Speech or No Internet")
它仍然不起作用我做错了什么吗?
推荐阅读
- node.js - Nginx 在尝试反向代理 nodejs 服务器时仅在端口 80 上工作
- php - 将 orderBy() 与 getAll() 一起使用;
- r - R 的 data.table 因大数据的因子子集而崩溃
- sql - SQL Server 中的行级动态数据屏蔽
- java - 为什么我的第 50000 个数字的 BigInteger 斐波那契数与本网站不匹配?
- powershell - Powershell 函数调用在 Windows 10 上使用 powershell v7 导致缺少函数错误
- c# - 列表
> 除了()列表 > 比较 HashSet 列表 - firebase - Firebase 身份验证 - 如何更改自定义域
- python - 在pygame中沿x轴拖动对象
- c - 运行 10 秒的 while 循环