Mintplex-Labs/anything-llm · warning · Error

Audio file sample rate is too low for accurate transcription

Error message

Audio file sample rate is too low for accurate transcription. Minimum required is 4kHz.

What it means

LocalWhisper.#validateAudioFile rejects WAVs whose fmt.sampleRate is below 4000 Hz. Whisper typically needs >=8 kHz; 4 kHz is a conservative floor. Since ffmpeg converts to 16 kHz beforehand, hitting this means conversion produced unexpected output or a pre-existing WAV bypassed conversion.

Source

Thrown at collector/utils/WhisperProviders/localWhisper.js:40

    if (!fs.existsSync(this.cacheDir))
      fs.mkdirSync(this.cacheDir, { recursive: true });

    this.#log("Initialized.");
  }

  #log(text, ...args) {
    console.log(`\x1b[32m[LocalWhisper]\x1b[0m ${text}`, ...args);
  }

  #validateAudioFile(wavFile) {
    const sampleRate = wavFile.fmt.sampleRate;
    const duration = wavFile.data.samples / sampleRate;

    // Most speech recognition systems expect minimum 8kHz
    // But we'll set it lower to be safe
    if (sampleRate < 4000) {
      // 4kHz minimum
      throw new Error(
        "Audio file sample rate is too low for accurate transcription. Minimum required is 4kHz."
      );
    }

    // Typical audio file duration limits
    const MAX_DURATION_SECONDS = 4 * 60 * 60; // 4 hours
    if (duration > MAX_DURATION_SECONDS) {
      throw new Error("Audio file duration exceeds maximum limit of 4 hours.");
    }

    // Check final sample count after upsampling to prevent memory issues
    const targetSampleRate = 16000;
    const upsampledSamples = duration * targetSampleRate;
    const MAX_SAMPLES = 230_400_000; // ~4 hours at 16kHz

    if (upsampledSamples > MAX_SAMPLES) {
      throw new Error("Audio file exceeds maximum allowed length.");
    }

View on GitHub (pinned to 526360e320)

Solutions

  1. Ensure all audio flows through convertAudioToWav (which forces 16 kHz) before validation.
  2. Re-encode the source to at least 16 kHz before passing to LocalWhisper.
  3. Inspect wavFile.fmt.sampleRate to confirm the header parsed correctly.

Example fix

// before
if (sampleRate < 4000) throw new Error("Audio file sample rate is too low...");

// after — include the actual rate for debugging
if (sampleRate < 4000)
  throw new Error(`Sample rate ${sampleRate} Hz is below the 4 kHz minimum.`);
Defensive patterns

Strategy: validation

Validate before calling

function sampleRateOk(wavFile) {
  return (wavFile?.fmt?.sampleRate ?? 0) >= 4000;
}

Type guard

function isValidWav(wav) {
  return !!wav && typeof wav === "object"
    && wav.fmt && typeof wav.fmt.sampleRate === "number"
    && wav.data && typeof wav.data.samples === "number";
}

Try / catch

try { this.#validateAudioFile(wavFile); }
catch (e) {
  if (e.message.includes("sample rate is too low")) { /* re-encode source to 16 kHz */ }
  throw e;
}

Prevention

When it happens

Trigger: A WAV reaching #validateAudioFile with fmt.sampleRate < 4000 — a hand-crafted file, a conversion that mis-parsed the header, or wavFile.fmt mis-read.

Common situations: Feeding a low-rate WAV directly; ffmpeg produced a malformed header; telephony audio downsampled below 4 kHz.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/1c26f8c751e0843a. Report an issue: GitHub.