How to install pyaudio


12 posts
by vedeja » Sun Dec 09, 2012 8:49 pm
Can someone please bother to describe how pyaudio is installed on the Pi?
Posts: 2
Joined: Sun Dec 09, 2012 8:46 pm
by ZacharyI123 » Tue Dec 11, 2012 7:26 pm
sudo apt-get install git
git clone http://people.csail.mit.edu/hubert/git/pyaudio.git
Don't be mean, I'm only thirteen 8-)
User avatar
Posts: 263
Joined: Sun Jun 17, 2012 1:09 pm
Location: Ilford, Essex
by vedeja » Wed Dec 12, 2012 10:20 pm
For the record, here's what I did:

$ sudo apt-get install git
$ git clone http://people.csail.mit.edu/hubert/git/pyaudio.git
$ sudo apt-get install libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev
$ sudo apt-get python-dev
$ sudo python pyaudio/setup.py install
Posts: 2
Joined: Sun Dec 09, 2012 8:46 pm
by SpaceGerbil » Fri Mar 15, 2013 12:17 am
$ sudo apt-get install git
$ git clone http://people.csail.mit.edu/hubert/git/pyaudio.git
$ sudo apt-get install libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev
$ sudo apt-get python-dev
$ sudo python pyaudio/setup.py install


Many thanks. I wanted this on my laptop as well and had to make a few changes.
In root:
$ sudo apt-get install git
$ sudo git clone http://people.csail.mit.edu/hubert/git/pyaudio.git
$ sudo apt-get install libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev
$ sudo apt-get install python-dev
$ cd pyaudio
$ sudo python setup.py install
Posts: 27
Joined: Sat Feb 02, 2013 10:03 am
by simple-simon » Mon Jul 01, 2013 12:05 pm
I have been hacking around and stress that I am no expert being new to Linux and Pi. I found this...

sudo apt-get install python-pyaudio

It seems to install everything required
Posts: 3
Joined: Mon Jul 01, 2013 12:01 pm
by bohemier » Wed Oct 09, 2013 8:38 pm
Thanks...
sudo apt-get install python-pyaudio

works like a charm
Posts: 1
Joined: Wed Oct 09, 2013 8:36 pm
by jim.b » Sun Nov 16, 2014 11:26 pm
This only appears to setup pyaudio for python2.x. I've tried a few things to get it to work with python3 on my brand new pi and wolfson. Any ideas what I might be missing? I tried: "sudo python3 setup.py install" but still cannot "import pyaudio" in the python3 interpreter. I'm using python 3.2.3. thanks!
Posts: 1
Joined: Sun Nov 16, 2014 11:14 pm
by DirkS » Mon Nov 17, 2014 12:29 pm
For python 3
Code: Select all
sudo apt-get install python-dev

needs to be changed to
Code: Select all
sudo apt-get install python3-dev


viewtopic.php?f=32&t=54658 suggests that it can work with python 3

Gr.
Dirk.
Posts: 6646
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK
by smrtsmrf » Sat Jun 13, 2015 5:56 pm
I've tried these methods, and PyAudio seems to install fine, but then when I try to run the example on the PyAudio documentation site (on my Pi 2), I get slow/choppy/garbled audio which eventually stops. Playing audio with aplay from the command line works just fine, so it must be something with PyAudio.

Does anyone have any help they can offer? I've scoured the web, but can't find any solutions.

Thanks in advance.
Posts: 2
Joined: Thu Jun 11, 2015 11:08 pm
by zgt » Tue Jun 23, 2015 7:57 pm
I'm exactly with the same problem, smrtsmrf.

I am using the B+, Python 2.7.3, PyAudio (0.2.8 and 0.2.4) and I also get slow/choppy/garbled audio...
When I play the sound with pygame it works pretty good though. So it should be something with PyAudio...

Did you find what was causing that?
Posts: 3
Joined: Tue Jun 23, 2015 7:18 pm
by jonwitts » Sat Mar 12, 2016 2:06 pm
jim.b wrote:This only appears to setup pyaudio for python2.x. I've tried a few things to get it to work with python3 on my brand new pi and wolfson. Any ideas what I might be missing? I tried: "sudo python3 setup.py install" but still cannot "import pyaudio" in the python3 interpreter. I'm using python 3.2.3. thanks!


To install pyAudio for Python 3 try:
Code: Select all
sudo apt-get install python3-pyaudio

Just hacking around with it now...
User avatar
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 8
Joined: Fri Oct 17, 2014 3:45 pm
Location: Kingston upon Hull
by jonwitts » Sat Mar 12, 2016 3:14 pm
The following code allows me to record from my USB microphone. It does output a lot of errors first, but it works!

Code: Select all
#!/usr/bin/env python3
import pyaudio
import wave

CHUNK = 512
FORMAT = pyaudio.paInt16 #paInt8
CHANNELS = 1
RATE = 44100 #sample rate
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "pyaudio-output.wav"

p = pyaudio.PyAudio()

stream = p.open(format=FORMAT,
                channels=CHANNELS,
                rate=RATE,
                input=True,
                frames_per_buffer=CHUNK) #buffer

print("* recording")

frames = []

for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
    data = stream.read(CHUNK)
    frames.append(data) # 2 bytes(16 bits) per channel

print("* done recording")

stream.stop_stream()
stream.close()
p.terminate()

wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close()
User avatar
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 8
Joined: Fri Oct 17, 2014 3:45 pm
Location: Kingston upon Hull