• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Help with expression controlling opacity

New Here ,
Jan 21, 2025 Jan 21, 2025

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.

TOPICS
Expressions

Views

104

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 21, 2025 Jan 21, 2025

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

Votes

Translate

Translate
Community Expert ,
Jan 21, 2025 Jan 21, 2025

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 22, 2025 Jan 22, 2025

Copy link to clipboard

Copied

LATEST

This works perfectly! Thank you so much.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines