This is a script to change the sound speed in real time like for example background music in pygame.
The script generates the raw data of a sound file each time there is space in the queue. The sample will scale to the desired speed which you can modify with sound_Factor.
To play the music, you just need to get buffers from the queue and pass them to your music stream. Exemple for pygame :
# musique update
if channel.get_queue() == None:
_buffer = generate_music.Sounds_buffer.get()
channel.queue(pygame.mixer.Sound(_buffer))
elif not channel.get_busy() and not channel.get_queue():
_buffer = generate_music.Sounds_buffer.get()
channel.play(pygame.mixer.Sound(_buffer))
The script executes the main function in a Process so as to not overload our main loop.