Page 1 of 1

Create markers from gaps in audio file

Posted: July 31st, 2007, 11:20 am
by Atomic
Hi All,

Just wondering if anyone knows how to create markers based upon the pauses in an audio file.

Mainly I am working with voiceover that has silence between sections and I wanted markers generated at the start of a talking point.

Thanks

Posted: July 31st, 2007, 11:58 am
by Atomic
Sorry,

I just noticed this should be posted in the expression forum not scripts.

Feel free to move it.

I am looking for a script solution, not an expression solution. :roll:

Posted: July 31st, 2007, 1:47 pm
by Atomic
I have come up with this:

Code: Select all

{
	// Create project if necessary
	var proj = app.project;
	if(!proj) proj = app.newProject();
	try
	{
		temp = "The Audio Amplitude layer needs to be generated by After Effects prior to running this script. (Right-Click On Audio File in comp, choose Keyframe Assistant, Convert Audio To Keyframes will do this)";
		alert(temp);
		//Set currently selected comp to variable
		var myComp = app.project.activeItem; 
		var shouldContinue = confirm("This script will operate on the selected comp named: " + myComp.name + " do you want to continue?");
		if (shouldContinue == true)
		{
			app.beginUndoGroup("Create Markers From Audio Gaps");
					
			//The audio amplitude layer needs to be generated by After Effects prior to running this script. (Right-Click On Audio File choose Keyframe Assistant, Convert Audio To Keyframes will do this)
			//The audio amplitude layer is assumed to be in the comp and named "Audio Amplitude" in the comp (look out for crashes here, no checking for shame!)
			var AudioAmplitudeLayer = myComp.layer("Audio Amplitude"); 
			var markerGroup = AudioAmplitudeLayer.Marker; 

			var beginGap = 1;				//This is the frame # where a marker goes when the end of the gap is detected.
			var silenceThreshold = 1;			//Below this value is considered silence.
			var minGapLength = 60;			//Minimum number of frames below threshold to generate a gap.
			var gapFrameCount = 0;			//Count the number of frames we remain below the silence threshold.
			
			writeLn("Begin processing...");
			t=AudioAmplitudeLayer.inPoint;		//Start at the begining of this layer. 
			while(t < AudioAmplitudeLayer.outPoint) 
			{ 
				audioSample=myComp.layer("Audio Amplitude").effect("Both Channels")("Slider").valueAtTime(t); 
				writeLn(audioSample.toString());
				/*
				if (audioSample <silenceThreshold> minGapLength)
					{
						//Looks like we are at the end of a gap.
						markerTime = markerGroup.keyTime(beginGap); 	//Add a maker at the begining.
						beginGap = t;							//Set our new begining to where we are now.
						gapFrameCount = 0;						//Reset our count back to zero to detect again.
					}
				}
				else
				{
					beginGap = t;							//Set our new begining to where we are now.	
				}
				*/
				t++; 		//Advance time. (what power, I can actually move time forward...muhaaa!)
			} 
			writeLn("End processing...");
			app.endUndoGroup();
		}
		else
		{
			writeLn ("User canceled script.");
		}
	}
	catch(error)
	{
		writeLn (error.description);
	}
}


But After effects throws an error stating that it can not call "valueAtTime".

Is this becuase I am running it as a script and not an expression?

If so, is there a way to get the value of slider from a script?