Dev.to WebDev 🛠 Dev 👁 0 📖 3 min read

Silence detection from scratch: RMS in 10 ms steps and the four settings that matter

Cutting dead air out of a talking video sounds like an editing job, but the detection part is a loudness problem. Here is the method behind a free browser tool I built, boiled down to a sketch you can read in one sitting

Cutting dead air out of a talking video sounds like an editing job, but the detection part is a loudness problem. Here is the method behind a free browser tool I built, boiled down to a sketch you can read in one sitting.

The idea in four steps

  1. Mix the audio to mono.
  2. Take a reading every 10 ms: the RMS level of a 20 ms window, in decibels below full scale.
  3. Call a step "silent" if it is quieter than your chosen level.
  4. Keep a silent run only if it lasts longer than a minimum, then trim a little off each side so speech is not clipped.

It measures loudness, not meaning. That is why the settings matter more than any "auto" button.

A simplified sketch

This is an illustration of the method, not the tool's source code. It runs on a Float32Array of mono samples.

// Simplified sketch of level-based silence detection (not the Silence Cutter's source).
function findSilences(samples, sampleRate, opts = {}) {
  const { levelDb = -40, minSilence = 0.4, pad = 0.08, minSound = 0.1 } = opts;
  const step = Math.round(sampleRate * 0.010); // one reading every 10 ms
  const win = Math.round(sampleRate * 0.020);  // RMS over a 20 ms window
  const quiet = [];
  for (let i = 0; i + win <= samples.length; i += step) {
    let sum = 0;
    for (let j = i; j < i + win; j++) sum += samples[j] * samples[j];
    const db = 20 * Math.log10(Math.sqrt(sum / win) + 1e-12);
    quiet.push(db < levelDb);
  }
  // runs of quiet steps -> [start, end] in seconds
  const runs = [];
  let start = null;
  quiet.forEach((q, k) => {
    if (q && start === null) start = k;
    if (!q && start !== null) { runs.push([start, k]); start = null; }
  });
  if (start !== null) runs.push([start, quiet.length]);
  let secs = runs.map(([a, b]) => [a * 0.01, b * 0.01]);
  // a short burst of sound inside a pause should not split it
  const merged = [];
  for (const r of secs) {
    const last = merged[merged.length - 1];
    if (last && r[0] - last[1] < minSound) last[1] = r[1]; else merged.push([...r]);
  }
  // keep only long-enough silences, then give speech some air on both sides
  return merged
    .filter(([a, b]) => b - a >= minSilence)
    .map(([a, b]) => [a + pad, b - pad])
    .filter(([a, b]) => b > a);
}

I ran this on a generated six-second signal with a 1.5 s quiet stretch and a 0.2 s gap. It returned one silence (about 1.08 s to 2.41 s) and left the short gap alone, which is the behaviour you want.

The four settings

  • levelDb: start between -35 and -45 dB in a quiet room. A higher level cuts more, including breaths and quiet speech.
  • minSilence: 0.4 s suits a talking head, 0.2 s suits fast reels. Below that you start removing the natural rhythm of speech.
  • pad: 0.08 s of air on each side stops cuts clipping the first and last letters of words.
  • minSound: 0.1 s stops a mouse click or a bump from counting as speech and splitting a pause.

Where level-based detection goes wrong

  • Quiet speech, music beds and constant background noise can fool it. Always listen to a preview before you commit.
  • Decoding the whole track into memory is fine for a clip, but recordings over about an hour get slow. Split them first.
  • Variable frame rate video should be converted to a constant rate before editing.

Getting the result into an editor

A cut list stores timecode, so the frame rate matters: export at 30 on a 29.97 timeline and the cuts drift. Pick the frame rate of your timeline, then import the EDL (File, Import, Timeline in DaVinci Resolve, or File, Import in Premiere Pro).

Try it, and what I checked

The finished tool is free, runs in your browser and uploads nothing: Silence Cutter. It exports an EDL, Resolve markers, After Effects markers, CSV and an ffmpeg script. The longer, editor-facing write-up is here.

I checked the detection against ffmpeg's silencedetect on a generated recording and the EDL layout against the CMX 3600 format. I have not opened the files in every editor.

I'm Bhavesh, a freelance video editor and motion designer in Rajkot, India.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.