Play multiple sounds at the same time in python
<p>I have been looking into a way to play sounds from a list of samples, and I found some modules that can do this.</p>

<p>I am using <strong>AudioLazy</strong> module to play the sound using the following script:</p>

<pre><code>from audiolazy import AudioIO

sound = Somelist
with AudioIO(True) as player:
  player.play(sound, rate=44100)
</code></pre>

<p>The problem with this code is that it stop the whole application till the sound stop playing and I can't play multiple sound at the same time.</p>

<p>My program is interactive so what I want is to be able to play multiple sound at the same time,So for instance I can run this script which will play a 5 second sound then at the second 2 I can play a 5 second sound again.</p>

<p>And I don't want the whole program to stop till the sound finish playing.</p>

<p>I suggest using <a href="https://people.csail.mit.edu/hubert/pyaudio/docs/" rel="nofollow">Pyaudio</a> to do this.</p>

<pre><code>sound1 = wave.open("/path/to/sound1", 'rb')
sound2 = wave.open("/path/to/sound2", 'rb')

def callback(in_data, frame_count, time_info, status):
    data1 = sound1.readframes(frame_count)
    data2 = sound2.readframes(frame_count)
    decodeddata1 = numpy.fromstring(data1, numpy.int16)
    decodeddata2 = numpy.fromstring(data2, numpy.int16)
    newdata = (decodeddata1 * 0.5 + decodeddata2* 0.5).astype(numpy.int16)
    return (result.tostring(), pyaudio.paContinue)
</code></pre>

python audio interactive