Page 1 of 1

How to implement "background voice"?

Posted: Sat Sep 04, 2021 10:25 pm
by balloon2036
What I mean by background voice:
1. when no one speaks, background voice loops (like BGM).
2. when a character speaks, background voice is paused (or volume reduced) until the character voice finishes (so we can hear character voice clearly).

From the documentation, I can't find how to enable a callback after a voice is finished.
So I try using renpy.music.set_queue_empty_callback, the following code somehow works.
(It reduces the volume of "back_voice" channel to 0.1 and resumes original volume in callback)

Code: Select all

    renpy.music.register_channel("char_voice", mixer="voice", loop=False, stop_on_mute=True, tight=False)
    renpy.music.register_channel("back_voice", mixer="voice", loop=True, stop_on_mute=True, tight=False)

    def resume_back_voice():
        renpy.music.set_volume(0.5, delay=0.5, channel="back_voice")

    def play_char_voice(file):
	renpy.music.set_volume(0.1, delay=0.5, channel="back_voice")
        renpy.music.play(_audio_eval(file), channel="char_voice", relative_volume=1.0)
        renpy.music.queue("<silence 1.0>", channel="char_voice")
        renpy.music.queue("<silence 1.0>", channel="char_voice")
        renpy.music.set_queue_empty_callback(resume_back_voice, channel='char_voice')
            
    def play_back_voice(file):
        renpy.music.play(_audio_eval(file), fadeout=1.0, fadein=1.0, loop=True, channel="back_voice", relative_volume=0.5)
But since I can't use voice() to play the character voice, I can't access some voice functionalities like character tag and voice history.
Any suggestion on how to implement it properly? Thanks in advance.