Play multiple sound files on multiple output devices with Python and sounddevice

Ever wanted to have multiple different sound files playing on different output devices attached to a host computer? Say you’re writing a DJing application where you want one mix for headphones and one for the speakers. Or you’re doing some sort of kiosk or art installation where you have many sets of speakers that need to all be playing their own sound file but the whole thing needs to be synchronized. This would even be cool for something like an escape room.

The ladder example is where I needed this bit of code. I’ve been working with interdisciplinary artist Sara Dittrich on a few projects recently and she asked if I could come up with a way to play 8 different mono sound files on 8 different loudspeakers. Here’s a video of the whole setup in action, and an explanation of the project:

I’ve wrapped up all of the code for the art installation project, and that can be found in a github repo here. It includes the startup functionality etc. If you’re interested in recreating the video above, that repo would be a good starting place. The following is a list of the parts used to make that build happen:

Multi-Audio Example

It is worth it to give a simple example of how to play multiple files on multiple audio devices using python. I couldn’t find an examples on how to do this online and had to spend some time experimenting to make it all come together. Hopefully this saves you the trouble.

To install sounddevice on my Raspberry Pi, I had to run the following commands:

For this example, let’s say there are 4 audio files in the same directory as , so the directory looks like this:

The code is based on the sounddevice library for python, whose documentation is pretty sparse. This script will find the audio files, and then play them on as many devices as there are attached. For example, if you have 3 sound devices it will play 1.wav, 2.wav and 3.wav on devices 1-3. If you have any questions, feel free to ask:

Here are some more photos of the build:


  1. Thx! your job he inpire me.

    i work in a escape game in france

    i made a equivalent system in C++ with 3D sound gestion
    you can use 4 sound card too
    you can add sound in a config file and with a client in RAW like putty send a json in the 3216 port
    launch the sound, make it move with dopler effect etc..

    it’s always in WIP but if you want to take look … ( i need to clean the repo to 🙂 )

  2. Great work, I need to do something like this, so this resource is saving me some time!
    How can I best talk with you in more detail?

  3. Thank you very much, I was looking for something like this ! Works almost perfectly, however I noticed that it sounds like you have to divide the samplerate by the number of usb devices to get the play duration right… Is that just me ?

  4. Hey Devon!

    I’m Aga. I’m an artist currently working on a project that requires a similar set up.

    First of all great job! I’m very impressed with how clean your work is.

    I have a question about controlling the sound output. In my piece it is crucial that the sound loops play on their own and only overlap sporadically. I would like to crete two different situations that will interchange randomly. Firstly, I would like for one speaker to play while others are silent and sedondly to sometimes play different sounds simultaneously on several speakers.
    Each speaker would have an assigned and distinct sound loop (it will be fragments of interviews and each speaker will effectively represent one person). So the sounds would not migrate between the 12 speakers.

    I am wondering if using the set up with the usb to jack solution will allow me to asign each speaker its ‘identity’ and programme the interaction between them? Some sort of order of the sounds. Either random or pre-designed – im interested in both.

    Thank you for any kind of pointers!

    All the best,

    1. Yeah that would be totally possible. You could get creative with joining the audio playback threads.

      This is the existing implementation:

      for thread in threads:

      for thread, device_index in zip(threads, usb_sound_card_indices):
      print("Waiting for device", device_index, "to finish")

      If you wanted the files to playback in a sequence, you’d use:

      for thread in threads:

      That way, you’d never get overlap.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.