harry0703/MoneyPrinterTurbo · error · ElevenLabsMusicError

ElevenLabs returned no audio data

Error message

ElevenLabs returned no audio data

What it means

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.

Source

Thrown at app/services/elevenlabs_music.py:288


def _stream_audio(response: requests.Response, temp_audio_path: str) -> int:
    """分块保存音频并限制最大体积,防止异常响应耗尽本机磁盘。"""
    total_bytes = 0
    with open(temp_audio_path, "wb") as output:
        for chunk in response.iter_content(chunk_size=1024 * 1024):
            if not chunk:
                continue
            total_bytes += len(chunk)
            if total_bytes > MAX_GENERATED_AUDIO_BYTES:
                raise ElevenLabsMusicError(
                    "ElevenLabs audio exceeds the 50 MB limit"
                )
            output.write(chunk)
        output.flush()
        os.fsync(output.fileno())
    if total_bytes <= 0:
        raise ElevenLabsMusicError("ElevenLabs returned no audio data")
    return total_bytes


def _request_bgm(video_path: str, output_path: str, prompt: str) -> str:
    """请求 ElevenLabs 配乐,完整下载并通过 FFmpeg 校验后再原子发布。"""
    output_dir = os.path.dirname(os.path.abspath(output_path))
    os.makedirs(output_dir, exist_ok=True)
    descriptor, temp_audio_path = tempfile.mkstemp(
        prefix=".elevenlabs-music-",
        suffix=Path(output_path).suffix or ".mp3",
        dir=output_dir,
    )
    os.close(descriptor)
    try:
        model_id = _model_id()
        logger.info(
            "requesting ElevenLabs background music: "
            f"video={video_path}, model={model_id}, "

View on GitHub (pinned to 1f9f19c202)

Solutions

  1. Retry the generation once — empty-body responses are typically transient upstream faults.
  2. Check the subscription/credits state via test_connection() and the ElevenLabs dashboard if it recurs.
  3. If a custom music_base_url/proxy is in use, verify it passes streaming response bodies through.
Defensive patterns

Strategy: retry

Try / catch

for attempt in range(2):
    try:
        return generate_bgm(video_path, output_path, prompt)
    except ElevenLabsMusicError as e:
        if 'no audio data' in str(e) and attempt == 0:
            time.sleep(5)
            continue
        raise

Prevention

When it happens

Trigger: 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.

Common situations: Quota exhausted right as the track was generated; transient upstream incidents; misconfigured gateways dropping streaming bodies.

Related errors


AI-assisted analysis of harry0703/MoneyPrinterTurbo@1f9f19c202 (2026-08-14). Data as JSON: /api/errors/0273a07164e2cb18. Report an issue: GitHub.