1

I am trying to make my audio interface continuous play the same audio in a loop. Someone recommended the use of the "OutputStream" function in the sounddevice library. This is the code I wrote to do this:

sounddevice.default.device = "Focusrite USB ASIO, ASIO"
sounddevice.default.samplerate = 48000
stream = sounddevice.OutputStream()
stream.start()
stream.write(data)

The last line code is giving me the error:

sounddevice.PortAudioError: Wait timed out [PaErrorCode -9987]

What am I doing wrong?

PetSven
  • 366
  • 3
  • 13

1 Answers1

2

The way I got it working was by using:

with sounddevice.OutputStream(device="Focusrite USB ASIO, ASIO", channels=8, callback=callback, samplerate=samplesPerSecond)

This repeatedly calls the callback function. In the callback function I set the output:

def callback(outdata, frames, time, status):
     for i in range(8):
          channels[i] = audioData
     multiChannel = np.column_stack((channels[0], channels[1], channels[2], channels[3], channels[4], channels[5], channels[6], channels[7]))
     outdata[:] = multiChannel
PetSven
  • 366
  • 3
  • 13
  • What are `channels` and `audioData` here? – vincent Nov 21 '21 at 01:25
  • I am playing the same sound to all eight channels. "audioData" is list containing the sound I want to play. "channels" is a 2D list containing eight copies of the audio data, one for each channel. – PetSven Jan 03 '23 at 19:12