stop dialogue sound effect when other screen is showing

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
sherwinnie
Newbie
Posts: 13
Joined: Fri Mar 01, 2019 1:00 am
Contact:

stop dialogue sound effect when other screen is showing

#1 Post by sherwinnie »

Hello, I have been using the callback function from the old forum:

Code: Select all

def callback(event, **kwargs):
        if event == "show":
            renpy.music.play(sound_blip, channel="sound", loop=True)
        elif event == "slow_done" or event =="end":
            renpy.music.stop(channel="sound", fadeout = 0.2)
which pretty much does what I want it to do: the a sound effect continuously while the character is speaking, and stop accordingly.
However, just yesterday, I realized one bug: the sound won't stop if I call another screen in the middle of a dialogue, as in this video demonstrates: https://www.youtube.com/watch?v=eLqcu_2 ... e=youtu.be (the sound keeps play when I call the game menu screen)

I have been trying to add in condition in the callback function, such as:

Code: Select all

def callback(event, **kwargs):
        if event == "show":
            renpy.music.play(sound_blip, channel="sound", loop=True)
        elif not renpy.get_screen("say"):
            renpy.music.stop(channel="sound", fadeout = 0.2)
        elif event == "slow_done" or event =="end":
            renpy.music.stop(channel="sound", fadeout = 0.2)
or just:

Code: Select all

def callback(event, **kwargs):
        if event == "show":
            renpy.music.play(sound_blip, channel="sound", loop=True)
        elif renpy.get_screen("game_menu"):
            renpy.music.stop(channel="sound", fadeout = 0.2)
        elif event == "slow_done" or event =="end":
            renpy.music.stop(channel="sound", fadeout = 0.2)
however, these don't work out. Does anyone know a solution to this?

User avatar
auger
Newbie
Posts: 9
Joined: Tue Oct 16, 2018 2:48 am
Projects: Unnamed CYA Project
Contact:

Re: stop dialogue sound effect when other screen is showing

#2 Post by auger »

Try:

Code: Select all

def callback(event, **kwargs):
        if event == "show":
            renpy.music.play(sound_blip, channel="sound", loop=True)
        elif event == "slow_done" or event =="end" or event == "show_done": #I believe you should also be able to add| or renpy.get_screen("game_menu")
            renpy.music.stop(channel="sound", fadeout = 0.2)#The reason I'd recommend show_done as that it should stop the moment a say finishes.


No need to have multiple elif statements.
Try this, let me know if it works.
Life is short; be kind.

sherwinnie
Newbie
Posts: 13
Joined: Fri Mar 01, 2019 1:00 am
Contact:

Re: stop dialogue sound effect when other screen is showing

#3 Post by sherwinnie »

auger wrote: Sat Jun 01, 2019 11:21 am Try:

Code: Select all

def callback(event, **kwargs):
        if event == "show":
            renpy.music.play(sound_blip, channel="sound", loop=True)
        elif event == "slow_done" or event =="end" or event == "show_done": #I believe you should also be able to add| or renpy.get_screen("game_menu")
            renpy.music.stop(channel="sound", fadeout = 0.2)#The reason I'd recommend show_done as that it should stop the moment a say finishes.


No need to have multiple elif statements.
Try this, let me know if it works.
adding event=="show_done" shuts all the sound effect down. and adding or renpy.get_screen("game_menu") doesn't really work other either...thanks for the suggestion, though!

User avatar
auger
Newbie
Posts: 9
Joined: Tue Oct 16, 2018 2:48 am
Projects: Unnamed CYA Project
Contact:

Re: stop dialogue sound effect when other screen is showing

#4 Post by auger »

Oh, I'm an idiot! :lol: Well, maybe not entirely an idiot, but I zoomed through your code.
Do you mind trying something else? This one is straight from the documentation, and will probably work better, anyway.

Code: Select all

#init python: Just to remind you that this goes under the init
    def character_voice(event, interact=True, **kwargs):
        if not interact:
            return

        if event == "show_done":
            renpy.sound.play("sound_blip.ogg")
        elif event == "slow_done":
            renpy.sound.stop()

#define charanamehere = Character("charanamehere", callback=character_voice)
#Just add the callback function to your characters
#and ofc you can have different voices if you want, down the line


In the interest of trying to figure out where I messed up your code, I think it's because we had multiple references to both music and sound channels. That would explain the death of all audio, aha. I doubt this 'fixed' version will work, but just in case...

Code: Select all

def callback(event, **kwargs):
        if event == "show":
            renpy.sound.play(sound_blip, channel="sound", loop=True)
        elif event == "slow_done" or event =="end" or event == "show_done":
            renpy.sound.stop(channel="sound", fadeout = 0.2)
Anyway, this ought to do the trick. :)
(else) If not, I'll crack open something for serious and see what I can't get out.
Life is short; be kind.

