Trying to use Pydub in Renpy

DiviDreamer

Member
Aug 29, 2020
262
229
Hi i try to use Pydub in Renpy all works fine but i NEED to use native Renpy play (like play sound "fx.wav") from memory or pointer
all i can do now is save wave after pydub translate file and then load it from disk again
it seems pydub use own wav format after calling AudioSegment

so i need something like this:

sound = AudioSegment.from_file("samples.wav")
translated_sound = do_something(sound )
play sound translated_sound

Thanks, hope someone point me right direction.


Code sample:
from pydub import AudioSegment
from pydub.playback import play

sound = AudioSegment.from_file('samples/piano_c2.wav', format="wav")
#play(sound)

octaves = 1.5
new_sample_rate = int(sound.frame_rate * (2.0 ** octaves))
hipitch_sound = sound._spawn(sound.raw_data, overrides={'frame_rate': new_sample_rate})
hipitch_sound = hipitch_sound.set_frame_rate(44100)

play(hipitch_sound)