Remove silence Script for Premiere Pro
Hello! 🙂 I'm new to Premiere Pro Scripting but not new to coding.
I've got PP2023 and I'm using JSX Launcher to run my jsx code as ExtendScript won't work on my Mac
I'm trying to create a script which will delete any silences from my project to make my editing faser.
I've made some very simple scripts for JSX (counting the clips etc) which work find. But the script I'm using to cut the silences is doing nothing. Can anyone tell me where I'm going wrong please?
// Define the noise level, minimum time, and offset time
var noiseLevel = 0.1; // 10%
var minTime = 1; // 1 second
var offsetTime = 0.5; // 0.5 seconds
// Get the active sequence
var activeSequence = app.project.activeSequence;
// Get the audio tracks in the active sequence
var audioTracks = activeSequence.audioTracks;
// Loop through each audio track
for (var i = 0; i < audioTracks.numTracks; i++) {
// Get the audio clips in the current audio track
var audioClips = audioTracks[i].clips;
// Loop through each audio clip in the current audio track
for (var j = 0; j < audioClips.numItems; j++) {
// Get the current audio clip
var audioClip = audioClips[j];
// Get the audio components in the current audio clip
var audioComponents = audioClip.components;
// Get the corresponding video clip for the current audio clip
var videoClip = activeSequence.videoTracks[i].clips[j];
// Create an array to store the cut points for the current clip
var cutPoints = [];
// Loop through each audio component in the current audio clip
for (var k = 0; k < audioComponents.numItems; k++) {
// Get the current audio component
var component = audioComponents[k];
// Check if the current audio component is silent
if (component.audioLevel <= noiseLevel && component.end-component.start >= minTime) {
// Add the start and end points of the silent component to the cut points array
cutPoints.push(component.start-offsetTime);
cutPoints.push(component.end+offsetTime);
}
}
// Sort the cut points array in ascending order
cutPoints.sort(function(a, b) {
return a - b;
});
// If there are any cut points, cut the video and audio clips between them
if (cutPoints.length > 0) {
// Cut the first clip from the start of the original clip to the first cut point
var firstClip = audioClip.clone();
firstClip.end = cutPoints[0];
videoClip.end = cutPoints[0];
audioClip.start = cutPoints[0];
// Cut the rest of the clips between the cut points
for (var l = 0; l < cutPoints.length; l += 2) {
var newClip = audioClip.clone();
newClip.start = cutPoints[l];
newClip.end = cutPoints[l+1];
videoClip.start = cutPoints[l];
videoClip.end = cutPoints[l+1];
}
// Cut the last clip from the last cut point to the end of the original clip
var lastClip = audioClip.clone();
lastClip.start = cutPoints[cutPoints.length-1];
videoClip.start = cutPoints[cutPoints.length-1];
audioClip.end = cutPoints[cutPoints.length-1];
}
}
}
