Ser*_*mis 10 python speech-recognition module speech-to-text
我正在尝试使用带有 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!")
speak("I heard you say " + listen())
Run Code Online (Sandbox Code Playgroud)
OS X Sierra附带 Python 2.7.10。由于您使用的是 Python 3.5.1,因此您可能自己安装了它,并且现在有两个版本的 Python。IDLE 显然正在使用您没有安装模块的 Python 版本运行speech_recognition。
做什么取决于您的设置。idle3我首先从命令行运行,而不是从idle. 如果您的模块是为 Python 3 安装的,那么这就是您所需要的。如果这不起作用,请检查所有内容并注意不同版本,并按照您想要的方式整理它们。
| 归档时间: |
|
| 查看次数: |
43181 次 |
| 最近记录: |