AI Engineering November 4, 2026

Demystifying Audio RMS & Noise Gates: Why LLMs Hallucinate in Silence

By Kahraman Bayraktar
Editorial NoteThis article was drafted with AI assistance from real engineering problems, debugging sessions, and architectural questions that surfaced during my own software development work. While the underlying experience is real, AI-generated explanations may contain inaccuracies.

In the GenAI hype cycle, we are told that multimodal Large Language Models (LLMs) can directly hear, reason, and speak in real time. But the moment you connect a real microphone in a living room to a native audio model like Google Vertex AI's Gemini Live API (gemini-live-2.5-flash), you collide with the messy physics of the real world.

While building the real-time voice concierge for Lokus (our curated Bodrum real estate intelligence platform), we encountered an infuriating anomaly:

You sit in total silence. A refrigerator hums in the background. A fork clinks against a ceramic plate. Suddenly, the AI interrupts you, confidently transcribing phantom words: "Dedi." A few seconds later: "İtti."

The pipeline wasn't hearing ghost voices; the speech/audio decoder was hallucinating short Turkish tokens out of ambient noise.

Here is the story of how we diagnosed the root cause, rejected a junior monkey-patch, and drilled down to first principles using Digital Signal Processing (DSP) and Root Mean Square (RMS) noise gating.


The Junior Trap: The String Blacklist

When our development session flagged these phantom tokens, the initial proposal was tempting in its simplicity:

// ❌ The Anti-Pattern: Treating an acoustic problem as a string problem
const BLACKLIST = ['dedi', 'itti', 'gitti'];
if (BLACKLIST.includes(transcript.trim())) {
  return; // Drop it!
}

I stopped the line immediately.

This is the quintessential junior engineer trap. When an acoustic neural decoder hallucinates because it is fed low-energy noise during silence, patching the symptom with a hardcoded list of banned words is technical debt at its worst. What happens when ambient noise produces "evet"? What happens when a user genuinely says a single word from that list?

If the problem originates in the acoustic signal, it must be solved in the acoustic signal.


Drilling to First Principles: The Socratic Interrogation

I am an engineer with two decades of experience in enterprise backend systems, and digital audio DSP was not my daily bread. I didn't want a canned copy-paste formula; I wanted to verify the fundamental physics.

I sat down with my AI pair-programmer and interrogated the math before putting a single line into production.

Question 1: "What exactly is an audio 'sample', and what does 16 kHz mean?"

When you capture video, your camera doesn't record a continuous stream of light; it captures 30 or 60 discrete frames per second. Played sequentially, your brain perceives continuous motion.

Digital audio works the same way. Sound in the physical world is a continuous pressure wave pushing and pulling a microphone diaphragm. A computer stores discrete numerical measurements of that wave:

  • Sample: A single instantaneous measurement of the audio waveform's amplitude (normalized between -1.0 and +1.0 in Web Audio Float32Array buffers).
  • 16 kHz (16,000 Hz): The audio context samples the microphone 16,000 times per second.
  • Chunking: In our Web Audio AudioWorkletProcessor, we buffer audio in 100-millisecond windows. At 16 kHz, each window contains:
16,000 samples/sec × 0.100 sec = 1,600 samples per chunk

Question 2: "What does Root Mean Square (RMS) give us? Why not take a simple average?"

If we have 1,600 sample values in a 100 ms chunk, why can't we just sum them up and divide by 1,600?

Because sound is an alternating oscillation around zero.

When you speak, acoustic pressure swings positive (+0.8) and negative (-0.8). If you take the plain arithmetic mean of [+0.8, -0.8], the result is 0.0. Even if you shout into the microphone, symmetrical positive and negative half-cycles cancel each other out.

RMS solves this. It measures the effective root-mean-square amplitude (proportional to the square root of average signal power) across the window, yielding a clean value from 0.0 (digital silence) up to 1.0 (full-scale sine/square wave amplitude).


Question 3: "Why is it called Root Mean Square if the code runs Square → Mean → Root?"

In mathematical naming, Root Mean Square is read from the outside in: "the Root of the Mean of the Squares." In code, evaluation proceeds from the inside out:

  1. Square (s * s): Multiplies each sample by itself. Because (-s) * (-s) = +s², every negative swing becomes positive—eliminating phase cancellation.
  2. Mean (sumSquares / 1600): Computes the average squared amplitude (mean power) across the 1,600-sample window.
  3. Root (Math.sqrt(mean)): Takes the square root to map the unit back from squared power (s²) to linear amplitude (0.0 to 1.0).

Question 4: "Wait—if 0.5² = 0.25, squaring made the number smaller! Does squaring shrink the voice?"

This was the exact point where I pushed back during the design review. Since Web Audio samples live between -1.0 and +1.0, squaring any fraction makes it numerically smaller (0.5² = 0.25, 0.05² = 0.0025).

Here is the crucial distinction between power (s²) and final RMS (√mean):

