Script Automatic Lipsync?

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

User avatar
slowtiger
Posts: 6089
Joined: Thu Feb 16, 2006 6:53 pm
Location: Berlin, Germany
Contact:

Script Automatic Lipsync?

Post by slowtiger »

Automatic lipsync is a godsend in some situations. Just open the switch layer tab, open the audio tab, select the one audio file in the scene and it creates all the keyframes.

Well. Unless you have that switch layer in several versions/views, and lots of characters and lots of scenes.

Would it be possible to write a script like
"- search for switch layer named "mouth"
- open its audio tab
- assign the one audio file in the project to it
- search next switch layer named "mouth""
etc
and will Moho create the keys as expected?
AS 9.5 MacPro Quadcore 3GHz 16GB OS 10.6.8 Quicktime 7.6.6
AS 11 MacPro 12core 3GHz 32GB OS 10.11 Quicktime 10.7.3
Moho 13.5 iMac Quadcore 2,9GHz 16GB OS 10.15

Moho 14.1 Mac Mini Plus OS 13.5
User avatar
synthsin75
Posts: 10013
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Script Automatic Lipsync?

Post by synthsin75 »

Not possible by script. The only access we have is to assign a .dat file to a switch. Moho does nothing when trying to use that to apply an audio file.

So we'd be left with maybe copying keyframes. If the phonemes across all switches have the same names, that would work.

But if the phonemes across all switches have the same names, we could just use reference layers of a single switch to keep them synced with the auto-lipsync switch. As long as the sublayers have the same names, it doesn't matter what their content is.
User avatar
slowtiger
Posts: 6089
Joined: Thu Feb 16, 2006 6:53 pm
Location: Berlin, Germany
Contact:

Re: Script Automatic Lipsync?

Post by slowtiger »

Well, that settles that. Thank you!

But that reference layer is an idea I should try.
AS 9.5 MacPro Quadcore 3GHz 16GB OS 10.6.8 Quicktime 7.6.6
AS 11 MacPro 12core 3GHz 32GB OS 10.11 Quicktime 10.7.3
Moho 13.5 iMac Quadcore 2,9GHz 16GB OS 10.15

Moho 14.1 Mac Mini Plus OS 13.5
User avatar
slowtiger
Posts: 6089
Joined: Thu Feb 16, 2006 6:53 pm
Location: Berlin, Germany
Contact:

Re: Script Automatic Lipsync?

Post by slowtiger »

OK, the reference layer idea was nice.

Thinking: if I create a switch layer, put it inside the bone layer, import some images a1 a2 a3, then create a reference layer from this switch layer, put it elsewhere, re-name it exactly as the original layer, then creating automatic lipsynce in the original switch should be replicated in ist reference layer.

Result: This works.

Thinking: Now I exchange the images in the reference layers with other, which are named a1 a2 a3 as well, this should work too.

Result: No, it doesn't. It doesn't make a difference wether I just import those images or replace the souce image image by image: as soon as there's a different bitmap the reference is broken. It also doesn't work to create a reference layer from an empty switch layer and fill the switches later, in this case nothing happens at all.

Conclusion: Referencing from a switch layer only works with an exact copy and identical content of the switches, and all layers inside the reference switch need to show that "reference" arrow marker as well.

Oh, it was such a nice dream ...
AS 9.5 MacPro Quadcore 3GHz 16GB OS 10.6.8 Quicktime 7.6.6
AS 11 MacPro 12core 3GHz 32GB OS 10.11 Quicktime 10.7.3
Moho 13.5 iMac Quadcore 2,9GHz 16GB OS 10.15

Moho 14.1 Mac Mini Plus OS 13.5
User avatar
Greenlaw
Posts: 9386
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: Script Automatic Lipsync?

Post by Greenlaw »

Hm...I think it shouldn't matter because the Switch layer itself only cares about the stacking order of the child layers, not the contents of the child layers. You might try breaking the reference connections for the Switch Layer's contents but keep the connection for the Switch Layer (where the switch keyframes are stored.)
Last edited by Greenlaw on Sat Jul 23, 2022 9:20 pm, edited 1 time in total.
User avatar
SimplSam
Posts: 1066
Joined: Thu Mar 13, 2014 5:09 pm
Location: London, UK
Contact:

Re: Script Automatic Lipsync?

Post by SimplSam »

slowtiger wrote: Sat Jul 23, 2022 4:34 pm OK, the reference layer idea was nice.
...
Oh, it was such a nice dream ...
From what I am reading you want multiple switch layers to share the same synchronised switching?

If so, can you not create the master lipsync switch and then copy the master switch keyframes to the replica switch layers - each with their unique content?
Moho 14.1 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam


Sam
User avatar
slowtiger
Posts: 6089
Joined: Thu Feb 16, 2006 6:53 pm
Location: Berlin, Germany
Contact:

Re: Script Automatic Lipsync?

Post by slowtiger »

then copy the master switch keyframes to the replica switch layers
Exactly this is the step I want to avoid - to go inside several switch layers and do something there - it would take the same time as to open each switch and assign that audio file to it.
I think It shouldn't matter because the Switch layer itself only cares about the stacking order of the child layers, not the contents of the child layers.
That was my thought too, but I tested it in every direction and it simply doesn't work. Maybe a feature request? (Too late for this project ...)
AS 9.5 MacPro Quadcore 3GHz 16GB OS 10.6.8 Quicktime 7.6.6
AS 11 MacPro 12core 3GHz 32GB OS 10.11 Quicktime 10.7.3
Moho 13.5 iMac Quadcore 2,9GHz 16GB OS 10.15

