Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Syncing text to audio

  • Syncing text to audio

    Posted by Henri Yates on January 10, 2020 at 2:52 pm

    Hi.. I wanted to sync my voice-over with markers aligned perfectly to each word said in the VO. I want to sync the VO with its corresponding text to the text appears as the word is being spoken… I tried using expressions but it doesn’t sync perfectly. Is there a mistake in my expression or my expression is completely wrong.
    Here’s my code
    4a642036-d23e-42ff-84f2-06b40e5fb39b.png.jpg

    Thanks,
    Cheers.

    // TypeMonkey
    m = thisComp.layer("1.mp3").marker;
    rate = 20;
    n = text.sourceText.length;
    d = n/rate;
    pre = d/2;
    t = time
    n = 0;
    if (marker.numKeys > 0){
    n = marker.nearestKey(time).index;
    if (marker.key(n).time > time){
    n--;
    }
    }

    if (n == 0){
    0
    }else{
    m = marker.key(n);
    myComment = m.comment;
    t = time - m.time;
    try{
    actMarker = action.marker.key(myComment);
    if (action.marker.numKeys > actMarker.index){
    tMax = action.marker.key(actMarker.index + 1).time - actMarker.time;
    }else{
    tMax = action.outPoint - actMarker.time;
    }
    t = Math.min(t, tMax);
    actMarker.time + t;
    }catch (err){
    0
    }
    }
    linear(t,0,d,0,100)

    Dan Ebberts
    replied 6 years, 2 months ago
    2 Members · 7 Replies
  • 7 Replies
  • Dan Ebberts

    January 10, 2020 at 8:02 pm

    It looks like maybe you took several unrelated expressions and mooshed them together somehow. In any case, this should give you one basic way to sync the text to the markers:


    m = thisComp.layer("1.mp3").marker;
    n = 0;
    if (m.numKeys > 0){
    n = m.nearestKey(time).index;
    if (m.key(n).time > time){
    n--;
    }
    }
    if (n == 0){
    ""
    }else{
    m.key(n).comment;
    }

    Dan

  • Henri Yates

    January 10, 2020 at 9:56 pm

    Thanks for replying sir.
    I tried your solution. Unfortunately, it didn’t work. It gave me this error;

    After Effect warning: an expression was disabled as a result of an error.

    Error at line 0 in property ‘Start’ of layer 5 (‘layer name’) in comp ‘5’.
    invalid numeric result (divide by zero?).

    What do you suggest I should do?

    Thanks again.
    Cheers

  • Dan Ebberts

    January 10, 2020 at 10:54 pm

    Sorry, I don’t notice you had the expression applied to a range selector. I assumed the text was coming from the markers, so that expression is for the Source Text property.

    Dan

  • Dan Ebberts

    January 14, 2020 at 12:25 am

    Henri,

    I got your emails, but my replies get returned immediately with a permanent error rejection message. I’m not sure why, but I’ll post here instead.

    What you’re describing is a lot trickier, because the expression has to be able to figure out how many characters were used in all the words triggered by previous markers. Not impossible, but considerably more complicated. I don’t have the time to do it right now, but maybe someone can crank it out for you.

    Dan

  • Henri Yates

    January 14, 2020 at 8:44 am

    Oh bummer, but thank you sir. I appreciate your help so much.
    Cheers.

  • Dan Ebberts

    February 6, 2020 at 8:01 pm

    For your latest question, you could use an opacity expression like this for the text:

    fade = .25;
    m = thisComp.layer(“1.mp3”).marker;
    n = 0;
    if (m.numKeys > 0){
    n = m.nearestKey(time).index;
    }
    if (n == 0){
    0;
    }else if (n == 1){
    t = time – m.key(n).time;
    ease(t,0,fade,0,100);
    }else{
    if (time < m.key(n).time){
    t = m.key(n).time – time;
    ease(t,0,fade,0,100);
    }else{
    t = time – m.key(n).time;
    ease(t,0,fade,0,100);
    }
    }

    Dan

  • Dan Ebberts

    February 7, 2020 at 7:55 pm

    OK, I didn’t understand what you’re doing. Try this. Add an Opacity Animator and set the Opacity value to 100. Add an Expression Selector and delete the Range Selector. Set the Expression Selector “Based On” parameter to Words, and replace the Amount expression with this:


    fade = .25;
    m = thisComp.layer("R.Smalls.mp4").marker;
    n = 0;
    if (m.numKeys > 0){
    n = m.nearestKey(time).index;
    if (time < m.key(n).time) n--;
    }
    if (textIndex < n){
    0;
    }else if (textIndex == n){
    t = time - m.key(n).time;
    ease(t,0,fade,100,0);
    }else{
    100;
    }

    Dan

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