我已经使用brew安装了portaudio并在我的macos中使用pip3安装了speechRecognition,pyaudio。 运行以下代码时出现错误
CODE:
#!/usr/bin/env python
# Python 3
import os
import sys
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
print ("say something!");
audio = r.listen(source)
try:
print("google thinks you said" +r.recognize_google(audio))
except:
pass
ERROR:
Traceback (most recent call last):
File "test.py", line 8, in <module>
with sr.Microphone() as source:
File "/Library/Python/2.7/site-
packages/speech_recognition/__init__.py", line 79, in __init__
self.pyaudio_module = self.get_pyaudio()
File "/Library/Python/2.7/site-
packages/speech_recognition/__init__.py", line 110, in get_pyaudio
raise AttributeError("Could not find PyAudio; check
installation")
AttributeError: Could not find PyAudio; check installation
我正在使用python-shell在我的nodejs应用程序中运行这个python脚本。 当我只使用python3 test.py运行这个脚本时,它正在运行,但是使用python test.py,它无法正常工作。 在我的节点应用程序中它也无法正常工作。我认为node正在基本的python 2.7版上执行这个脚本。 我正在使用MacOs sierra操作系统。
请事先帮助我: - )
答案 0 :(得分:1)
似乎你已经为python3安装了软件包,这就是它使用它的原因,但是从python2.7运行脚本时它会发出错误,要解决它你需要为python2.7版本安装相同的软件包。
您可以运行命令跟随命令并检查它是否有效。
pip2.7 install pyaudio
答案 1 :(得分:0)
安装2件东西,
brew install portaudio19-dev python-pyaudio
然后
pip install pyaudio