harry0703/MoneyPrinterTurbo · error · SoniloError

Sonilo audio exceeds the 30 MB limit

Error message

Sonilo audio exceeds the 30 MB limit

What it means

Raised when cumulative decoded audio bytes exceed MAX_GENERATED_AUDIO_BYTES (30 MB). This client-side safety cap enforces that a single video-to-music result stays consistent with the documented maximum input duration (videos are capped at 360 seconds), so an over-30MB stream means either a runaway generation or a protocol anomaly.

Source

Thrown at app/services/sonilo.py:259

            if event_type != "audio_chunk":
                logger.debug(f"ignoring unsupported Sonilo event: type={event_type}")
                continue

            stream_index = event.get("stream_index", 0)
            if stream_index != 0:
                continue
            encoded_chunk = event.get("data") or event.get("audio")
            if not isinstance(encoded_chunk, str) or not encoded_chunk:
                raise SoniloError("Sonilo returned an empty audio chunk")
            try:
                chunk = base64.b64decode(encoded_chunk, validate=True)
            except (binascii.Error, ValueError) as exc:
                raise SoniloError("Sonilo returned an invalid audio chunk") from exc
            if not chunk:
                raise SoniloError("Sonilo returned an empty audio chunk")
            total_bytes += len(chunk)
            if total_bytes > MAX_GENERATED_AUDIO_BYTES:
                raise SoniloError("Sonilo audio exceeds the 30 MB limit")
            output.write(chunk)
        output.flush()
        os.fsync(output.fileno())

    if not completed:
        raise SoniloError("Sonilo stream ended before completion")
    if total_bytes <= 0:
        raise SoniloError("Sonilo returned no audio data")
    return total_bytes, title


def _request_bgm(video_path: str, output_path: str, prompt: str) -> str:
    """请求配乐并在完整协议及音频校验通过后原子保存。"""
    output_dir = os.path.dirname(os.path.abspath(output_path))
    os.makedirs(output_dir, exist_ok=True)
    descriptor, temp_audio_path = tempfile.mkstemp(
        prefix=".sonilo-audio-",
        suffix=Path(output_path).suffix or ".m4a",

View on GitHub (pinned to 1f9f19c202)

Solutions

  1. Confirm the source video duration is within MAX_VIDEO_DURATION_SECONDS (360); a misreported container duration can make the server render extra audio.
  2. Check logs for whether byte totals grow steadily or spike; repeated or duplicate chunks indicate a provider bug worth reporting.
  3. If legitimate outputs genuinely exceed 30 MB, raise MAX_GENERATED_AUDIO_BYTES after verifying downstream consumers accept the size.
  4. Retry the task; a one-off runaway stream is transient.

Example fix

# before
MAX_GENERATED_AUDIO_BYTES = 30 * 1024 * 1024
# after (only if longer outputs are legitimate)
MAX_GENERATED_AUDIO_BYTES = 50 * 1024 * 1024
Defensive patterns

Strategy: validation

Validate before calling

import sonilo

# expected_worst_case: duration_s * provider_max_bitrate_bps / 8
if expected_worst_case_bytes(source_duration) > sonilo.MAX_GENERATED_AUDIO_BYTES:
    raise ValueError("expected audio exceeds the client 30 MB cap")

Try / catch

try:
    audio = request_bgm(video, out, prompt)
except SoniloError as exc:
    if "exceeds the 30 MB limit" in str(exc):
        # guard against runaway streams; never resume partial files
        cleanup_temp_and_retry_once()
    raise

Prevention

When it happens

Trigger: Generation runs far longer than the source video (server ignores duration limits); repeated chunks for stream_index 0 due to a server retry loop; a client-side loop bug accumulating a chunk twice; provider changing chunk semantics so the same audio is resent.

Common situations: Long (near six-minute) sources with high-bitrate output; a provider incident causing infinite chunk repeats; mismatch between the 360-second input cap and server-side render length.

Related errors


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