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.
Using multiple threads will solve your problem :
I suggest using Pyaudio to do this.
Here is a simpler solution using pydub.
Using
overlay
function ofAudioSegment
module, you can very easilysuperimpose
multiple audio on to each other.Here is a working code to combine three audio files. Using same concept you can combine multiple audio onto each other.
More on
overlay
function herepydub
supports multiple audio formats as well.Here are updates as per our discussions.
First we create 44KHz signal and save to
sound.wav
Next Read wave file and save signal to text file
Then create three variations of input signal to test overlay.
Original signal has
dtype int16
Then we create three audio segments then mix/overlay as above.
wav
signal data is stored intest.txt
Working Modified Code