gpt4 book ai didi

python - 语音识别后控制

转载 作者:太空宇宙 更新时间:2023-11-03 20:42:05 32 4
gpt4 key购买 nike

problem screenshot

语音转文字后如何触发命令?现在我有文本,但无法使用 python 中的 if 条件对其进行比较,以便我可以执行所需的任务。我已使用 pocketsphinx 在树莓派中进行语音识别。

   import os
from pocketsphinx import LiveSpeech, get_model_path

model_path = get_model_path()

speech = LiveSpeech(
verbose=False,
sampling_rate=16000,
buffer_size=2048,
no_search=False,
full_utt=False,
hmm=os.path.join(model_path, 'en-us'),
lm=os.path.join(model_path, 'en-us.lm.bin'),
dic=os.path.join(model_path, 'cmudict-en-us.dict')
)

for phrase in speech:
print(phrase)
if phrase == "HOME"
print (OK)

代码没有给出任何错误并且工作正常;我所说的它打印在屏幕上,即代码一直工作到最后第三行 [打印(短语)] 并给出预期结果,但最后 2 行不执行所需的任务,但没有给出错误

最佳答案

你可以使用

if str(phrase) == "HOME":

if phrase.hypothesis() == "HOME":

关于python - 语音识别后控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56801666/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com