I have taken an old script from the renpy wiki that does this effect and modified it to work with layeredimages and the animation happen when playing voice audio.
The script animates the lips while playing an audio or while the letters appear in the dialog box.
The script works thanks to a function named renpy.curry. I do not understand much of it, it is not documented in https://www.renpy.org/doc/html/, apparently it is a very powerful function, it would be great if someone explains it in a post or PyTom write a Patreon article.
If you do not understand about layered images there is a great post by BáiYù viewtopic.php?f=51&t=50764#p490465
Here is the script :
Code: Select all
init python:
# This is set to the name of the character that is speaking, or
# None if no character is currently speaking.
speaking = None
# This returns speaking if the character is speaking, and done if the
# character is not.
def while_speaking(name, speak_d, done_d, st, at):
if renpy.music.is_playing(channel='voice') or speaking == name:
return speak_d, .1
else:
return done_d, None
# Curried form of the above.
curried_while_speaking = renpy.curry(while_speaking)
# Displays speaking when the named character is speaking, and done otherwise.
def WhileSpeaking(name, speaking_d, done_d=Null()):
return DynamicDisplayable(curried_while_speaking(name, speaking_d, done_d))
# This callback maintains the speaking variable.
def speaker_callback(name, event, **kwargs):
global speaking
if event == "show":
speaking = name
elif event == "slow_done":
speaking = None
elif event == "end":
speaking = None
# Curried form of the same.
speaker = renpy.curry(speaker_callback)
Code: Select all
define aug = Character("Augustina", voice_tag="aug",callback=speaker("aug"))
image speaking_august:
"august_mouth_closed"
pause 0.2
"august_mouth_open"
pause 0.2
repeat
layeredimage august:
always "august_base"
group outfit auto:
attribute jeans default
group eyes auto:
attribute open default
group eyebrows auto:
attribute normal default
group mouth auto:
attribute smile default
attribute speaking:
WhileSpeaking("aug", "speaking_august", "august_mouth_closed")
group glasses auto
group emotion auto
label start:
"START"
show august speaking
# voice aug_voice01 ## TODO add your voice file
aug "Blah blah blah blah blah blah blah."
"END"
return
Code: Select all
default preferences.text_cps = 15