Can Lip Flap Be Synched (Sync / Synced) With Voice [solved]

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
User avatar
leon
Miko-Class Veteran
Posts: 554
Joined: Sun Oct 09, 2011 11:15 pm
Completed: Visual Novel Tycoon, Night at the Hospital, Time Labyrinth, The Buried Moon, Left of Center, Super Otome Quest
Projects: Lemon Project, Porcelain Heart, Dream's Dénouement
Organization: Team ANARKY
Contact:

Can Lip Flap Be Synched (Sync / Synced) With Voice [solved]

#1 Post by leon »

I'm using Blink And Lip Flap code which makes the character's mouth move while the text is being displayed and it stops when the text is fully displayed. For a fully voiced game, is it possible to have the character's mouth move, while the voice is playing instead?
Last edited by leon on Tue Feb 25, 2014 5:46 pm, edited 2 times in total.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Can Lip Flap Be Synched With Voice

#2 Post by xela »

leon wrote:I'm using Blink And Lip Flap code which makes the character's mouth move while the text is being displayed and it stops when the text is fully displayed. For a fully voiced game, is it possible to have the character's mouth move, while the voice is playing instead?
I can't see why not but you're prolly looking for an advice from someone who's actually done this before :)
Like what we're doing? Support us at:
Image

Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: Can Lip Flap Be Synched With Voice

#3 Post by Asceai »

I haven't done this before either, but if I'd have to guess how to modify the code, I'd probably replace while_speaking with:

Code: Select all

    def while_speaking(name, speak_d, done_d, st, at):
        if renpy.music.is_playing('voice'):
            return speak_d, .1
        else:
            return done_d, None
This might be a bit naive though- there's probably other considerations I'm forgetting.
EDIT: For example, making sure that the right character is actually speaking...

Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: Can Lip Flap Be Synched With Voice

#4 Post by Asceai »

Alright, here we go:

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('voice') and 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
        speaking = name
  
    # Curried form of the same.
    speaker = renpy.curry(speaker_callback)

User avatar
leon
Miko-Class Veteran
Posts: 554
Joined: Sun Oct 09, 2011 11:15 pm
Completed: Visual Novel Tycoon, Night at the Hospital, Time Labyrinth, The Buried Moon, Left of Center, Super Otome Quest
Projects: Lemon Project, Porcelain Heart, Dream's Dénouement
Organization: Team ANARKY
Contact:

Re: Can Lip Flap Be Synched With Voice

#5 Post by leon »

Thank you very much Asceai! It works perfectly! :D

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Can Lip Flap Be Synched With Voice [solved]

#6 Post by xela »

Could you rename the thread to include the word "sync" (synced or synchronized) as well? Synched does not seem to show up in searches and this can be very useful to others.
Like what we're doing? Support us at:
Image

User avatar
leon
Miko-Class Veteran
Posts: 554
Joined: Sun Oct 09, 2011 11:15 pm
Completed: Visual Novel Tycoon, Night at the Hospital, Time Labyrinth, The Buried Moon, Left of Center, Super Otome Quest
Projects: Lemon Project, Porcelain Heart, Dream's Dénouement
Organization: Team ANARKY
Contact:

Re: Can Lip Flap Be Synched (Sync / Synced) With Voice [solv

#7 Post by leon »

Sure, I added these too. Synchronized makes the title too long...

cosmo
Regular
Posts: 120
Joined: Mon Aug 29, 2011 11:01 am
Projects: | ZUKUNFT | Wayang Kulit - A Shadow Play (WIP version 0.1) |
Location: Germany
Contact:

Re: Can Lip Flap Be Synched (Sync / Synced) With Voice [solv

#8 Post by cosmo »

I think this could be a nice addition to the wiki article as well…

hmmm… How to add that now! :D
Project: Wayang Kulit - A Shadow Play
Status: First demo version "Proof of Concept" of my first project is out.

ZeroQ
Newbie
Posts: 20
Joined: Thu Jun 21, 2012 12:05 am
Contact:

Re: Can Lip Flap Be Synched (Sync / Synced) With Voice [solv

#9 Post by ZeroQ »

This is an excellent alteration to an already excellent code. Thanks a lot, Asceai! :3

I hope that one day somebody discovers a way to implement full animation/audio synching into Ren'py. Although I don't know how many people besides myself and a few others, are interested in such a feature.
I also realize that this would be a difficult thing to accomplish and may even require the aid of third-party software, but it would be a nice little feature to have in the engine.

Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: Can Lip Flap Be Synched (Sync / Synced) With Voice [solv

#10 Post by Asceai »

It's really hard to do anything timing-dependent with audio in ren'py - you can play a sound but you don't know when it will start and you can't detect it. I don't know exactly why but renpy uses pygame which uses SDL1 which I recall liked to create huuuuge audio buffers.

If you give me some graphics (a character with a lip-flap animation) and a voice file I'll play around with this for you, but no promises. I've looked at the code to do this in commercial VNs so I've got a bit of an idea, just a matter of getting it to work in Ren'Py

ZeroQ
Newbie
Posts: 20
Joined: Thu Jun 21, 2012 12:05 am
Contact:

Re: Can Lip Flap Be Synched (Sync / Synced) With Voice [solv

#11 Post by ZeroQ »

Asceai wrote:It's really hard to do anything timing-dependent with audio in ren'py - you can play a sound but you don't know when it will start and you can't detect it. I don't know exactly why but renpy uses pygame which uses SDL1 which I recall liked to create huuuuge audio buffers.
LOL, so I've noticed. There used to be another code for lip synching, where you would have to manually input the duration of each individual frame of animation whenever you wanted to have a character talking. It was virtually impossible to properly sync it with voice audio. What's worse is that the animation wouldn't automatically stop when you clicked to progress the story, so you would sometimes have Character #1's mouth still moving while Character #2 was talking.
Asceai wrote:If you give me some graphics (a character with a lip-flap animation) and a voice file I'll play around with this for you, but no promises. I've looked at the code to do this in commercial VNs so I've got a bit of an idea, just a matter of getting it to work in Ren'Py
I'll try and get something to you soon, then. Even if you aren't able to find a solution, I appreciate the help. Thanks.
^_^

Post Reply

Who is online

Users browsing this forum: No registered users