Solvedspeech_recognition Install/compilation of PyAudio failed

Kubuntu 17.10.1
Python 3.6.3
Pip 9.0.1

Created a virtual environment and read through the SpeechRecognition instructions. Here are the steps

$ sudo apt-get install python-pyaudio python3-pyaudio

that went okay, it also installed libportaudio2

$ sudo apt-get install python3 python3-all-dev python3-pip build-essential swig git libpulse-dev

Apt also added the suggestions - "The following NEW packages will be installed:
libglib2.0-dev libglib2.0-dev-bin libpcre16-3 libpcre3-dev libpcre32-3 libpcrecpp0v5 libpulse-dev libpython3-all-dev pkg-config python3-all python3-all-dev swig swig3.0"

Then installed SpeechRecognition

$ pip install SpeechRecognition

Then tried SpeechRecognition and got an error

$ python3 -m speech_recognition
Traceback (most recent call last):
File ".../SpeechRecognition/lib/python3.6/site-packages/speech_recognition/init.py", line 108, in get_pyaudio
import pyaudio
ModuleNotFoundError: No module named 'pyaudio'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File ".../SpeechRecognition/lib/python3.6/site-packages/speech_recognition/main.py", line 4, in
m = sr.Microphone()
File ".../SpeechRecognition/lib/python3.6/site-packages/speech_recognition/init.py", line 79, in init
self.pyaudio_module = self.get_pyaudio()
File ".../SpeechRecognition/lib/python3.6/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

Tried installing PyAudio , even though it is already installed via Apt

$ pip3 install pyaudio
Collecting pyaudio
Downloading PyAudio-0.2.11.tar.gz
Building wheels for collected packages: pyaudio
Running setup.py bdist_wheel for pyaudio ... error
Complete output from command .../SpeechRecognition/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-build-72_au_03/pyaudio/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" bdist_wheel -d /tmp/tmpu_qg0ulxpip-wheel- --python-tag cp36:
usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: -c --help [cmd1 cmd2 ...]
or: -c --help-commands
or: -c cmd --help

error: invalid command 'bdist_wheel'


Failed building wheel for pyaudio
Running setup.py clean for pyaudio
Failed to build pyaudio
Installing collected packages: pyaudio
Running setup.py install for pyaudio ... error
Complete output from command .../SpeechRecognition/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-build-72_au_03/pyaudio/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-feocjwqu-record/install-record.txt --single-version-externally-managed --compile --install-headers .../SpeechRecognition/include/site/python3.6/pyaudio:
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.6
copying src/pyaudio.py -> build/lib.linux-x86_64-3.6
running build_ext
building '_portaudio' extension
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/src
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.6-sXpGnM/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I.../SpeechRecognition/include -I/usr/include/python3.6m -c src/_portaudiomodule.c -o build/temp.linux-x86_64-3.6/src/_portaudiomodule.o
src/_portaudiomodule.c:29:10: fatal error: portaudio.h: No such file or directory
#include "portaudio.h"
^~~~~~~~~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1


Command ".../SpeechRecognition/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-build-72_au_03/pyaudio/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-feocjwqu-record/install-record.txt --single-version-externally-managed --compile --install-headers .../SpeechRecognition/include/site/python3.6/pyaudio" failed with error code 1 in /tmp/pip-build-72_au_03/pyaudio/

This appears to be the same problem - SlapBot/stephanie-va#8 . I will try the solution at SlapBot/stephanie-va#8 (comment)

