Hey all, I am facing a problem playing back wav/audio files in python on my raspberry pi + cirrus logic audio card setup. The file being played back is always buzzing and full of distortion. This problem is only faced when I ran the playback script on python, and the playback is normal using aplay-. Can anyone advice me on this?
Below is the playback python code. Please help me to see if everything is fine. Thanks.
def playAudio():
import pyaudio
import wave
CHUNK = 1024
wf = wave.open('White_Noise.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.stop_stream()
stream.close()
p.terminate()