Bootstrap

python中加入声音_在python中同时播放多个声音

I have been looking into a way to play sounds from a list of samples, and I found some modules that can do this.

I am using AudioLazy module to play the sound using the following script:

from audiolazy import AudioIO

sound = Somelist

with AudioIO(True) as player:

player.play(sound, rate=44100)

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.

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.

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

解决方案

Here is a simpler solution using pydub.

Using overlay function of

;