speech_recognition: AttributeError: Could not find PyAudio; check installation
Steps to reproduce
Hey I am just getting started with speech recignition and i was just checking some basic examples that i had found
It was nothing too complicated, very simple things
The code i am using is below :
import speech_recognition as sr
# Record Audio
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
audio = r.listen(source)
# Speech recognition using Google Speech Recognition
try:
# for testing purposes, we're just using the default API key
# to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
# instead of `r.recognize_google(audio)`
print("You said: " + r.recognize_google(audio))
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
Expected behaviour
I expect it to just use my microphone and let me record something.
(What did you expect to happen?)
Actual behaviour
This is the error i get,
Traceback (most recent call last):
File "<ipython-input-9-2b39d94ceb5b>", line 1, in <module>
runfile('/home/sanwal092/Desktop/Python/SR/dummy.py', wdir='/home/sanwal092/Desktop/Python/SR')
File "/home/sanwal092/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 866, in runfile
execfile(filename, namespace)
File "/home/sanwal092/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "/home/sanwal092/Desktop/Python/SR/dummy.py", line 14, in <module>
with sr.Microphone() as source:
File "/home/sanwal092/anaconda3/lib/python3.6/site-packages/speech_recognition/__init__.py", line 78, in __init__
self.pyaudio_module = self.get_pyaudio()
File "/home/sanwal092/anaconda3/lib/python3.6/site-packages/speech_recognition/__init__.py", line 109, in get_pyaudio
raise AttributeError("Could not find PyAudio; check installation")
AttributeError: Could not find PyAudio; check installation
When i run import pyauaudio as p;print(p.version)"`.) to check the version of pyaudio installed, i get the following error instead of the library working.
Could not import the PyAudio C module '_portaudio'.
Traceback (most recent call last):
File "<ipython-input-11-b37da17f237b>", line 1, in <module>
import pyaudio
File "/home/sanwal092/pyaudio/build/lib.linux-x86_64-2.7/pyaudio.py", line 116, in <module>
import _portaudio as pa
ImportError: /home/sanwal092/pyaudio/build/lib.linux-x86_64-2.7/_portaudio.so: undefined symbol: _Py_ZeroStruct
(What happened instead? How is it different from what you expected?) I am not sure where the error is coming from. It must have something to do with my compilation of the libray maybe and i am not sure what to do from here on. Anyhelp would be appreciated
(If the library threw an exception, paste the full stack trace here)
System information
(Delete all the statements that don’t apply.)
My system is Ubuntu 16.04 LTS x64
My Python version is Python 3.6.0 :: Anaconda 4.3.1 (64-bit)
My Pip version is pip 9.0.1
My SpeechRecognition library version is 3.6.5
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 52 (6 by maintainers)
Follow my step to solve the problem pip install pipwin pipwin install pyaudio
Not one of the maintainers but you are missing a dependency of pyaudio (libportaudio). On linux just do the following:
sudo apt-get install libportaudio-dev
Thanks @gotsanity! Just to add to that, if you get an error like
Package 'libportaudio-dev' has no installation candidate
with that command, trysudo apt-get install portaudio19-dev
instead.Hi @sanster9292,
How are you installing PyAudio? From source? Using pip?
If so, did you do so using the
sudo apt-get install portaudio19-dev python-all-dev python3-all-dev && sudo pip install pyaudio
command mentioned in the README?Hi @esterrrg,
If you installed it using Pip, simply do
pip install --upgrade pyaudio
. If you installed from an egg, wheel, or setup.py, download the latest version of the egg/wheel/source code and install it again.This command works very well on windows 10
pip install pipwin pipwin install pyaudio
got it to work on mac
brew install portaudio
pip install pyaudio
If pyaudio doesn’t work.
Try this in your code.It will show you the error if it is in import pyaudio without Tracebaking. then try again
pip uninstall pyaudio
pip install pyaudio
If doesn’t work workpip install pipwin
pipwin insatll pyaudio
Note: Above lines work in only in windows. check if you have installed the google speech recognition API correctly if you haven’t install-
pip install google-api-python-client
Solved my problem for me too after trying for hours (Win 10) . Thanks alot !!
@killerPhoenix @aritra-bhawani I was able to work through this issue by installing
. If you happen to be using the
distribution,
led me to the solution. Hope this helps.
conda install -c anaconda portaudio
worked for me,Solved my problem for me too (Win 10) . @Vishesht Thanks alot !! You Genius !!!
I don’t think I came across that error. You might want to start a new issue here with steps to reproduce that error. This issue is closed and might not get as much attention from the community. Once you post a new issue, we could all take a look
I have done
pip install pyaudio
as python 2 is default