我正在尝试使用带有 python 3.5.1 的语音识别模块来激活我的 jarvis AI 语音!我查看了堆栈溢出并发现了一些与我类似的问题,但他们没有我需要的答案,我需要为此个性化的答案。我已经下载了所有必要的软件包,但仍然没有运气,出现此错误:
ImportError: No module named 'speech_recognition'
Run Code Online (Sandbox Code Playgroud)
如果我运行:
python -m speech_recognition
Run Code Online (Sandbox Code Playgroud)
在终端中,它仅在终端中运行,我可以与它交谈,但它几乎无法定位,但它可以听到我的声音并且可以解释一些单词。我已经从本网站的说明下载了终端中的所有软件包。
https://pypi.python.org/pypi/SpeechRecognition/
当我在 IDLE 中运行我的代码时,我的代码得到上面显示的错误。我在运行 macOS Sierra 10.12.2 的 iMac 上,如果有人有帮助的答案。谢谢!
继承人我的代码:
import speech_recognition
import pyttsx
speech_engine = pyttsx.init('sapi5') # see
speech_engine.setProperty('rate', 150)
def speak(text):
speech_engine.say(text)
speech_engine.runAndWait()
recognizer = speech_recognition.Recognizer()
def listen():
with speech_recognition.Microphone() as source:
recognizer.adjust_for_ambient_noise(source)
audio = recognizer.listen(source)
try:
return recognizer.recognize_sphinx(audio)
# or: return recognizer.recognize_google(audio)
except speech_recognition.UnknownValueError:
print("Could not understand audio")
except speech_recognition.RequestError as e:
print("Recog Error; {0}".format(e))
return ""
speak("Say something!") …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个程序的一部分,将陈述变成问题。
当我尝试删除它时x
,它会返回None
。我希望它打印删除该项目的句子,我做错了什么?
def Ask(Question):
Auxiliary = ("will", "might", "would", "do", "were", "are", "did")
for x in Auxiliary:
if x in Question:
Question_l = Question.lower()
Question_tk_l = word_tokenize(Question)
Aux_Rem = Question_tk_l.remove(x)
print (Aux_Rem)
Run Code Online (Sandbox Code Playgroud)
想要的行为示例:
"what we are doing in the woods"
Run Code Online (Sandbox Code Playgroud)
应该成为
"what we doing in the woods"
Run Code Online (Sandbox Code Playgroud)
我想从问题中删除任何辅助词。