{"record":{"id":"231ea4f63dcb7dd5","repo":"Hmbown/CodeWhale","slug":"voice-clone-sample-is-too-large-after-base64-encod","errorCode":null,"errorMessage":"voice clone sample is too large after base64 encoding ({} bytes > 10 MB)","messagePattern":"voice clone sample is too large after base64 encoding \\((.+?) bytes > 10 MB\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/speech.rs","lineNumber":430,"sourceCode":"            path.display()\n        ))\n    })?;\n\n    voice_clone_data_uri_from_bytes(path, &bytes)\n        .map_err(|err| ToolError::invalid_input(err.to_string()))\n}\n\npub(crate) fn encode_voice_clone_sample_data_uri(path: &Path) -> anyhow::Result<String> {\n    let bytes = std::fs::read(path)\n        .with_context(|| format!(\"Failed to read voice clone sample {}\", path.display()))?;\n\n    voice_clone_data_uri_from_bytes(path, &bytes)\n}\n\nfn voice_clone_data_uri_from_bytes(path: &Path, bytes: &[u8]) -> anyhow::Result<String> {\n    let base64_audio = general_purpose::STANDARD.encode(bytes);\n    if base64_audio.len() > VOICE_CLONE_BASE64_MAX_BYTES {\n        anyhow::bail!(\n            \"voice clone sample is too large after base64 encoding ({} bytes > 10 MB)\",\n            base64_audio.len()\n        );\n    }\n\n    let extension = path\n        .extension()\n        .and_then(|value| value.to_str())\n        .unwrap_or_default()\n        .to_ascii_lowercase();\n    let mime = match extension.as_str() {\n        \"mp3\" => \"audio/mpeg\",\n        \"wav\" => \"audio/wav\",\n        other => {\n            anyhow::bail!(\"unsupported voice clone sample extension '{other}'. Use .mp3 or .wav.\");\n        }\n    };\n","sourceCodeStart":412,"sourceCodeEnd":448,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/speech.rs#L412-L448","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use a shorter sample: trim the clip to the minimum the voice-clone API requires (often just seconds)","Convert to compressed MP3 instead of WAV — mp3 at typical bitrates shrinks the payload several-fold","Lower sample rate / mono downmix before encoding (e.g. 16 kHz mono)","If you own the tool, note the limit applies post-encoding; a raw input under 10 MB can still be rejected"],"exampleFix":"// before\nffmpeg -i sample.wav sample.wav           # uncompressed, ~20 MB PCM\n// after\nffmpeg -i sample.wav -ar 16000 -ac 1 sample.mp3  # few MB, mp3 accepted","handlingStrategy":"validation","validationCode":"let b64len = (audio.len() + 2) / 3 * 4; if b64len > 10_000_000 { return Err(\"sample too large after base64\"); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Estimate base64 size (len*4/3) before calling","Prefer MP3 over WAV for samples","Trim samples to the minimum required duration","Downsample to 16 kHz mono before upload"],"tags":["audio","base64","size-limit","voice-clone"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}