Skip to content

Silence

Sambit Paul edited this page Jul 31, 2022 · 3 revisions

The Silence class aims to provide two key functionalities:

  • Silence Detection
  • Splitting by Silence

Silence Detection

Given an audio file (read using WAV class), this identifies all the segments of silence within the audio segment.

Code
WAV objRead = new WAV();
objRead.readWAV("audio.wav"); //Filepath of the audio to be processed

int silence_length = 500; //in milliseconds
int silence_threshold = -20 //in db
double iter_steps = 0.25 //in milliseconds

Silence s1 = new Silence(silence_length, silence_threshold, iter_steps);
s1.detectSilence(objRead);
int[][] silences_ms = s1.getSilence(true); //segment boundaries in milliseconds
//OR
int[][] silences_indices = s1.getSilence(); //segment boundaries as indices

Splitting by Silence

After segments of silence are detected, the original audio can be split into segments which do not contain any silence.

This has to be done after silent segments have been detected.

Code
WAV objRead = new WAV();
objRead.readWAV("audio.wav");

String saveDirectory = "./split_audio/"; //this folder must exist

int silence_length = 500; //in milliseconds
int silence_threshold = -20 //in db
double iter_steps = 0.25 //in milliseconds

Silence s1 = new Silence(silence_length, silence_threshold, iter_steps);
s1.detectSilence(objRead);
s1.splitBySilence(saveDirectory);
Clone this wiki locally