Play a lot of sounds in Python asynchronously

Viewed 1171

I would like to play sound in Python with these requirements:

  1. Multiple sounds at once
  2. Asynchronous
  3. Works on Linux

So here's an example of how this command should work:

while(True):
    play(sound)
    time.sleep(0.05)

This should massively spam the sound, EXACTLY 20 times a second

So far, I've tried: PyDub, PlaySound, PyGame.mixer (with channels)
PyGame did succeed in being asynchronous, but none of these were able to play the same multiple sounds at the same time, for me

Testing done on Linux, Python 3.5.2
Both solutions for Py2 and Py3 are welcome

1 Answers

I had no problem with getting multiple sounds to play at the same time with pygame and python3 code examples will probably be useful.

Note pygame.mixer.music only supports one file to be played at a time you need to use pygame.mixer.sound

Related