Moho 14.1 Mac Mini Plus OS 13.5
User avatar
SimplSam
Posts: 1066
Joined: Thu Mar 13, 2014 5:09 pm
Location: London, UK
Contact:

Re: Script Automatic Lipsync?

Post by SimplSam »

slowtiger wrote: Sat Jul 23, 2022 9:14 pm Exactly this is the step I want to avoid - to go inside several switch layers and do something there - it would take the same time as to open each switch and assign that audio file to it.
OK. The keyframe copying can be scripted. Wes already has a Copy Layer Parameters tool. This would make a nice addition (hint hint).

greenlaw wrote:I think It shouldn't matter because the Switch layer itself only cares about the stacking order of the child layers, not the contents of the child layers.
slowtiger wrote:That was my thought too, but I tested it in every direction and it simply doesn't work. Maybe a feature request? (Too late for this project ...)
Yeah - Switch layers only care about Layer Names, order is not important (except the top layer which gets chosen if no valid child-layer is active).
Moho 14.1 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam


Sam
User avatar
Greenlaw
Posts: 9386
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: Script Automatic Lipsync?

Post by Greenlaw »

slowtiger wrote: Sat Jul 23, 2022 9:14 pm That was my thought too, but I tested it in every direction and it simply doesn't work. Maybe a feature request? (Too late for this project ...)
It really should work. Here's an example I threw together in Moho 13.5.5

Image

The pose SBD opens and closes the hand, and the turn SBD turns the hand. Notice that pose drawings stay in sync as the hand turns.

On the right, you can see the three pose Switches and two of them are references, but the drawing layers are not referenced, they're all unique drawing layers. So it appears Moho just looks at the layer order, not the layer ID.

When I set up the two Smart Bone Actions, turn is animating the Switch Layer called hand to switch between hand_palm (original), hand_side (ref), and hand_back (ref), and pose is only animating hand_palm. Because hand_side and hand_back are references of the original hand_palm Switch Layer, they follow the animation of the hand_palm.

If this isn't working in your project, make sure the reference switch layers are synchronized to the original switch layer. You can do this by right-clicking each reference and selecting Sync All Channels To Original.

If you referenced the drawing layers, you can break the reference connection by choosing Break Layer Reference. Breaking the references here will prevent any unwanted modifications from occurring.

Here's the project if you want to pick it apart...

multiSwitchHands

Hope this helps.
Last edited by Greenlaw on Sun Jul 24, 2022 9:25 pm, edited 7 times in total.
User avatar
synthsin75
Posts: 10013
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Script Automatic Lipsync?

Post by synthsin75 »

slowtiger wrote: Sat Jul 23, 2022 4:34 pm Thinking: Now I exchange the images in the reference layers with other, which are named a1 a2 a3 as well, this should work too.

Result: No, it doesn't. It doesn't make a difference wether I just import those images or replace the souce image image by image: as soon as there's a different bitmap the reference is broken. It also doesn't work to create a reference layer from an empty switch layer and fill the switches later, in this case nothing happens at all.

Conclusion: Referencing from a switch layer only works with an exact copy and identical content of the switches, and all layers inside the reference switch need to show that "reference" arrow marker as well.

Oh, it was such a nice dream ...
No, I just verified that it does work. Maybe you missed the step of right-clicking the switch layer channel and selecting Sync Channel To Original? This works, even if you have extra layers and in a different order. This is because all the switch layer channel stores are the sublayer names that are keyframed. Doesn't matter the layer order or if there are extra, unkeyed layers. You can either change the content of each layer, or even delete all the layers and recreate them with different content. The only thing that matters is that for every switch sublayer keyframed in the original, there exists one with the exact same name in the reference.

Once synced with the new content, the reference will then automatically match the original.
User avatar
synthsin75
Posts: 10013
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Script Automatic Lipsync?

Post by synthsin75 »

SimplSam wrote: Sat Jul 23, 2022 10:01 pm OK. The keyframe copying can be scripted. Wes already has a Copy Layer Parameters tool. This would make a nice addition (hint hint).
Unless I've complete forgotten about another script I wrote, I don't think that one's mine.
User avatar
SimplSam
Posts: 1066
Joined: Thu Mar 13, 2014 5:09 pm
Location: London, UK
Contact:

Re: Script Automatic Lipsync?

Post by SimplSam »

OK - my mistake :oops: . It was written by Stan (SZ_CopyLayerParameters).
Moho 14.1 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam


Sam
User avatar
Greenlaw
Posts: 9386
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: Script Automatic Lipsync?

Post by Greenlaw »

synthsin75 wrote: Sat Jul 23, 2022 11:46 pm The only thing that matters is that for every switch sublayer keyframed in the original, there exists one with the exact same name in the reference.
@Synthsin75,
Ooooh! I didn't realize this...probably because I'm so 'OCD' about naming everything that I never had a problem with this. Anyway, I tried changing every layer name and you're right, it breaks things and the setup goes crazy.

@everyone else,
So, yes, be sure to keep your layer names sync'd between Switch Layers. The layers can have totally different content but the names must be consistent. :D
User avatar
Greenlaw
Posts: 9386
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: Script Automatic Lipsync?

Post by Greenlaw »

I tried shuffling the layer order inside two of the switches, and the SDB setup still worked correctly.

So, confirming what Wes wrote above: layer order does not matter but layer names do.
User avatar
synthsin75
Posts: 10013
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Script Automatic Lipsync?

Post by synthsin75 »

The only time layer order matters in a switch layer is when you're not using Preston Blair phonemes and Moho is just using audio amplitude to set the switches. The louder the audio, the higher in the layer order.
Post Reply