Pyaudio outputs slow/crackling/garbled audio - Raspberry Pi Forums


hello,

i'm trying use pyaudio play wave files i'm having slow/crackling/garbled outputs.

when play wave file described bellow, audio plays fine:

$ wget http://www.freespecialeffects.co.uk/sou ... lice_s.wav
$ aplay police_s.wav


however, when open 'play_wave.py' example /pyaudio/test, audio slow , garbled useless application.

code: select all

"""pyaudio example: play wave file."""  import pyaudio import wave import sys  chunk = 1024  #if len(sys.argv) < 2: #    print("plays wave file.\n\nusage: %s filename.wav" % sys.argv[0]) #    sys.exit(-1)  wf = wave.open('police_s.wav', 'rb')  # instantiate pyaudio (1) p = pyaudio.pyaudio()  # open stream (2) stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),                 channels=wf.getnchannels(),                 rate=wf.getframerate(),                 output=true)  # read data data = wf.readframes(chunk)  # play stream (3) while data != '':     stream.write(data)     data = wf.readframes(chunk)  # stop stream (4) stream.stop_stream() stream.close()  # close pyaudio (5) p.terminate()
to reproduce similar poor quality on linux, make chunk = 1 (the output pretty similar on laptop)


additional information:
______________________________________________________________________________________________________
what tried:
1- another raspberry pi b+.
2- change audio samples per buffer:
as supposing problem audio samples per buffer (the chunk variable in example), made loop increment chunk 1 , played audio each increment. notice slight difference chunk values, nothing close quality when play aplay.
however, notice big difference between 2 files:
1- police_s.wav = 8 bits , 22000hz, mono , 176 kb/s -> way better beat.wav played same chunk (2048)
2- beat.wav = 16bits , 44100hz, stereo, 1411 kb/s

when play same audio through example /pyaudio/test/play_wave_callback.py, output perfect, excepting interruptions @ end of audio. saw doesn't set chunk. uses frame_count parameter in callback function, printed , saw 1024 ¬¬, same default value came example /pyaudio/test/play_wave.py , results in garbled audio.

3- pyaudio 0.2.4:
since hayderoico mentioned using pyaudio 0.2.4 , said "i'm using pyaudio fine." (viewtopic.php?f=32&t=103190&p=715696&hi ... f8#p715696), decided give try on older version got same result...

i'm using: raspberry pi b+____raspbian____python 2.7.3____pyaudio v0.2.8____portaudio19-dev

how installed everything:
1st try:
$ sudo apt-get update
$ sudo apt-get -y install python-dev python-numpy cython python-smbus portaudio19-dev
$ git clone http://people.csail.mit.edu/hubert/git/pyaudio.git
$ cd pyaudio
$ sudo python setup.py install


2nd try:
$ sudo apt-get install python-pyaudio

3rd try:
github: https://github.com/jleb/pyaudio
______________________________________________________________________________________________________


it's frustrating having library's example not working on pi. don't think it's hardware limitation since same audio plays aplay , other libraries pygame , sdl2.

found 3 posts on raspberry's forum no solution:
1- viewtopic.php?f=28&t=113027&p=773638&hi ... f8#p773638
2- viewtopic.php?f=32&t=103190&p=715696&hi ... f8#p715696
3- viewtopic.php?f=32&t=25173&p=774430&hil ... f8#p774430

, these on stackoverflow:
1- http://stackoverflow.com/questions/2864 ... w-on-linux
2- http://stackoverflow.com/questions/2190 ... ing-a-file

new raspberry pi , audio programming, hope doing stupid...
using specific wrapper pyaudio, keep using instead of moving library...
appreciate help, suggestions , advice.


in advance!

are using hdmi audio or trrs analog audio?


raspberrypi



Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support