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

Leave a comment

Log in with itch.io to leave a comment.