xtekky/gpt4free · error · RuntimeError

No audio chunks received from ElevenLabs.

Error message

No audio chunks received from ElevenLabs.

What it means

RuntimeError raised after the nodriver page.evaluate JS completes but returned no audio chunks (falsy). The in-page JavaScript is expected to call the ElevenLabs API and return base64 chunks; an empty result means the browser-side capture failed silently — playback never started, the request was blocked, or the JS contract broke.

Source

Thrown at g4f/Provider/audio/ElevenLabs.py:111

            # Wait until DOM body exists before injecting elements
            await page.evaluate(
                """
                document.body || new Promise(r => {
                    document.addEventListener('DOMContentLoaded', r, {once: true});
                })
            """,
                await_promise=True,
            )

            chunks = await page.evaluate(
                _build_js(prompt, voice, model_id, output_format, language),
                await_promise=True,
            )
        finally:
            await stop_browser()

        if not chunks:
            raise RuntimeError("No audio chunks received from ElevenLabs.")

        audio_bytes = b"".join(base64.b64decode(c) for c in chunks)
        # ponytail: whole response buffered; streaming per-chunk yield if memory matters
        filename = get_filename([cls.__name__], prompt, ".mp3", prompt)
        target_path = os.path.join(get_media_dir(), filename)
        ensure_media_dir()
        with open(target_path, "wb") as f:
            f.write(audio_bytes)

        yield AudioResponse(f"/media/{filename}", text=prompt)


def _build_js(
    prompt: str, voice: str, model_id: str, output_format: str, language: str
) -> str:
    """Render invisible hcaptcha, fetch elevenlabs API with token, collect SSE audio chunks."""
    _text = json.dumps(prompt)
    _voice = json.dumps(voice)

View on GitHub (pinned to 973504e177)

Solutions

  1. Update g4f to the latest version (browser-automation scripts are patched frequently)
  2. Re-verify the hc_accessibility cookie is fresh and valid
  3. Retry after a delay in case of transient rate limiting
  4. For stable production use, switch to ElevenLabs' official API with an API key instead of the browser flow

Example fix

try:
    resp = await client.speech.create(model='ElevenLabs', text=text, hc_accessibility=cookie)
except RuntimeError as e:
    if 'No audio chunks' in str(e):
        resp = await client.speech.create(model='EdgeTTS', text=text)  # fallback TTS
Defensive patterns

Strategy: fallback

Try / catch

try:
    resp = await client.speech.create(model='ElevenLabs', text=text, hc_accessibility=cookie)
except RuntimeError as e:
    if 'No audio chunks' in str(e):
        resp = await client.speech.create(model='EdgeTTS', text=text)  # reliable fallback

Prevention

When it happens

Trigger: The injected JS resolves with [] / null: ElevenLabs changed its web app so audio element capture finds nothing, the captcha gate blocked the request, or a network error in the browser tab.

Common situations: Site redesigns breaking the capture script; expired/invalid hc_accessibility cookie passing the earlier check but failing server-side; rate limiting from repeated automated calls.

Related errors


AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14). Data as JSON: /api/errors/93d50d514ddd0621. Report an issue: GitHub.