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.
Sorry I'm not sure to understand what you means. If it's that you want to access the actual factor of the player. It's totally possible you just have to access the attribute
.value
of the factor value you passed when creating your Process.Here is an example of the class I personally used to manage my worker :
I just init my class in a variable accessible in my main loop and when I want to access or change the value of the factor I just do
mygenerator.speed_factor.value
andmygenerator.speed_factor.value = x
. If you want to access the frame_rate of theAudioSegment
directly without interacting with the factor I guess you will need to adapt the function a little bit. Since you are working in another process you will need to use aValue()
to communicate between both process.