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?
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:
Here's an image with some explanatory annotation:
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.