{"record":{"id":"7cc36f91cfb66b4b","repo":"harry0703/MoneyPrinterTurbo","slug":"elevenlabs-audio-exceeds-the-50-mb-limit","errorCode":null,"errorMessage":"ElevenLabs audio exceeds the 50 MB limit","messagePattern":"ElevenLabs audio exceeds the 50 MB limit","errorType":"exception","errorClass":"ElevenLabsMusicError","httpStatus":null,"severity":"error","filePath":"app/services/elevenlabs_music.py","lineNumber":281,"sourceCode":"            \"ElevenLabs video proxy is empty or exceeds the 200 MB limit\"\n        )\n    logger.info(\n        \"ElevenLabs video proxy prepared: \"\n        f\"source={video_path}, size={proxy_size} bytes\"\n    )\n    return proxy_path\n\n\ndef _stream_audio(response: requests.Response, temp_audio_path: str) -> int:\n    \"\"\"分块保存音频并限制最大体积，防止异常响应耗尽本机磁盘。\"\"\"\n    total_bytes = 0\n    with open(temp_audio_path, \"wb\") as output:\n        for chunk in response.iter_content(chunk_size=1024 * 1024):\n            if not chunk:\n                continue\n            total_bytes += len(chunk)\n            if total_bytes > MAX_GENERATED_AUDIO_BYTES:\n                raise ElevenLabsMusicError(\n                    \"ElevenLabs audio exceeds the 50 MB limit\"\n                )\n            output.write(chunk)\n        output.flush()\n        os.fsync(output.fileno())\n    if total_bytes <= 0:\n        raise ElevenLabsMusicError(\"ElevenLabs returned no audio data\")\n    return total_bytes\n\n\ndef _request_bgm(video_path: str, output_path: str, prompt: str) -> str:\n    \"\"\"请求 ElevenLabs 配乐，完整下载并通过 FFmpeg 校验后再原子发布。\"\"\"\n    output_dir = os.path.dirname(os.path.abspath(output_path))\n    os.makedirs(output_dir, exist_ok=True)\n    descriptor, temp_audio_path = tempfile.mkstemp(\n        prefix=\".elevenlabs-music-\",\n        suffix=Path(output_path).suffix or \".mp3\",\n        dir=output_dir,","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/harry0703/MoneyPrinterTurbo/blob/1f9f19c2021a68d04df228f33e9099a0c947f6f8/app/services/elevenlabs_music.py#L263-L299","documentation":"ElevenLabsMusicError raised by _stream_audio while downloading the generated track: cumulative bytes crossed MAX_GENERATED_AUDIO_BYTES (50 MB, app/services/elevenlabs_music.py:24). The download is chunked at 1 MB precisely so an abnormally large or endless response is cut off early instead of filling the disk. The temp audio file (created via mkstemp in the output dir) is left for the caller's cleanup path.","triggerScenarios":"The Music endpoint responding with an audio stream larger than 50 MB — e.g. an extremely long prompt-generated track, a WAV instead of compressed MP3, or a malformed/looping response body.","commonSituations":"Very long video durations producing long tracks; API behavior changes returning uncompressed audio; a proxy or retry layer duplicating the body.","solutions":["Retry once — oversized responses from a generation glitch are rare and transient.","Shorten the source video / music prompt so the generated track is smaller (cost scales with duration).","If it reproduces consistently, capture response headers (Content-Type/Content-Length) to see whether the API started returning WAV or duplicated bodies, and report upstream."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    generate_bgm(video_path, output_path, prompt)\nexcept ElevenLabsMusicError as e:\n    if 'exceeds the 50 MB limit' in str(e):\n        time.sleep(3)\n        generate_bgm(video_path, output_path, shorter_prompt_or_trimmed_video)","preventionTips":["Keep source videos and prompts modest — generated track size scales with duration.","Retry once before escalating; oversized responses are usually one-off glitches.","If reproducible, inspect Content-Type/Length of the music response for API behavior changes."],"tags":["elevenlabs","download","size-limit","streaming"],"backgroundTag":null,"analyzedSha":"1f9f19c2021a68d04df228f33e9099a0c947f6f8","analyzedAt":"2026-08-14T19:41:05.568Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}