How to implement "background voice"?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
balloon2036
Newbie
Posts: 1
Joined: Sat Sep 04, 2021 10:12 am
Contact:

How to implement "background voice"?

#1 Post 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.

Post Reply

Who is online

Users browsing this forum: Google [Bot], henne