Signal TypePeak/Constant Amplitude (s)Mean Power (s²)Final RMS (√s²)
Ambient Room Noise0.050.0025 (1× power baseline)0.050
Human Voice0.500.2500 (100× power)0.500 (10× amplitude)
  1. In the power domain (s²): A voice that is 10× louder in amplitude carries 100× the acoustic energy (0.2500 / 0.0025 = 100). Inside a single 100 ms window containing brief vocal peaks mixed with quiet gaps, squaring heavily weights energetic vocal peaks over low-level background hiss when computing the mean.
  2. After Math.sqrt(): Taking the square root brings the final RMS metric right back to the linear amplitude scale (10× separation: 0.50 vs 0.05), giving us an intuitive threshold scale while preventing positive/negative wave cancellation.

Question 5: "Are we isolating the voice from noise, or acting as a gatekeeper?"

We are not doing spectral noise suppression (like RNNoise or Krisp). We are building an acoustic Noise Gate:

  • When RMS stays below threshold: We suppress the raw microphone buffer and transmit a zero-filled PCM16 buffer (new Int16Array(1600)) over the WebSocket.
  • When sustained vocal energy is detected: We open the gate and pass the raw PCM16 audio frames straight through.

Why? Because multimodal audio models handle mild room ambiance remarkably well while a human is actively speaking. Hallucinations spike specifically during prolonged stretches of unvoiced room static, where Voice Activity Detection (VAD) and acoustic decoders try to force-fit faint noise bursts into short syllables.


Calibrated Thresholds in Production

In Lokus's audio-processor.js, we calibrated NOISE_GATE_RMS_THRESHOLD = 0.012 (roughly -38.4 dBFS).

Here is how typical living-room acoustics map against that 0.012 threshold:

ScenarioTypical RMS RangeRelation to 0.012Gate Action
Room Silence / Laptop Fan0.002 – 0.004~3–6× below thresholdMUTE (Zero-filled PCM sent)
Isolated Cutlery / Pen Click0.025 (< 50 ms)Brief spike above thresholdMUTE (Blocked by Onset Hysteresis)
Soft Whisper~0.0302.5× above thresholdOPEN (Sustained > 200 ms)
Normal Conversational Speech~0.080~6.7× above thresholdOPEN (Clean stream)
Loud Emphasis~0.250~20× above thresholdOPEN (Clean stream)

The wide ~10× margin between typical quiet-room noise floor (~0.003) and soft speech (~0.030) gives the gate a clean operating corridor.


The Dual-Defense State Machine

A naive single-frame RMS check is still vulnerable to impulse transients: a clinking fork or mouse click can exceed 0.012 for a single frame. Conversely, closing the gate the instant RMS dips can clip soft trailing consonants.

To solve both, we implemented a two-way temporal state machine inside audio-processor.js:

// Production excerpt from Lokus frontend/public/audio-processor.js
if (rms >= NOISE_GATE_RMS_THRESHOLD) {
  this.consecutiveVocalChunks++;
  if (this.consecutiveVocalChunks >= MIN_CONSECUTIVE_VOCAL_CHUNKS) {
    // Sustained speech confirmed (200ms): open gate & reset hangover
    this.hangover = HANGOVER_CHUNKS;
    chunk = this.buffer.buffer;
  } else {
    // First 100ms onset chunk: hold/mute until second chunk confirms it's not an isolated click
    const silentBuffer = new Int16Array(CHUNK_SAMPLES);
    chunk = silentBuffer.buffer;
  }
} else {
  this.consecutiveVocalChunks = 0;
  if (this.hangover > 0) {
    // Hangover tail (400ms): preserve soft trailing consonants (-k, -t, -s)
    this.hangover--;
    chunk = this.buffer.buffer;
  } else {
    // Pure ambient silence
    const silentBuffer = new Int16Array(CHUNK_SAMPLES);
    chunk = silentBuffer.buffer;
  }
}
  1. Speech Onset Verification (MIN_CONSECUTIVE_VOCAL_CHUNKS = 2): Requires two consecutive 100 ms chunks above 0.012 before opening the gate. Isolated transient clicks (< 50 ms) decay within a single chunk and are suppressed. (Trade-off: holding the first 100 ms onset frame slightly trims the initial attack—a conscious compromise to eliminate false barge-in interruptions, which can also be refined with a 1-chunk lookahead ring buffer if sub-100 ms plosive preservation is needed.)
  2. Hangover Tail (HANGOVER_CHUNKS = 4): Keeps the gate open for 400 ms after vocal energy drops below threshold, preventing premature clipping on quiet trailing consonants (like "git-ti-k").

Architectural Lessons

  1. Never solve physical signal problems with string blacklists: Filtering hallucinated transcripts with regexes or banned-word arrays is a losing game. Fix signal anomalies at the DSP boundary.
  2. Interrogate every formula: Don't let an AI assistant drop math into your codebase without questioning what happens to units, scales, and edge cases. Asking "Wait, why didn't 0.5² = 0.25 shrink the voice relative to noise?" turns opaque code into verified engineering.
  3. Analog silence is not digital zero: To a live microphone and a neural speech decoder, a quiet room is a continuous stream of low-level noise. When no one is speaking, explicitly transmit digital zero.