def play_audio(self):
with self.default_speaker.player(consts.SAMPLE_RATE) as player:
while True:
try:
samples = self.voice_buffer.get_samples()
if samples is not None:
np_samples = np.frombuffer(samples, dtype=np.int16).astype(np.float32)
player.play(np_samples)
except Exception as e:
print("Error playing audio: %s" % (e,))
'samples' is a one-dimensional byte array of 16 bit samples reprsenting a single audio channel. If I use scipy to save 'samples' as a .wav file, it sounds completely correct, and I can also play samples using PyAudio and it works. This makes me confident that my data represents valid audio. However, Running the above code produces pure static through my speakers. Any ideas?
My current code looks like this:
'samples' is a one-dimensional byte array of 16 bit samples reprsenting a single audio channel. If I use scipy to save 'samples' as a .wav file, it sounds completely correct, and I can also play samples using PyAudio and it works. This makes me confident that my data represents valid audio. However, Running the above code produces pure static through my speakers. Any ideas?