
-----------------------------------
DtY
Sat Nov 07, 2009 4:23 pm

PyAudio
-----------------------------------
All I need to do is read raw samples from the microphone, and I've come across PyAudio. When I go through the microhpone to wav file tutorial I get an error, I have no idea at all what it means.

>>> import pyaudio
>>> p = pyaudio.PyAudio()
>>> stream = p.open(format=pyaudio.paInt16,channels=1,rate=44100,input=True,frames_per_buffer=1024)
>>> stream.read(1024)
Traceback (most recent call last):
  File "", line 1, in 
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pyaudio.py", line 564, in read
    return pa.read_stream(self._stream, num_frames)
IOError: 

Anyone have any idea what's going on? I'm on Mac OS 10.6 (snow leopard), Python 2.6, btw. Another library that would let me read raw samples from a microphone would work too, it needs to at least work on OS X, and cross platform would be better.

-----------------------------------
handsome-music
Thu Nov 19, 2009 9:03 pm

Re: PyAudio
-----------------------------------
I just installed PyAudio tonight and ran into the same problem.  I was able to handle the error by wrapping the call to stream.read(chunk) in a try/except statement to catch any dropped frames gracefully, without exiting.   For example:


try:
      data = stream.read(chunk)
except IOError:
      print 'warning: dropped frame' # can replace with 'pass' if no message desired


Let me know if that works for you.

-----------------------------------
zizou1304
Wed Jan 06, 2010 8:55 am

Re: PyAudio
-----------------------------------
>>> import pyaudio
>>> p = pyaudio.PyAudio()
>>> stream = p.open(format=pyaudio.paInt16,channels=1,rate=44100,input=True,frames_per_buffer=1024)
>>> stream.read(1024)


hi
don't write code step by step in the python shell.
pyaudio need to be launched from a script.

just after you create the stream, a buffer begins to keep input data.
when you read 1024, it's too late, the buffer is overflowed.

when you launch the same code from a script, the execution is faster, and may success.

you can have something like that :

while not stop:
   try:
        x = self.stream.read(1024)   
    except IOError,e:
         if e

-----------------------------------
muneeb.ahmad
Sat May 07, 2011 2:56 am

RE:PyAudio
-----------------------------------
Hi every one ! 

I am facing some peculiar problem with pyaudio! 

I have used Pyaudio to implement VoIP chat module. and it is working fine as well when i connects to the internet through WiFi but when i connects two computers through LAN or Internet a dail up. I am receiving a peculiar kind of sound which is very odd .. I can hear my voice as well as that peculiar sound Can any one help me what can be the reason for it because i am stuck.

Thank you!

-----------------------------------
dayaramb
Tue Oct 18, 2011 2:59 am

Re: PyAudio
-----------------------------------
hello, muneeb.ahmad,
Could you please let me know , how do you implement the pyaudio for voip chat . I am also trying the same thing for python audio chat. 
Thank you !
