{"record":{"id":"0273a07164e2cb18","repo":"harry0703/MoneyPrinterTurbo","slug":"elevenlabs-returned-no-audio-data","errorCode":null,"errorMessage":"ElevenLabs returned no audio data","messagePattern":"ElevenLabs returned no audio data","errorType":"exception","errorClass":"ElevenLabsMusicError","httpStatus":null,"severity":"error","filePath":"app/services/elevenlabs_music.py","lineNumber":288,"sourceCode":"\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,\n    )\n    os.close(descriptor)\n    try:\n        model_id = _model_id()\n        logger.info(\n            \"requesting ElevenLabs background music: \"\n            f\"video={video_path}, model={model_id}, \"","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/harry0703/MoneyPrinterTurbo/blob/1f9f19c2021a68d04df228f33e9099a0c947f6f8/app/services/elevenlabs_music.py#L270-L306","documentation":"ElevenLabsMusicError raised by _stream_audio when the download completed with total_bytes == 0 — the response body contained no content chunks at all. Unlike a size or connection failure, the request 'succeeded' but delivered nothing, which usually means the endpoint answered 200 with an empty body (or the generation job produced no audio). The temp file is empty on disk and the error propagates.","triggerScenarios":"The Music generation endpoint returning an empty 200 body: exhausted credits mid-generation, an internal upstream failure surfaced as empty audio, or a proxy stripping the body.","commonSituations":"Quota exhausted right as the track was generated; transient upstream incidents; misconfigured gateways dropping streaming bodies.","solutions":["Retry the generation once — empty-body responses are typically transient upstream faults.","Check the subscription/credits state via test_connection() and the ElevenLabs dashboard if it recurs.","If a custom music_base_url/proxy is in use, verify it passes streaming response bodies through."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for attempt in range(2):\n    try:\n        return generate_bgm(video_path, output_path, prompt)\n    except ElevenLabsMusicError as e:\n        if 'no audio data' in str(e) and attempt == 0:\n            time.sleep(5)\n            continue\n        raise","preventionTips":["Retry empty-audio responses once with backoff before surfacing to the user.","Check ElevenLabs credits/subscription when the error repeats.","Verify custom base URLs/proxies forward streaming bodies unchanged."],"tags":["elevenlabs","empty-response","download","api"],"backgroundTag":null,"analyzedSha":"1f9f19c2021a68d04df228f33e9099a0c947f6f8","analyzedAt":"2026-08-14T19:41:05.568Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}