Mintplex-Labs/anything-llm · warning · Error

Audio file duration exceeds maximum limit of 4 hours.

Error message

Audio file duration exceeds maximum limit of 4 hours.

What it means

Rejects WAVs longer than 14400 seconds (4 hours), computed as data.samples / sampleRate. Guards against runaway memory and CPU use during Whisper transcription.

Source

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

  }

  #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.");
    }

    return true;
  }

  async #convertToWavAudioData(sourcePath) {
    try {
      let buffer;
      const wavefile = require("wavefile");

View on GitHub (pinned to 526360e320)

Solutions

  1. Split the source into <4 h segments before transcription.
  2. Trim to the relevant portion.
  3. Sanity-check the header-derived duration against file size.

Example fix

// before
const MAX_DURATION_SECONDS = 4 * 60 * 60;
if (duration > MAX_DURATION_SECONDS) throw new Error("...4 hours.");

// after — configurable limit + actual duration reported
const MAX_DURATION_SECONDS = opts.maxDuration ?? (4 * 60 * 60);
if (duration > MAX_DURATION_SECONDS)
  throw new Error(`Duration ${duration}s exceeds ${MAX_DURATION_SECONDS}s.`);
Defensive patterns

Strategy: validation

Validate before calling

function durationSeconds(wav) {
  return wav.data.samples / wav.fmt.sampleRate;
}
// if (durationSeconds(wav) > 14400) split the file before transcription;

Try / catch

try { this.#validateAudioFile(wavFile); }
catch (e) {
  if (e.message.includes("duration exceeds")) { /* chunk and retry */ }
  throw e;
}

Prevention

When it happens

Trigger: A genuinely long recording (>4 h) reaches validation, or a mis-parsed header inflates data.samples relative to sampleRate.

Common situations: Multi-hour podcasts/lectures; concatenated audio; a corrupt header reporting a huge sample count.

Related errors


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