python - 键盘键按住以运行并释放以暂停 python 中的语音识别器
问题描述
我想按住键(例如 KeyA)启动并释放键暂停
所以基本上当我拿着 KeyA 时,我应该能够说“你好”,并且 Speech_recognizer 将运行,当我释放 KeyA 时,它应该暂停 Speech_recognizer 但仍然能够说出答案。speak() 是文字转语音
就像firestick电视遥控器上的alexa一样,我们必须按住alexa按钮然后说话然后释放按钮
这是我的代码
def takeCommand():
# speech recognizer
r = sr.Recognizer()
with sr.Microphone() as source:
print("Hearing...")
# r.pause_threshold = 1
r.chunk_size = 2048
r.adjust_for_ambient_noise(source, duration=0.5)
r.energy_threshold = 300
audio = r.listen(source)
try:
print("Recognizing....")
query = r.recognize_google(audio, language='en-in')
print(f"You said: {query}\n")
except Exception as e:
print(e) # to remove error from console remove this
print("Say that again please...")
return "None"
return query
pass
while True:
query = takeCommand().lower()
if 'hello' in query:
speak("Hello, how are you?")
解决方案
推荐阅读
- javascript - Liferay 动态快速链接
- cakephp - 使用一个模型 cakephp 3 将数据保存到多个数据库表
- python - 如何在张量流中保存/冻结任意泡菜模型?
- sql - 在一个元素中返回 SQL Server 中的逗号分隔值
- azure - XRDP 突然无法连接到 Azure VM
- angular - 单元测试 ViewChild 与 mat 排序和设置内容、Jasmine 和 Karma
- c# - 使用鼠标移动事件绘制和移动线
- python - 使用 format() 函数增加对 Python 格式的理解
- python - 如何在 .xlsm 文件中使用 Pandas 将数据框添加到现有 Excel 工作表
- typescript - Angular7 通过更改文本切换工具