Skip to content

feat: improve language detection with multi-sampling#7

Open
Zonrotan wants to merge 2 commits into
ellite:mainfrom
Zonrotan:feature/robust-language-detection
Open

feat: improve language detection with multi-sampling#7
Zonrotan wants to merge 2 commits into
ellite:mainfrom
Zonrotan:feature/robust-language-detection

Conversation

@Zonrotan
Copy link
Copy Markdown
Contributor

@Zonrotan Zonrotan commented Apr 29, 2026

Description

The new auto-detect works great, but has a hidden flaw: when language=None, Whisper natively limits its language detection to the first 30 seconds of the audio.

If a video starts with silent logos, long musical intros, or background noise, Whisper often hallucinates a random language (e.g., guessing Thai for a Swedish video). Because Whisper locks in its first guess for the entire file, this ruins the transcription and triggers unnecessary translation logic.

Solution

This PR bypasses Whisper's 30-second limitation with a lightweight detect_robust_language helper function that samples three snippets from the file. Instead of trusting just the first 30 seconds, it:

  1. Samples three 30-second snippets (at 15%, 50%, and 85%).
  2. Silently runs model.transcribe() on them.
  3. Uses majority voting to determine the true language.
  4. Falls back to native detection for videos under 2 minutes.

Why this approach?
Since the audio is already loaded as a numpy array, slicing it and running inference on these snippets takes only a fraction of a second and requires no external dependencies (like ffmpeg).

Changes Made

  • Added detect_robust_language in whisper.py
  • Injected the check before the main model.transcribe call (when no metadata is present).
  • Muted the progress bar for the detection samples.

Sounds good, no? 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant