【发布时间】:2018-01-23 00:49:22
【问题描述】:
我正在做一个项目,让计算机在我发出命令时回复它。我刚开始,但是当我运行代码时,它没有以我期望的方式响应。这是我的代码:
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循环只是打印每个短语而不检查短语的值是否为'oh'。尝试在print之前添加一个换行符并缩进该行以及它下面的两行以嵌套在for循环下。 -
@cole 谢谢,但它不起作用
-
喂?有人吗?
标签: python speech pocketsphinx espeak