Copy link to clipboard
Copied
I'm trying to work out how to get a sound to play everytime a keyframe is reached. The idea being that as a list of word flows past a sound is heard for each word. Kind of like what happens when you set a date in an iphone or android phone. I can't work out how I attach the sound to the corresponding key frame.
Copy link to clipboard
Copied
AE is not event driven, therefore you cannot just attach a sound to a key.
But of course you can write an expression, which does this 😉
The idea is that you manipulate the time of the soundfile. You want that the time is always 0 when hitting a key and starts counting up frame by frame from that point (you know, increasing time by one frame every frame is the same as "playback").
Code:
// first you need to grap the proberty with keyframes
keys = pigwhip the proberty with keys here;
// get the time of the next key - next key is the one closer to the playhead
nextkeytime = keys.nearestKey(time).time;
// finally just subtract the key time from the current time
time - nextkeytime;
Result: the time of the audio file will be 0 and stay 0 until the playhead hits the first keyframe (I wonder why it's 0, it should be negative, but ok).
Let's say the first keyframe is at 1sec. This is a static value, since it's keyframed.
When the playhead is also on 1 sec, the audio time is 0.
When the playhead is on 1 sec and 1 frame, the audio time is 1 frame.
When the playhead is on 2 sec and 15 frame, the audio time is 1sec and 15 frame.
This goes on and on, and staret over when the next key is in reach.
If your audio sample is just a short "bling" or whatever, it doesn't matter if audio time is continously increasing, because after the "bling", there is no audio data to playback anymore.
If your audio file contains several samples in one file, you have to seperate each sound from it, otherwise you will hear all the "blings" and "blongs" continously till the end of file or the next keyframe.
If you put the keys too close to each other, audio will break and start over. In such cases, if they are not constantly appearing, better make a new audio layer and place it manually where it should be heared and use a if-statement to skip this particular keyframe.
If you are constantly dealing with such cases, the expression needs to be more complex, but still, this will be doable.
*Martin
Copy link to clipboard
Copied
Where do I insert this code? is it on the audio layer or the text layer? or is there a scripting editor in the composition? I'm still coming to terms with scripting in AE
Copy link to clipboard
Copied
You put the code on time remap of the audio layer - enable time remap with CTRL+ALT+T first.
*Martin
Copy link to clipboard
Copied
The extension iExpressions has a solution to play a song at each marker. It is not the same as on every keyframe, but still muchs simpler to add a marker at each keyframe than duplicating your sound layer dozens of times.
See this video at 15:45
Here is the full documentation of the iExpression used to play the sound at markers
https://mamoworld.com/after-effects-expression/time-remap-marker
Find more inspiration, events, and resources on the new Adobe Community
Explore Now