【发布时间】:2015-09-07 19:46:25
【问题描述】:
我最近用 Python 为我设置了一个项目,创建一个语音控制的脚本。
我一直在使用 googles API 来执行此操作,但在使用此 API 时,我注意到它永远不会停止监听,除非它完全安静,这会阻止你在甚至有些嘈杂的区域或与周围的人交谈时运行命令。
这是我所拥有的:
import speech_recognition as sr
import pyttsx
r = sr.Recognizer()
engine = pyttsx.init()
listen = False
# Define methods
while True:
while listen == False:
with sr.Microphone() as source:
audio = r.listen(source)
try:
if (r.recognize(audio) == "start") :
listen = True
print("Listening...")
break
else:
continue
except LookupError:
continue
while listen == True:
with sr.Microphone() as source:
audio = r.listen(source)
print("1")
try:
print("2")
if (r.recognize(audio) == "stop") :
listen = False
print("Listening stopped. Goodnight")
break
else:
print("You said " + r.recognize(audio))
except LookupError:
engine.say('Audio cannot be read!')
engine.runAndWait()
print("Could not understand audio")
导入 PYTTSX 和 SpeechRecognition(使用 googles API)。现在我怎样才能让它运行得更像 Google Now,在任何情况下,无论有没有背景噪音,我都可以说任何话,并且在我说完后让它停止收听?谢谢。
【问题讨论】:
-
就像谷歌现在听噪音一样,您需要在上述问题的答案中提供关键字发现解决方案。它可以在噪音中工作,它只会对特定的关键词做出反应。
-
好吧,这似乎是我要找的东西,但我找不到适用于 Windows 7 的 PocketSphinx。
-
@Mikolay 我在 Sourceforge 上给你发了消息。
标签: python api speech-recognition