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

Journal de développement : comment, en Rust pur, parvenir à une suppression de bruit minimale et un filtre d'empreinte vocale après avoir rencontré les défis du bruit ambiant et des voix d'autrui lors de la saisie vocale

Journal de développement : comment, en Rust pur, parvenir à une suppression de bruit minimale et un filtre d'empreinte vocale après avoir rencontré les défis du bruit ambiant et des voix d'autrui lors de la saisie vocale

Introduction: A DIY Voice Input System That Worked Perfectly in a Quiet Room

I stopped typing on the keyboard and sought to think directly by voice, converting thoughts instantly into text.
Chasing this ideal, I developed a custom high-speed Japanese voice input daemon called Voice-Typer (Pure Rust + Whisper), leveraging a GPU (RTX 3060).

In my quiet home office environment, it was incredibly comfortable. Text appeared on the screen as if being sucked in instantly within about 0.3 seconds from the moment I opened my mouth; I was convinced, “I can never go back to manual typing.”

However—taking this comfortable system just one step outside (to a café, 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, vehicle movement, air conditioning)”.

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

  • Speaking while walking caused the microphone to pick up strong low-frequency sounds 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, completely interrupting my train of thought.

[Solution #1]: Introducing RNNoise for Noise Cancellation

“First, I must eliminate the physical ambient noise around me.”

So, I incorporated RNNoise (Neural Network-based Adaptive Noise Suppression) into the front end of the pure Rust audio pipeline.

flowchart LR
    Mic["Microphone 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, distant vehicle hums, 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 with relief.


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

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

However, in cafés or crowded places I visited next, a more troublesome and fundamental wall awaited me.

  • The microphone would pick up conversations from the seat next to me in a café, shop announcements, or TV audio in the living room with remarkable clarity.
  • Whisper, being extremely capable, diligently transcribed anyone’s voice if it was “human speech,” regardless of who was speaking.

As a result, a tragedy occurred where private conversations between neighbors were automatically typed onto the screen during moments of silence when I wasn’t speaking.

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

“I thought, ‘If we increase RNNoise’s suppression ratio even more (to 80%–90% suppression), shouldn’t distant voices from others be eliminated 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, making it impossible to eliminate others’ voices as noise by principle.
  2. Excessive Noise Suppression Destroys Voice Quality:
    If we forcibly apply intense noise suppression, along with environmental sounds, delicate harmonic components of the voice (high-frequency formants) and consonants (sa/ta/pa sounds) get stripped away, resulting in an unnatural robot voice as if speaking underwater. Consequently, Whisper’s recognition accuracy plummeted.

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


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

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

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

Instead of setting up a heavy separate Python process, I directly embedded 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 system’s biggest breakthrough was born.

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

Speaker verification (WeSpeaker) identifies individuals by looking not just at the fundamental frequency of the vocal cords but also at subtle harmonic components generated from the shape of the vocal tract and bone structure. 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["Microphone 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<br>(Other Voices, TV, etc.)"]
    Speaker -- "Similarity >= 0.45