Not sure if the following had an impact or not. The apt commands I used were run within a virtual environment, but I would have thought anything to do with Kubuntu packages would be system wide. I installed SpeechRecognition with pip instead of pip3 (I don't think it matters).

Although if I run pip3 or pip within the virtual environment, they both say version 9.0.1, yet if I run them both outside the virtual environment, it shows pip3 is installed but not pip.

24 Answers

✔️Accepted Answer

Tried those apt commands ( I left our libportaudio2 as apt informed me it was already installed)

$ sudo apt install libasound-dev portaudio19-dev libportaudiocpp0

which resulted in

The following NEW packages will be installed:
libasound2-dev libjack-dev libjack0 libportaudiocpp0 portaudio19-dev uuid-dev

Back to the VE, and although building the wheel fails, installed PyAudio

$ pip3 install pyaudio

Collecting pyaudio
Using cached PyAudio-0.2.11.tar.gz
Building wheels for collected packages: pyaudio
Running setup.py bdist_wheel for pyaudio ... error
Complete output from command .../SpeechRecognition/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-build-7egcf6_n/pyaudio/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" bdist_wheel -d /tmp/tmps83qs996pip-wheel- --python-tag cp36:
usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: -c --help [cmd1 cmd2 ...]
or: -c --help-commands
or: -c cmd --help

error: invalid command 'bdist_wheel'


Failed building wheel for pyaudio
Running setup.py clean for pyaudio
Failed to build pyaudio
Installing collected packages: pyaudio
Running setup.py install for pyaudio ... done
Successfully installed pyaudio-0.2.11

Try the SpeechRecognition again

$ python3 -m speech_recognition

ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
A moment of silence, please...
Set minimum energy threshold to 366.5422636248088
Say something!
Got it! Now to recognize it...
You said no no
Say something!
^C

Seems to fix it. The readme at https://github.com/Uberi/speech_recognition/blob/master/README.rst needs updating to reflect the additional packages required (if PyAudio is to be used)

Other Answers:

I got the same error, and I found that the file "portaudio.h" was truly missing. So i first usebrew install portaudio and then pip install pyaudio . These work for me. If those commands still not work ,maybe this may help.

Related Issues:

14
speech_recognition Install/compilation of PyAudio failed
Tried those apt commands ( I left our libportaudio2 as apt informed me it was already installed) $ s...
62
react player Error parsing header X-XSS-Protection: 1; When playing youtube videos
It's a known bug in current Google Chrome and Chromium: https://bugs.chromium.org/p/chromium/issues/...
25
tenacity Transparency and trust
Hi I can understand your concerns; maybe explaining the background behind the decision AudioBakery w...
22
allegro5 Android build fails due to deprecated 'android' command
I have searched and found no replacement for the android update project command ...
20
mumble macOS Mojave: passing the null port to CGEventTapEnable() segfaults
This is because the accessibility access for Mumble gets disabled on upgrade Trying to run Mumble-1....
17
mpv Better scaletempo (on high speed x1.5-x3)
@TiGR @wiiaboo I've fine tuned the settings a bit and this is what I got I've been watching some tal...
16
AudioKit AKMicrophone fails to initialize
Sounds good For anyone else who may be experiencing this issue with this version (4.5.2) ...
16
eqMac Bug: Driver failed to activate with new version 0.3.2 (beta): still problems
As a workaround I quit eqMac executed this from the Terminal reopend eqMac and allowed it to reinsta...
15
mpv [Feature request?] Play multiple videos sides by sides
Awesome! “Probably slow” is no issue for me it’s 1000×800@5fps streams that I have ;) Thanks both of...
13
tenacity Detach from audacity's repository
I think we should detach Is your feature request related to a problem? Please describe This fork as ...
12
srs PROTOCOL: JS API FETCH STREAM for flv.js
使用flv.js 播放flv时,出现跨域问题。 在srs_app_http_stream.cpp#485后添加w->header()->set(Access-Control-Allow-Origin ...
11
srs Disable -Werror for http parser.
You should change the source code: the file http_parser.c in 3rdparty/http-parser-2.1.zip change to ...
10
pulseaudio modules bt Building DEB package
PPA source here https://launchpad.net/~eh5/+archive/ubuntu/pulseaudio-a2dp I've managed to get a wor...
9
pulseaudio modules bt PPA Ubuntu 19.10
So more Docker hacking and I have the emulated bluetooth device functioning which results in a worki...
9
eqMac Beta eqMac2 v2.3 - possible fix for static/sync loss and Catalina install issue
@andrewmorner Had exact same problem Looks like more of the liscio ring buffer code needed to be cop...
6
sonic pi Mac OS 11.0.1 Big Sur (not loading)
Hi @duncangeere! I traced back the behaviour the week before last in my Big Sur test VM to a specifi...
5
mpv [Request] Hotkey to copy currently displayed subtitles text to clipboard
Linux: (needs xclip to be installed) add the following to ~/.config/mpv/input.conf Ctrl+c run /bin/b...
5
aeneas /usr/bin/ld: cannot find -lespeak
Thanks for the tip frish1 This installation solved my install failure Installing espeak wasn't enoug...
4
audioplayers E/MediaPlayerNative( 6767): error (1, -2147483648)
Currently having the same issue pub upgrade not working for me I am using AudioCache to play every 1...
4
qTox Choosing camera in settings causing qTox to crashing
Hey guys I was pointed to issues with your project in the MSDN forum thread linked above and I decid...
3
MPD io_uring throws and exception
Works fine after ulimit -l 65535 which sets the limit to 64 MiB (oh just saw your message) Yeah it's...
3
snapcast [Question] JSON RPC API
curl didn't work for me Hi I don't really understand how to remotely get or set the status or volume...
3
snapcast Snapclient with multiple audio hardware
@gerroon I am sorry that it does not work for you! Let me summarize what I did to make it work Maybe...
3
audioplayers update path_provider dependency version
A quirky and potentially hazardous fix until it is solved: Need to update the version of path_provid...
3
mpv DTS/AC3 passthrough via coax S/PDIF
I would like to add that you can force the output of the lavcac3enc filter to be passthrough to the ...
926
keras Loading model with custom loss function: ValueError: 'Unknown loss function'
I solved this problem by adding 'custom_bojects' my loss function: I trained and saved a model that ...
731
scrapy ' error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 '
@euler16 for scrapy with Python 3 you'll need with Python 2 you'll need I wanted to install scrapy i...
633
keras Tensorflow backend - bug in model._make_predict_function(...)
I had this problem when doing inference in a different thread than where I loaded my model ...
575
mysqlclient Can't install mysqlclient on MacOS
You can set ssl library path explicitly. Hi I'm on MacOSX Sierra ...
516
keras Creating Model variable throws "AttributeError: 'Tensor' object has no attribute '_keras_history'"
@zaid478 oh I assumed you were doing it on coursera Anyway Hello all setup: Keras 2.0 Tensorflow 1.0...
456
tensorflow ImportError: libcublas.so.10.0: cannot open shared object file: No such file or directory
@rhinsall I just found this out myself not sure if it's common knowledge but got around this by doin...
423
ipython Last jedi release (0.18.0) is incompatible with ipython (7.19 and 7.18 tested); reason - column arg was deprecated, and now removed
As a temporary fix for anyone just trying to get things working again: It would be really nice if yo...
416
pyodbc pip install pyodbc failing: error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
src/pyodbc.h:56:17: fatal error: sql.h: No such file or directory #include <sql.h> ^ Your machine do...
395
keras "<tensor> is not an element of this graph." when loading model.
I had a problem similar to that of @piraka9011 which was solved by calling model._make_predict_funct...
392
psycopg2 psycopg2-binary fails to install on macOS Big Sur 11.0.1 and Python 3.9.0 (with possible workaround)
Actually figured it out Haven't worked on a Mac in a while and forgot about the PostgreSQL dependenc...
387
pytorch I can't import PyTorch, libomp.dylib can't be loaded.
brew install libomp solves the problem. 🐛 Bug I tried to install PyTorch but I can't use it ...
380
pytorch RuntimeError: cuda runtime error (59) : device-side assert triggered when running transfer_learning_tutorial
@soumith Hi I find the error it is due to my labels contain value -1 which is unacceptable in criter...
373
Zappa bad magic number in 'application': b'\x03\xf3\r\n': ImportError
I was able to fix this too by doing find -name \*.pyc -delete Mine definitely wasn't caused by PY2 -...
356
tensorflow At Runtime : "Error while reading resource variable softmax/kernel from Container: localhost"
I had the same issue in tensorflow 1.13.1 which I have resolved by creating a reference to the sessi...
355
tensorflow Mac + Python 3.6.1: Attempting to download mnist data results in CERTIFICATE_VERIFY_FAILED error
This might have also been because I recently switched to a new machine and it's still only partially...
335
pyenv WARNING: pyenv init - no longer sets PATH.
I saw the same message on an RH derivative Linux using bash 4.4.19 To resolve After running pyenv up...
333
pyenv unable to install python 3.8.0 on macox 11
Try to install brew reinstall zlib bzip2 and in the ~/.zshrc file add the following: in case you are...
331
psutil psutil fails to install on python3.6 and Ubuntu16.04
I was just about to comment the same after I read the install file: https://github.com/giampaolo/psu...
326
psycopg2 Installing psycopg2-binary with Python:3.6.4-alpine doesn't work
I found this solution which worked quite fine Edit The above compiles the package from source so I w...
325
pyenv Unable to build Python on macOS Big Sur with Xcode 12 beta
Thank you HomeBrew team for all the hard work you did to find the patch that python team is brewing ...
320
Pillow ImportError: cannot import name 'PILLOW_VERSION' from 'PIL' (unknown location)
I'm getting the same error right now after conda install pillow on Win 10 It installed pillow 6.2.1 ...
317
pip ImportError in system pip wrappers after an upgrade
I followed some instructions elsewhere and ran and hit upon this issue fixed it returning me to the ...
308
tensorflow UnrecognizedFlagError: Unknown command line flag 'f'
I solved this issue by adding the line: tf.app.flags.DEFINE_string('f' '' 'kernel') what this essent...
298
tensorflow FutureWarning: Deprecated numpy API calls in tf.python.framework.dtypes
@Akeaakar And for the time being pip install numpy<1.17 to revert to numpy version 1.16.4 ...