我正在开发一个项目,让计算机在我给它命令时回声。我刚开始,但是当我运行代码时,它没有以我期望的方式做出响应。这里是我的代码:检查里面的循环未执行
from pocketsphinx import LiveSpeech
import os
for phrase in LiveSpeech(): print(phrase)
if phrase == 'oh' :
os.system('espeak' ' "hi"')
我运行此代码时出错。以下是错误:
Traceback (most recent call last):
File "xxt", line 4, in <module>
print(phrase)
File "/Library/Python/2.7/site-packages/pocketsphinx/__init__.py", line 93, in __str__
return self.hypothesis()
File "/Library/Python/2.7/site-packages/pocketsphinx/__init__.py", line 126, in hypothesis
hyp = self.hyp()
File "/Library/Python/2.7/site-packages/pocketsphinx/pocketsphinx.py", line 359, in hyp
return _pocketsphinx.Decoder_hyp(self)
File "/Library/Python/2.7/site-packages/pocketsphinx/__init__.py", line 225, in stop
raise StopIteration
StopIteration
感谢, 阿迪亚
这可能太简单了,但你确定你的'if'语句正在执行'for'循环吗?它看起来像你的'for'循环只是打印每个短语而不检查短语的值是否是'哦'。在'print'之前尝试添加一个换行符并缩进该行,以及它下面的两行嵌套在'for'循环中。 – cole
@cole谢谢,但它不起作用 – Aditya
你好?任何人? – Aditya