Question

The end result trying for: every time a keyframe in the sound file passes, the text will add a letter through the Typewriter animation. Essentially the sound file is the sound of a keyboard. So this will match the letters up with the key sounds.

I'm fairly new to writing expressions for After Effects. So far I have converted the sound file to keyframes and dragged the squiggle from the Range Selector to one of the sound channels. This, however, sets the Range Selector to the value of the channel. So currently the text is bouncing back and forth between displaying 0-5 characters.

This is is a screenshot of both the audio file and the text file in question.

Any ideas?

enter image description here

Was it helpful?

Solution

threshold = 9.5;
audioLev = thisComp.layer("typewr11.wav").effect("Both Channels")("Slider");
above = false;
frame = Math.round(time / thisComp.frameDuration);
n = 0;
while (frame >= 0){
  t = frame * thisComp.frameDuration;
  if (above){
    if (audioLev.valueAtTime(t) < threshold){
      above = false;
    }

  }else if (audioLev.valueAtTime(t) >= threshold){
    above = true;
    n++;
  }
  frame--;
}
n;

Apologies for seeing this rather late. Based on the great Dan Ebberts' work (http://www.motionscript.com/design-guide/audio-count.html), here is the solution. But first let me point out:

"every time a keyframe in the sound file passes, the text will add a letter" -- actually, this isn't correct. If you convert audio to keyframes, you're looking for certain volume threshold to trigger the action; it's not any keyframe.

So here's what I did:

  1. brought in a typewriter sound effect file with 11 characters being typed (http://frogstar.com/wp-content/uploads/2012/wav/typewr11.wav).
  2. converted audio to keyframes for this audio layer, took the 'both channels' keys from the resulting new layer and pasted them into the original audio layer, deleting the unnecessary newly created layer.
  3. created the text file with 11 or so characters to type ("12345, six!!").
  4. Selected Opacity from text layer's Animate popup. Set Range Selector Units to index, Opacity (of Range Selector, not layer) to 0.
  5. Set smoothness to 0.
  6. Option-clicked on Range Selector's "Start" property, pasted the above expression into it.

Here's an image with some explanatory annotation:

two layers, audio typing

Ebberts warns that if you have a really long comp/layer doing this expression, it can bog down because of the looping it has to do for every frame (loop iterations increase for every frame), so be aware of this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top