{"record":{"id":"b66aac71a73753c7","repo":"Panniantong/Agent-Reach","slug":"audio-chunks-total-total-chunk-bytes-bytes-safe","errorCode":null,"errorMessage":"audio chunks total {total_chunk_bytes} bytes; safety limit is {limit_mib:g} MiB","messagePattern":"audio chunks total (.+?) bytes; safety limit is (.+?) MiB","errorType":"exception","errorClass":"TranscribeError","httpStatus":null,"severity":"error","filePath":"agent_reach/transcribe.py","lineNumber":475,"sourceCode":"    if compressed.stat().st_size <= SIZE_LIMIT_BYTES:\n        chunks = [compressed]\n    else:\n        chunks = chunk_audio(compressed, work_dir)\n\n    if len(chunks) > MAX_CHUNKS:\n        max_minutes = MAX_CHUNKS * CHUNK_SECONDS // 60\n        raise TranscribeError(\n            f\"audio produced {len(chunks)} chunks; safety limit is \"\n            f\"{MAX_CHUNKS} (~{max_minutes} minutes)\"\n        )\n    chunk_sizes = [\n        _require_size_at_most(chunk, SIZE_LIMIT_BYTES, f\"chunk {chunk.name}\")\n        for chunk in chunks\n    ]\n    total_chunk_bytes = sum(chunk_sizes)\n    if total_chunk_bytes > MAX_TOTAL_CHUNK_BYTES:\n        limit_mib = MAX_TOTAL_CHUNK_BYTES / (1024 * 1024)\n        raise TranscribeError(\n            f\"audio chunks total {total_chunk_bytes} bytes; \"\n            f\"safety limit is {limit_mib:g} MiB\"\n        )\n\n    pieces: List[str] = []\n    for chunk in chunks:\n        text = _transcribe_with_fallback(chunk, order, cfg)\n        pieces.append(text.strip())\n    return \"\\n\".join(p for p in pieces if p)\n\n\ndef _transcribe_with_fallback(chunk: Path, order: List[str], config: Config) -> str:\n    \"\"\"Try each provider in order; return first success or raise the last error.\"\"\"\n    last_err: Optional[Exception] = None\n    for p in order:\n        if not _provider_key(p, config):\n            # Skip silently — caller already validated at least one is configured.\n            continue","sourceCodeStart":457,"sourceCodeEnd":493,"githubUrl":"https://github.com/Panniantong/Agent-Reach/blob/93ae1d18c37b707dec053c7c4f9d91cd8ef8943d/agent_reach/transcribe.py#L457-L493","documentation":"Raised when the sum of all chunk sizes exceeds MAX_TOTAL_CHUNK_BYTES (96 MiB) after per-chunk size validation passes. Even when each chunk is under the 24 MiB Whisper limit, the aggregate upload budget (cost/time guard) is capped at 96 MiB per transcribe() call. It fires before any upload, so no API spend has occurred.","triggerScenarios":"Calling transcribe() on audio where chunk_audio produces e.g. 5 chunks of ~20 MiB each (100 MiB total) — each passes the per-chunk SIZE_LIMIT_BYTES check but the sum exceeds MAX_TOTAL_CHUNK_BYTES. Typical for high-bitheadroom audio that compresses poorly.","commonSituations":"High-bitrate music-heavy or noise-heavy sources (podcasts with music beds, concert recordings); WAV/FLAC sources converted at conservative compression settings; long audio near but under the 4-hour chunk-count cap.","solutions":["Reduce source length: trim with yt-dlp --download-sections or ffmpeg and transcribe parts separately","Re-encode the source at a lower bitrate (e.g. ffmpeg -b:a 48k mono flac/opus) before calling transcribe()","Check that ffmpeg compression is actually succeeding in your environment (doctor verifies ffmpeg presence)"],"exampleFix":"# before\ntext = transcribe(\"huge_recording.wav\")  # chunks total > 96 MiB\n\n# after — pre-compress to speech-friendly bitrate\n# ffmpeg -i huge_recording.wav -ac 1 -b:a 32k small.opus\ntext = transcribe(\"small.opus\")","handlingStrategy":"validation","validationCode":"from agent_reach.transcribe import MAX_TOTAL_CHUNK_BYTES  # 96 MiB\n\ndef compressed_size_ok(path: str) -> bool:\n    import os\n    return os.path.getsize(path) <= MAX_TOTAL_CHUNK_BYTES","typeGuard":null,"tryCatchPattern":"from agent_reach.transcribe import transcribe, TranscribeError\ntry:\n    text = transcribe(src)\nexcept TranscribeError as e:\n    if \"chunks total\" in str(e):\n        src = recompress_mono_low_bitrate(src)  # ffmpeg -ac 1 -b:a 32k\n        text = transcribe(src)\n    else:\n        raise","preventionTips":["Pre-encode speech audio to mono, low-bitrate opus/flac before transcribe()","Remember both caps: per-chunk 24 MiB, aggregate 96 MiB, count 24 chunks","Check compressed output size, not source size — compression ratio decides"],"tags":["transcription","audio","limits","size","ffmpeg"],"backgroundTag":null,"analyzedSha":"93ae1d18c37b707dec053c7c4f9d91cd8ef8943d","analyzedAt":"2026-08-14T22:54:06.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}