Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Animate Checkbox to Audio Waveform

  • Animate Checkbox to Audio Waveform

    Posted by Sean Hellwig on July 17, 2007 at 11:41 pm

    Hello, heres my situation
    I have a project that requires basic animation of a mouth opening and closing. This is done via an expression based check box. I key frame the check box on (opens mouth), off (closes mouth). now ive been manually doing this nearly frame by frame while looking at the waveform to see the pauses in speech. My question. is there an easier / more automatic way to achieve this, taken the pauses in speech which would result in a closed mouth, or no movement? I hope ive explained myself properly. Thank you very very much in advance.

    Specs:
    G5 Quad Power PC 2.5
    8GB RAM
    After Effects 7
    Nucleo saves my life

    Dan Ebberts replied 18 years, 10 months ago 3 Members · 9 Replies
  • 9 Replies
  • Dan Ebberts

    July 18, 2007 at 12:23 am

    You could convert the audio to keyframes and start with something simple like this:

    threshold = 5.0;
    level = thisComp.layer(“Audio Amplitude”).effect(“Both Channels”)(“Slider”);

    if (level > threshold){

    // mouth open code goes here

    }else{

    // mouth closed code goes here

    }

    Dan

  • Mike Clasby

    July 18, 2007 at 12:41 am

    I don’t fully get how your checkbox triggers the animation, is it telling Time remapping to choose one frames or another?

    Anyway, have you seen Aharon’s tut on using time remapping keyframes to match phonemes to different mouth shapes: it’s here:

    Lip-Synching for Character Animation

    https://library.creativecow.net/articles/rabinowitz_aharon/lip_synch.php

    You could use a similar setup to have the audio levels drive which mouthshape to use, especially in your limited open/closed setup.

    If you download Aharon’s project file, open up the comp “Mouths”. Put you close mouth at frame zero, and your open mouth at frame1.

    Open the “Mr. Face” comp. Take you audio layer and convert it to keyframes, Animation>Keyframe Assistant>Convert Audio to Keyframes.

    In the new Audio Amplitude layer that appears, UU reveals the Sliders.

    We’ll put an expression on the Mouths layer (it’s a precomp in that same Mr. Face comp) to have the audio drive the time remapping. So, select the [Mouths] layer, E reveals Time Remap, and Alt click the Time Remap stopwatch and Paste in the following expression (oh, yeah, you need to copy the expression below first):

    AudioTrigger = 3 // amount of Audio Amplitude to trigger mouth open
    if (thisComp.layer(“Audio Amplitude”).effect(“Both Channels”)(“Slider”) < AudioTrigger) 0 else 1/29 This just tells the Time Remap to use frame 0 if the Audio Amplitude in the Slider for Both Channels if less than 3, and to use frame 1 if it's 3 or more. Set that AudioTigger to a level that works for you. The 3 worked on Aharon's Mr. Face comp. It sound a little complicated but it makes that mouth open and close automatically.

  • Mike Clasby

    July 18, 2007 at 12:42 am

    Yikes, to slow again.

  • Mike Clasby

    July 18, 2007 at 1:08 am

    OK, stealing from Dan (what I do best) and then hacking away, this expression if put on your checkbox (Alt-click that Checkbox Stopwatch and Paste), should turn that checkbox on or off depending on those audio keyframes. That should be easier for you to use your existing setup.

    threshold = 5.0;
    level = thisComp.layer(“Audio Amplitude”).effect(“Both Channels”)(“Slider”);
    control = effect(“Checkbox Control”)(“Checkbox”) ;

    if (level > threshold){
    control == 0
    }else{
    control == 1
    }

    If your setup has another layer reading that checkbox, this works.

    But if the checkbox has an expression on it that drives the expression, no go.

  • Sean Hellwig

    July 18, 2007 at 3:57 am

    Thank you so much everybody for the quick responses. I love the cow.. I will try out some of your suggestions and let you know how it goes. Thanks again!

  • Sean Hellwig

    July 18, 2007 at 4:27 pm

    thanks again all of you for your responses advice thus far…

    Heres where im at, using the code below

    threshold = 5.0;
    level = thisComp.layer(“Audio Amplitude”).effect(“Both Channels”)(“Slider”);
    control = effect(“mouthOnOff”)(“Checkbox”) ;

    if (level > threshold){
    control == 0
    }else{
    control == 1

    }

    This code seems to work great as far as determining the pauses in speech, however the mouth does not open and close nearly enough during the speaking.. note: im not looking for 100% perfection, but something somewhat convincing. so when the level > threshold i need the value you to alternate between 0 (mouth open), and 1 (mouth closed). I tried inserting a loop here (see attempt code below), but its not working out. ideas anyone?

    Attempt code here:

    threshold = .5
    level = thisComp.layer(“Audio Amplitude”).effect(“Both Channels”)(“Slider”);
    control = effect(“mouthOnOff”)(“Checkbox”) ;

    if (level > threshold){

    for (i =0; i<5; i++){
    control == 1
    control == 0
    }
    }else{
    control ==1
    }

    THANKS AGAIN!

  • Dan Ebberts

    July 18, 2007 at 5:37 pm

    Something like this maybe?

    threshold = .5;
    freq = 5; //mouth actions per second
    level = thisComp.layer(“Audio Amplitude”).effect(“Both Channels”)(“Slider”);

    if (level > threshold) Math.floor(time*freq)%2 else 1

    Dan

  • Sean Hellwig

    July 18, 2007 at 5:58 pm

    DAN DAN DAN!!!! Thank you so so much.. That did it! You have no idea how much time you’ve saved me, Well, im sure you do. Now i can focus more on the aesthetics of the piece.

    One last favor to ask.. can you please explain this line to me:

    if (level > threshold) Math.floor(time*freq)%2 else 1

    more particulary,the Math.floor(time*freq)%2

    Thanks again, lifesaver!

  • Dan Ebberts

    July 18, 2007 at 6:25 pm

    Sure,

    Math.floor(time*freq)%2

    just generates a square wave that runs at the frequency defined by freq. It does that by multiplying the current comp time by the frequency, converting that to an integer (that’s what Math.floor does), then converting even integers to zeros and odd integers to ones (that’s what %2 does). This gives you the alternating ones and zeros while the level is above the threshold.

    Any good JavaScript reference will have more detailed info on Math.floor() and % if you’re interested.

    Dan

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy