Reputation: 63
The playback of my wav audio files on my raspberry pi, through pyaudio, doesn't work well The .wav files have been created on my (windows) laptop and I now want to play them properly on my rpi.
I am testing it with the test scripts that come with pyaudio.
import pyaudio
import wave
chunk = 1024
wf = wave.open('sample.wav', 'rb')
p = pyaudio.PyAudio()
stream = p.open(
format = p.get_format_from_width(wf.getsampwidth()),
channels = wf.getnchannels(),
rate = wf.getframerate(),
output = True)
data = wf.readframes(chunk)
while data != '':
stream.write(data)
data = wf.readframes(chunk)
stream.close()
p.terminate()
I have also tried forcing the settings of the pyaudio stream to the ones I used to record it with, but that does not help.
The playback works fine when I do it with aplay
from the command line.
I've come across a few other posts that have this problem on other forums, but no one came up with an answer (yet).
Some further context:
I am trying to stream audio from my laptop to my rpi, and from there output it to my speakersystem. I capture the audio using VB-Audio Virtual Cable. When I play something on my laptop, I turn on the Virtual cable and my python code. pyaudio then captures this, and sends it to the rpi, the rpi collects them (buffers them) and then plays it. This all works fine if I keep it on windows, but when I port it to my rpi the playback quality became terrible.
I then started testing with playing simple wav files to see whether it was a latency issue or rather a playback issue, and it is now clearly the latter.
Upvotes: 2
Views: 905
Reputation: 63
Should anyone run into the same issue, I did not manage to fix this issue, but found an alternative solution. I am now using the alsaudio library (https://sourceforge.net/projects/pyalsaaudio/), which does the trick nicely.
Upvotes: 1