HIRO GEAR
Rust 音声認識 AI・エージェント Whisper 個人開発

Registro de desarrollo: cómo, al enfrentarse con el ruido y las voces ajenas mediante entrada de voz, llegué a una solución de 'supresión de ruido mínima × puerta biométrica vocal' escrita en Rust puro

Registro de desarrollo: cómo, al enfrentarse con el ruido y las voces ajenas mediante entrada de voz, llegué a una solución de 'supresión de ruido mínima × puerta biométrica vocal' escrita en Rust puro

Introduction: A Self-Built Voice Input System That Worked Perfectly in a Quiet Room

By stopping the tapping of the keyboard and thinking directly into text using my voice, I pursued this ideal.
To achieve it, I developed a custom high-speed Japanese voice input daemon called Voice-Typer (Pure Rust + Whisper), leveraging a GPU (RTX 3060).

In the quiet environment of my bedroom desk, it was incredibly comfortable.
Text would expand on the screen as if being sucked in within about 0.3 seconds from the moment I opened my mouth, and I became convinced that “I can never go back to manual typing.”

However—taking this comfortable system just one step outside (to a cafe, train station platform, road intersection, or living room with family) immediately brought me face-to-face with two massive walls of reality.


Wall #1: Going Outside Makes It Useless Due to “Environmental Noise”

The first obstacle was “street environmental noise (wind noise, vehicle running noise, HVAC sounds)”.

The microphone that worked perfectly in a quiet room bared its teeth as soon as I went outdoors.

  • Speaking while walking caused the microphone to strongly pick up low-frequency rumbling from gusts of wind or truck road noise.
  • The speech recognition engine, Whisper, when encountering sections of pure noise, would forcibly fabricate words, outputting mysterious English hallucinations (e.g., Please create a big yellow...).

Looking at the screen, I saw mysterious English sentences and meaningless symbols that I hadn’t spoken lined up, completely interrupting my train of thought.

[Solution #1]: Introducing RNNoise for Noise Cancellation

“First, we must cleanly eliminate the physical noise around us.”

So, I incorporated RNNoise (neural network-based adaptive noise suppression) into the front end of the pure Rust audio pipeline.

flowchart LR
    Mic["Mic Input (16kHz)"] --> RNNoise["RNNoise<br>(AI Noise Cancellation)"] --> Whisper["Whisper<br>Transcription"]

RNNoise estimates and removes stationary and non-stationary environmental noise from the audio in just a few milliseconds per frame.
The sound of air conditioner fans, the roar of distant cars, and low-frequency gusts vanished smoothly, leaving only my voice clearly floating through the microphone.

“Great, the noise problem is solved! I can use voice input comfortably anywhere!”
At that time, I patted myself on the back thinking so.


Wall #2: Even with Noise Cancelled, “Other People’s Voices” Cannot Be Blocked

Scene of confusion surrounded by cafe chatter and other people's voices

However, in cafes or crowded places that I visited next, a more troublesome and essential wall awaited me.

  • The microphone would clearly pick up conversations from the seat next to me in a cafe, shop staff announcements, or TV audio in the living room.
  • Whisper, being extremely excellent, diligently transcribes anyone’s voice if it is “human speech,” regardless of who is speaking.

As a result, a tragedy occurred where even during moments of silence when I wasn’t speaking, private small talk from neighbors would be lazily typed onto the screen.

The Failure: “If We Just Make Noise Cancellation Stronger?”

“I thought, ‘If we increase the suppression ratio of RNNoise to a more powerful level (80%~90% suppression), shouldn’t we be able to eliminate distant voices of others as noise?’”
However, here I faced the cruel dilemma of acoustics.

  1. RNNoise cannot distinguish “other people’s voices”:
    RNNoise is an AI that separates “human voice vs. other environmental sounds.” For RNNoise, both “my voice” and “the neighbor’s voice” are equally valid audio to protect, so it is fundamentally impossible to eliminate others’ voices as noise.
  2. Over-suppressing noise destroys “voice quality”:
    If we forcibly apply strong noise suppression, along with environmental sounds, delicate harmonic components of the voice (high-frequency formants) and consonants (sa/ta/pa rows) get shaved off, resulting in an unnatural robot voice as if speaking underwater. Consequently, Whisper’s recognition accuracy plummeted.

“Environmental noise” and “other people’s voices” were completely different things.
It was a mistake to try to carry everything on the tool of noise cancellation alone.


Solution #2: Reject Other People’s Voices via “Speaker Verification” Instead of Noise Suppression

“I realized that trying to eliminate other people’s voices with noise cancellation was wrong.”
From this realization, I made a major turn in the architecture.

“We will use noise cancellation to reduce environmental noise, but for other people’s voices, we will cut them off flat before passing them to speech recognition (Whisper) using ‘speaker verification (is this really my voice?)’”

Instead of setting up a heavy separate Python process, I directly incorporated a super-lightweight 26MB ONNX model (WeSpeaker ResNet-34) into Voice-Typer (pure Rust standalone binary).

Concept diagram of Minimum Noise Suppression × Speaker Gate Pipeline


Core: The Golden Ratio Reached at “Minimum Noise Suppression × Speaker Gate”

Here, the biggest breakthrough in this system was born.

“If we apply too much noise cancellation, the harmonics of the voice get shaved off, causing speaker verification (WeSpeaker) to even reject my own voice” is a technical trade-off.

Speaker verification (WeSpeaker) identifies individuals by looking not just at the fundamental frequency of the vocal cords, but also fine harmonic components generated from the shape of the vocal tract and skeleton. If we flatten the voice with noise cancellation, speaker verification goes haywire.

Therefore, I strictly redesigned the division of labor between the two technologies as follows:

flowchart LR
    Mic["Mic Input (16kHz)"] --> Denoise["RNNoise<br>Mild Fixed Noise Suppression (30%)"]
    Denoise --> VAD{"VAD Gate<br>Voice Present?"}
    VAD -- No --> Skip1["Skip<br>(Silence/Minimal Noise)"]
    VAD -- Yes --> Speaker{"Speaker Gate<br>Matches My Voiceprint?"}
    Speaker -- "Similarity < 0.45" --> Skip2["Skip