Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Play sound when word changes

  • Play sound when word changes

    Posted by Jarle Leirpoll on August 13, 2017 at 3:56 pm

    I’ve built the expression below to the Source Text of a text layer to make words change based on sliders for frame rate, delay before first change, and ramping. It works – but now I want a sound clip to play each time there’s a word change. I can’t figure out how to do this.

    I know I could do it with markers (https://forums.creativecow.net/thread/2/918559) – but this is different. Since it’s all driven by sliders, I can’t use markers. I guess I need to add an expression to Time Remapping on the Audio clip, but other than that, I’m blank.

    Anyone?

    txt = thisComp.layer("Left Text Source").text.sourceText.value.split("*");
    frameRate = thisComp.layer("Controls").effect("Left Words per Second")("Slider")*(thisComp.layer("Controls").effect("Ramp Value Compute Left")("Slider")+1);
    startDelay = thisComp.layer("Controls").effect("First Change Time")("Slider");
    // define which word to show
    wordIndex = Math.ceil((time - startDelay)*frameRate);
    if (wordIndex<0) wordIndex = 0;
    if (wordIndex>=txt.length) wordIndex = txt.length-1;
    txt[wordIndex];

    Jarle Leirpoll
    PremierePro.net

    Jarle Leirpoll replied 8 years, 8 months ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    August 14, 2017 at 12:49 am

    I think your time remapping would looks something like this:


    txt = thisComp.layer("Left Text Source").text.sourceText.value.split("*");
    frameRate = thisComp.layer("Controls").effect("Left Words per Second")("Slider")*(thisComp.layer("Controls").effect("Ramp Value Compute Left")("Slider")+1);
    startDelay = thisComp.layer("Controls").effect("First Change Time")("Slider");

    tLast = startDelay+(txt.length-2)*(1/frameRate);
    if(time < startDelay){
    t = 0;
    }else if (time < tLast){
    t = (time-startDelay)%(1/frameRate);
    }else{
    t = time - tLast;
    }
    t

    Time remapping audio can be tricky though, because you can get a chirping sound as the audio rewinds over the last frame. If that’s an issue, you may have to manipulate the audio level in sync with the time remapping to squelch the chirp.

    Dan

  • Dan Ebberts

    August 14, 2017 at 12:52 am

    This might actually be a little better:


    txt = thisComp.layer("Left Text Source").text.sourceText.value.split("*");
    frameRate = thisComp.layer("Controls").effect("Left Words per Second")("Slider")*(thisComp.layer("Controls").effect("Ramp Value Compute Left")("Slider")+1);
    startDelay = thisComp.layer("Controls").effect("First Change Time")("Slider");

    tLast = startDelay+(txt.length-1)*(1/frameRate);
    if(time < startDelay){
    t = 0;
    }else if (time < tLast){
    t = (time-startDelay)%(1/frameRate);
    }else{
    t = 0;
    }
    t

    Dan

  • Jarle Leirpoll

    August 14, 2017 at 7:58 am

    Thanks Dan – this works!

    But now I’m getting a problem that I somehow failed to predict: The audio plays faster when I increase the ramping. I need it to play at normal speed. I guess that’s not possible with just one clip?

    One solution might be to duplicate the audio clip as many times as the maximum allowed number of words, which means maybe 50 times – and let each one get a slightly different expression (or maybe use index?) that plays the clip at normal speed, when a word change happens.

    1. Would this (many layers with expressions) slow down the project a lot? (The sound clip is very short)
    2. What kind of expression would do this?

    Sorry for all the questions – my brain has a problem with time expressions. 🙂

    Jarle Leirpoll
    PremierePro.net

  • Dan Ebberts

    August 14, 2017 at 4:29 pm

    So are you animating the frame rate? That would introduce a whole new set of problems.

    Dan

  • Jarle Leirpoll

    August 15, 2017 at 8:02 am

    No, I’m not animating the frame rate. Sorry, “frameRate” was a bad choice of variable name. Naming it “changeRate” would have been better. I’m animating the frequency of word changes (after an initial delay) so that it can be constant (like 1 or 2 words per second) or ramp up from 1 word per second to 30 words per second – or any other numbers the user wants.

    So the code you offered worked really well, in the sense that it triggers a sound at every word change, which is what I asked for. But since it’s done with Time Remapping, it also changes the speed and pitch of the sound. I need the sound to play at normal speed.

    So I’m thinking that it’s probably best to use several duplicates of the audio clip. But I have no idea how such a code would look.

    Jarle Leirpoll
    PremierePro.net

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