Copy link to clipboard
Copied
Hi all,
I'm working on a visualizer for a podcast. I want to set it so that each speaker's picture only appears when they're speaking. This is the expression I'm using on the opacity of the picture, which references the audio keyframes:
speaker1 = thisComp.layer("speaker1").effect("Both Channels")("Slider"); if ( speaker1 >= 1 ) { 100; } else { 0; }
This is working as it should, but the issue is the image flickers on and off for things like pauses between words, and breaks in laughs. In addition I feel like the animation would be more visually smooth if the picture lingered for a moment instead of turning off immediately when the speaking stops.
Is there a way I can add some kind of condition instead of the else statement here? Something like, if speaker1 < 1 and has been so for at least 20 frames, then the opacity = 0. I'm fairly new to expressions so I don't quite know where to start.
Thank you.
You could try something like this:
speaker1 = thisComp.layer("speaker1").effect("Both Channels")("Slider");
threshold = 3;
gap = 20;
val = 100;
if (speaker1 < threshold){
for (i = 1; i < gap; i++){
if (speaker1.valueAtTime(time - framesToTime(i)) >= threshold) break;
}
if (i == gap){
val = 0;
}
}
val
Copy link to clipboard
Copied
You could try something like this:
speaker1 = thisComp.layer("speaker1").effect("Both Channels")("Slider");
threshold = 3;
gap = 20;
val = 100;
if (speaker1 < threshold){
for (i = 1; i < gap; i++){
if (speaker1.valueAtTime(time - framesToTime(i)) >= threshold) break;
}
if (i == gap){
val = 0;
}
}
val
Copy link to clipboard
Copied
This works perfectly! Thank you so much.