{"record":{"id":"93d50d514ddd0621","repo":"xtekky/gpt4free","slug":"no-audio-chunks-received-from-elevenlabs","errorCode":null,"errorMessage":"No audio chunks received from ElevenLabs.","messagePattern":"No audio chunks received from ElevenLabs\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/audio/ElevenLabs.py","lineNumber":111,"sourceCode":"            # Wait until DOM body exists before injecting elements\n            await page.evaluate(\n                \"\"\"\n                document.body || new Promise(r => {\n                    document.addEventListener('DOMContentLoaded', r, {once: true});\n                })\n            \"\"\",\n                await_promise=True,\n            )\n\n            chunks = await page.evaluate(\n                _build_js(prompt, voice, model_id, output_format, language),\n                await_promise=True,\n            )\n        finally:\n            await stop_browser()\n\n        if not chunks:\n            raise RuntimeError(\"No audio chunks received from ElevenLabs.\")\n\n        audio_bytes = b\"\".join(base64.b64decode(c) for c in chunks)\n        # ponytail: whole response buffered; streaming per-chunk yield if memory matters\n        filename = get_filename([cls.__name__], prompt, \".mp3\", prompt)\n        target_path = os.path.join(get_media_dir(), filename)\n        ensure_media_dir()\n        with open(target_path, \"wb\") as f:\n            f.write(audio_bytes)\n\n        yield AudioResponse(f\"/media/{filename}\", text=prompt)\n\n\ndef _build_js(\n    prompt: str, voice: str, model_id: str, output_format: str, language: str\n) -> str:\n    \"\"\"Render invisible hcaptcha, fetch elevenlabs API with token, collect SSE audio chunks.\"\"\"\n    _text = json.dumps(prompt)\n    _voice = json.dumps(voice)","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/audio/ElevenLabs.py#L93-L129","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Update g4f to the latest version (browser-automation scripts are patched frequently)","Re-verify the hc_accessibility cookie is fresh and valid","Retry after a delay in case of transient rate limiting","For stable production use, switch to ElevenLabs' official API with an API key instead of the browser flow"],"exampleFix":"try:\n    resp = await client.speech.create(model='ElevenLabs', text=text, hc_accessibility=cookie)\nexcept RuntimeError as e:\n    if 'No audio chunks' in str(e):\n        resp = await client.speech.create(model='EdgeTTS', text=text)  # fallback TTS","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    resp = await client.speech.create(model='ElevenLabs', text=text, hc_accessibility=cookie)\nexcept RuntimeError as e:\n    if 'No audio chunks' in str(e):\n        resp = await client.speech.create(model='EdgeTTS', text=text)  # reliable fallback","preventionTips":["Treat browser-based ElevenLabs as best-effort: always keep a fallback TTS provider","Pin a known-good g4f version and update promptly when site-scraping breaks","For production, use the official ElevenLabs API with a key"],"tags":["elevenlabs","browser-automation","fragile-scraping","tts"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}