sherwinnie
Newbie
Posts: 13
Joined: Fri Mar 01, 2019 1:00 am
Contact:

Re: stop dialogue sound effect when other screen is showing

#5 Post by sherwinnie »

auger wrote: Sat Jun 01, 2019 11:51 am Oh, I'm an idiot! :lol: Well, maybe not entirely an idiot, but I zoomed through your code.
Do you mind trying something else? This one is straight from the documentation, and will probably work better, anyway.

Code: Select all

#init python: Just to remind you that this goes under the init
    def character_voice(event, interact=True, **kwargs):
        if not interact:
            return

        if event == "show_done":
            renpy.sound.play("sound_blip.ogg")
        elif event == "slow_done":
            renpy.sound.stop()

#define charanamehere = Character("charanamehere", callback=character_voice)
#Just add the callback function to your characters
#and ofc you can have different voices if you want, down the line


In the interest of trying to figure out where I messed up your code, I think it's because we had multiple references to both music and sound channels. That would explain the death of all audio, aha. I doubt this 'fixed' version will work, but just in case...

Code: Select all

def callback(event, **kwargs):
        if event == "show":
            renpy.sound.play(sound_blip, channel="sound", loop=True)
        elif event == "slow_done" or event =="end" or event == "show_done":
            renpy.sound.stop(channel="sound", fadeout = 0.2)
Anyway, this ought to do the trick. :)
(else) If not, I'll crack open something for serious and see what I can't get out.
unfortunately this still doesn't really work out...I have tried both of the codes that you provide, but the first one doesn't stop the sound effect, and the second one, well...the sound effect is still gone (but the music and other channels are going fine, though).

I wonder if I can try a while loop like "for every second check the condition" , but I am also afraid that it will take up too much performance of the machine.

And also, can this be something wrong with my version of Ren'Py? I mean, I have downloaded the latest version (7.2.2), but I also think it is unlikely for the documentation to have a bug that is this obvious...

Still, thanks for the suggestion!

User avatar
auger
Newbie
Posts: 9
Joined: Tue Oct 16, 2018 2:48 am
Projects: Unnamed CYA Project
Contact:

Re: stop dialogue sound effect when other screen is showing

#6 Post by auger »

Hrmn, that's a puzzle... For the first example, you're using slowtext/{cps}{/cps} tags, right?
It's only work with those. I wouldn't worry too much about performance, my toaster is about eleven years old this point and - like me - still creaking on. 8)
No, I don't believe it's your version of Ren'Py. It's more likely that I am missing something obvious in my attempts to assist you.

Still, we've got nothing but time, and making mistakes is a good tutor.
Let me know if you'd be willing to copy what you've got so far, or let me know the approximate length of whatever sound file you're using.
It's possible your test dialogue is so short maybe it's finished scrolling before it has chance to play?
Life is short; be kind.

sherwinnie
Newbie
Posts: 13
Joined: Fri Mar 01, 2019 1:00 am
Contact:

Re: stop dialogue sound effect when other screen is showing

#7 Post by sherwinnie »

Sure, I will post the code once I get home (cuz I’m outside).

I am thinking that maybe I can try playing the audio only once at the every start of the dialogue, although it would like of lose a flavor...

sherwinnie
Newbie
Posts: 13
Joined: Fri Mar 01, 2019 1:00 am
Contact:

Re: stop dialogue sound effect when other screen is showing

#8 Post by sherwinnie »

So, I kind of find the trick, which is to use the voice channel instead of the sound channel, as the following:

Code: Select all

def callback(event, interact=True, **kwargs):
        if not interact:
            return

        if event == "show" or event == "begin" or event == "show_done":
            renpy.music.play(sound_blip, channel="voice", loop=True)
        elif event == "slow_done" or event =="end":
            renpy.music.stop(channel="voice", fadeout = 0.2)
however, there is still a major flaw: it only works after a {w} or a {p} tag. For example, the following line will have no blip sound:

e "hello, how's going?"

but this will have the blip sound after the {w=0} tag (namely, the "how's going?" line):

e "hello, {w=0}how's going?"

Or the following line will continuously have the sound––from start to the end:

e "{w=0}hello, {w=0}how's going?"

So, problem solved....? Well yes, but actually no, because now I have to add the {w=0} tag to every single line, which is...certainly not the most effective way. It can be done, though. I will stick around to try finding a perfect solution, or to see if anyone has a suggestion to the problem.

Thank you!

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: stop dialogue sound effect when other screen is showing

#9 Post by philat »

Eh. Wouldn't it be simpler to just pause the channel on showing/hiding the screen?

Code: Select all

screen blahblah():
    on "show" action PauseAudio("voice", "toggle")
    on "hide" action PauseAudio("voice", "toggle")

Post Reply

Who is online

Users browsing this forum: Andredron