The goal is to play two sound files simultaneously so the sounddevice.play
function is not an option. I believe that I should make an OutputStream
for each file. Right now I'm stuck in trying to get one OutputStream
to work. Please help.
My code so far:
import soundfile as sf
import sounddevice as sd
data, fs = sf.read('sound_file.wav', dtype='float32')
def callback(outdata, frames, time, status):
outdata[:] = data
with sd.OutputStream(callback=callback):
pass
Edit: switched to RawOutputStream
import soundfile as sf
import sounddevice as sd
wf = sf.SoundFile('sound_file.wav')
def callback(outdata, frames, time, status):
data = wf.buffer_read(frames, dtype='float32')
if len(data) <= 0:
raise sd.CallbackAbort
if len(outdata) > len(data):
raise sd.CallbackAbort #wrong obviously
outdata[:] = data
with sd.RawOutputStream(channels=wf.channels,
callback=callback) as stream:
while stream.active:
continue