How to put voice to Characters in Renpy (Character Callback)


Last night I decided to figure out how to put "Voices" for each character when they speak, like Undertale does. And to be honest the Renpy documentation had me covered on that one. 

I mean, you can put the "play voice" command before all lines, but the main problem goes that I have to do that for all lines, and really does not work for something like Undertale does. 

But eventually found out that the Character Object have something called Callback:

The Callback must be a function which has to get 2 variables. The first one is going to be called event and the second one is going to be called interaction. You can use this to tell Renpy to play a sound or voice for every time the Character "say" something. 

From the Renpy Docs:

init python: 

      def beepy_voice(event, interact=True, **kwargs):

           if not interact: 

                return 

           if event == "show_done": 

                 renpy.sound.play("beeps.ogg") 

           elif event == "slow_done":

                renpy.sound.stop() 

 define pike = Character("Christopher Pike", callback=beepy_voice) 

 label start:

      pike "So, hanging out on Talos IV, minding my own business, when..."

Here's created a Python function called "beepy_voice", which going to play when the speech appears (Thanks to the event "show_done") and going to stop when the speech stop appearing (The event "slow_done"). 

The main problem here though, is the fact renpy.sound.play just going to play the clip once, and that does not work for Undertale voice grunts, as they just, like, a second long. Just happens that Renpy.sound is a alias of Renpy.music but in the "sound" channel, meaning we can use all the music functions as per documentation

renpy.sound.play("beeps.ogg", loop=True) 

And with this renpy should loop the sound until the the sound is stopped thanks to slow_done. 

Edit: I just added a new tutorial for sound channels, which I think is a good idea to checkout after this. 

Get User Interface

Comments

Log in with itch.io to leave a comment.

(1 edit)

when i tried to implement the same thing, i got this.

I'm sorry, but errors were detected in your script. Please correct the

errors listed below, and try again.

File "game/script.rpy", line 3: expected statement.

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

what it shows is that there's supposed to be something in between "callback" and "(event," and i am wondering what it means... sorry if i sound like a dumbass but i started renpy a few weeks ago.


edit: i'm on ver 8.3.0

You explained this in a perfectly clear way! I was struggling until I came across your article. Thank you for this! <3