Hmbown/CodeWhale · error

voice clone sample is too large after base64 encoding

Error message

voice clone sample is too large after base64 encoding ({} bytes > 10 MB)

What it means

voice_clone_data_uri_from_bytes base64-encodes an audio sample and enforces VOICE_CLONE_BASE64_MAX_BYTES (10 MB) on the encoded size. Base64 inflates data by ~4/3, so a raw sample over ~7.5 MB trips this even though the file itself is under 10 MB.

Solutions

  1. Use a shorter sample: trim the clip to the minimum the voice-clone API requires (often just seconds)
  2. Convert to compressed MP3 instead of WAV — mp3 at typical bitrates shrinks the payload several-fold
  3. Lower sample rate / mono downmix before encoding (e.g. 16 kHz mono)
  4. If you own the tool, note the limit applies post-encoding; a raw input under 10 MB can still be rejected

Example fix

// before
ffmpeg -i sample.wav sample.wav           # uncompressed, ~20 MB PCM
// after
ffmpeg -i sample.wav -ar 16000 -ac 1 sample.mp3  # few MB, mp3 accepted
Defensive patterns

Strategy: validation

Validate before calling

let b64len = (audio.len() + 2) / 3 * 4; if b64len > 10_000_000 { return Err("sample too large after base64"); }

Prevention

When it happens

Trigger: Calling encode_voice_clone_data_uri or encode_voice_clone_sample_data_uri with an audio file whose base64 encoding exceeds 10 MB — e.g. a raw WAV file larger than ~7.5 MB, or any file whose encoded length > 10,000,000 bytes.

Common situations: Recording a long voice-clone sample as uncompressed WAV (large headers + PCM); passing a studio-quality multi-minute clip; confusing the 10 MB base64 limit with a 10 MB file-size limit.

Understand the failure class

Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/231ea4f63dcb7dd5. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/tools/speech.rs:430

            path.display()
        ))
    })?;

    voice_clone_data_uri_from_bytes(path, &bytes)
        .map_err(|err| ToolError::invalid_input(err.to_string()))
}

pub(crate) fn encode_voice_clone_sample_data_uri(path: &Path) -> anyhow::Result<String> {
    let bytes = std::fs::read(path)
        .with_context(|| format!("Failed to read voice clone sample {}", path.display()))?;

    voice_clone_data_uri_from_bytes(path, &bytes)
}

fn voice_clone_data_uri_from_bytes(path: &Path, bytes: &[u8]) -> anyhow::Result<String> {
    let base64_audio = general_purpose::STANDARD.encode(bytes);
    if base64_audio.len() > VOICE_CLONE_BASE64_MAX_BYTES {
        anyhow::bail!(
            "voice clone sample is too large after base64 encoding ({} bytes > 10 MB)",
            base64_audio.len()
        );
    }

    let extension = path
        .extension()
        .and_then(|value| value.to_str())
        .unwrap_or_default()
        .to_ascii_lowercase();
    let mime = match extension.as_str() {
        "mp3" => "audio/mpeg",
        "wav" => "audio/wav",
        other => {
            anyhow::bail!("unsupported voice clone sample extension '{other}'. Use .mp3 or .wav.");
        }
    };

View on GitHub (pinned to 73e0f67d83)