Streams synthesis as Server-Sent Events so you can start playing audio before the full clip is
ready. The request body is identical to /speak; the response is an
text/event-stream body instead of a single file.
Authorization
string
Your workspace API key (flv_…), from server-side code. Required scope:tts.
string
Alternative for browsers: Bearer fin_tok_…, a short-lived, single-use token your server minted with
Create an access token. Send either this or X-API-Key.
Path parameters
string
required
The voice id.
Body
string
required
The text to synthesize. Maximum 10,000 characters.
string
BCP-47 language code (for example en, hi). Defaults to the voice’s primary language.
string
Chunk encoding. One of s16le, s24le, s32le, f32le, f64le (raw, headerless PCM), or
mulaw (G.711 µ-law for phone calls, requires sample_rate: 8000). Chunks arrive base64-encoded
either way; the format decides the sample width.
integer
default:24000
Output sample rate in Hz. Defaults to the provider’s native rate (24000); values above it are
upsampled. 8000 (telephony) is produced as asked; other rates below 24000 return 24000. The
effective rate is reported in the start event.
integer
default:32
Number of inference steps, 1–32 (a quality/latency trade-off). Provider default (32) if
omitted.
number
Accepted (0.0–1.0) but has no effect today: the engine ignores it, so the audio is the
same with or without it.
Response headers
string
text/event-stream (with Cache-Control: no-cache and X-Accel-Buffering: no so proxies don’t
buffer the stream).
string
Your remaining character allowance for the month (present when billing is active). Streaming is
metered per character of text, same as /speak.
Event format
Each event is delimited per the SSE spec (event: line, data: JSON line, blank line):
Sent once at the beginning. sample_rate is the effective output rate and audio_format the
PCM encoding of the chunks - use these (not what you requested) to configure playback.
event
One per audio chunk, in order. index is the 0-based position; audio_b64 is base64-encoded raw
PCM audio to append to your buffer.
event
Sent once when synthesis is complete; no more chunks follow. Carries audio_duration_s (total
seconds of audio), and - when object storage is enabled - generation_id and a public audio_url
of the full clip as a WAV file, so you can link or re-download it without reassembling the chunks.
event
Sent if synthesis fails, with a code and message: upstream_error (retry later),
upstream_busy (the synthesis service is at capacity), invalid_input (fix the text), or
stream_incomplete (the stream ended before synthesis finished). The stream ends after it.
Streaming requires the streaming feature on your plan; without it the request returns 403 when
billing enforcement is active, and an exhausted character allowance returns 402 (a flat billing
body, or the standard envelope with message: "insufficient_credits") - see
Errors. Streamed synthesis is never served from cache.
curl -N -X POST \ "https://fi.production.flamapis.com/flam-voice-svc/api/v1/public/voices/665f1a2b3c4d5e6f7a8b9c0d/stream" \ -H "X-API-Key: $FINESSE_API_KEY" \ -H "Content-Type: application/json" \ -d '{"text":"Streaming hello from Finesse.","language":"en"}'
const id = "665f1a2b3c4d5e6f7a8b9c0d";const res = await fetch( `https://fi.production.flamapis.com/flam-voice-svc/api/v1/public/voices/${id}/stream`, { method: "POST", headers: { "X-API-Key": process.env.FINESSE_API_KEY, "Content-Type": "application/json", }, body: JSON.stringify({ text: "Streaming hello from Finesse.", language: "en" }), },);const reader = res.body.getReader();const decoder = new TextDecoder();let buffer = "";for (;;) { const { done, value } = await reader.read(); if (done) break; buffer += decoder.decode(value, { stream: true }); let sep; while ((sep = buffer.indexOf("\n\n")) !== -1) { const frame = buffer.slice(0, sep); buffer = buffer.slice(sep + 2); const line = frame.split("\n").find((l) => l.startsWith("data:")); if (!line) continue; const ev = JSON.parse(line.slice(5).trim()); if (ev.type === "chunk") { const pcm = Buffer.from(ev.audio_b64, "base64"); // append to your audio buffer } else if (ev.type === "done") { break; } else if (ev.type === "error") { throw new Error(ev.message ?? ev.code); } }}
import os, base64, json, requestsvoice_id = "665f1a2b3c4d5e6f7a8b9c0d"with requests.post( f"https://fi.production.flamapis.com/flam-voice-svc/api/v1/public/voices/{voice_id}/stream", headers={"X-API-Key": os.environ["FINESSE_API_KEY"], "Content-Type": "application/json"}, json={"text": "Streaming hello from Finesse.", "language": "en"}, stream=True,) as res: res.raise_for_status() for raw in res.iter_lines(): if not raw or not raw.startswith(b"data:"): continue ev = json.loads(raw[5:].strip()) if ev["type"] == "chunk": pcm = base64.b64decode(ev["audio_b64"]) # append to your audio buffer elif ev["type"] == "done": break elif ev["type"] == "error": raise RuntimeError(ev.get("message") or ev.get("code"))
Prompt
Copy this into your coding agent (Claude Code, Cursor, Codex…) to implement this endpoint.
You are implementing a typed client for one Finesse Voice API endpoint: "Stream speech (SSE)".Everything you need is in this prompt. Do not invent anything that is not specified here.WHAT TO BUILD- A function streamSpeech(voiceId, params, options) (name it per the project's conventions) that streams synthesis as Server-Sent Events and exposes typed events in order, as an async iterator or callbacks, whichever fits the stack. Support cancellation (AbortSignal or equivalent).- A convenience helper that consumes the stream and returns { pcm: bytes, sampleRate, audioFormat, audioDurationS, audioUrl?, generationId? }.- Use a streaming HTTP read (fetch + res.body reader in TypeScript, requests stream=True / httpx stream in Python). Do not add an EventSource dependency: EventSource cannot send POST bodies or custom headers.- Detect the stack first: look for package.json, tsconfig.json, pyproject.toml, requirements.txt, go.mod, Gemfile, composer.json and similar. Use the project's language, HTTP client, module layout, error-handling conventions and test runner. If there is no project yet or the stack is unclear, use TypeScript on Node 18+ with the built-in fetch and no new dependencies.- If the project already has a Finesse API client module, add this to it (reuse its auth, base URL, error type and retry helper) instead of creating a parallel one.- Keep the base URL (https://fi.production.flamapis.com) in one constant or config value.ENDPOINT- Method: POST- URL: https://fi.production.flamapis.com/flam-voice-svc/api/v1/public/voices/{id}/stream- Request Content-Type: application/json- Success response Content-Type: text/event-stream (with Cache-Control: no-cache and X-Accel-Buffering: no so proxies do not buffer)- The voice must be "ready" and belong to the key's workspace or be a public platform voice (as returned by the list endpoint).PARAMETERS- id (path, string, required): the voice id, a 24-character hex string (for example "665f1a2b3c4d5e6f7a8b9c0d"). Validate it locally against /^[0-9a-f]{24}$/i and URL-encode it.REQUEST BODY (same fields as the one-shot /speak endpoint, except output_format)- text (string, required): maximum 10,000 characters (check locally, counting Unicode code points; reject empty text).- language (string, optional): BCP-47 code (e.g. "en", "hi"). Defaults to the voice's primary_language.- output_format (string, optional): chunk encoding, one of "s16le", "s24le", "s32le", "f32le", "f64le" (raw, headerless PCM), or "mulaw" (G.711 mu-law for phone calls, requires sample_rate 8000). Chunks arrive base64-encoded either way; the format decides the sample width. Do not offer "wav" for streaming.- sample_rate (integer, optional, default 24000): output rate in Hz; values above the native 24000 are upsampled, 8000 (telephony) is produced as asked, other lower rates return 24000. The EFFECTIVE rate is reported in the start event.- num_step (integer, optional, default 32): 1-32, quality vs latency.- expressiveness (number, optional): accepted (0.0-1.0) but has no effect today; the engine ignores it. Do not present it as a working control.- Omit optional fields the caller did not set. { "text": "Streaming hello from Finesse.", "language": "en" }AUTHENTICATION- Send the header X-API-Key: <workspace API key> on every request. Keys start with "flv_".- Required scope: tts. Keys carry one or more scopes (voices:read, voices:write, clone, tts); a key without this scope gets 403 with code "insufficient_scope". Keys created before scopes existed have all four.- Read the key from the environment variable FINESSE_API_KEY (or the project's existing secrets or config mechanism). Fail fast with a clear error if it is missing, before making any request.- Never hard-code, log or commit the key, and never ship it in browser/client-side code: call this from server-side code only. A key with the tts scope can synthesize with every voice in its workspace.- A key is bound to one workspace. Referencing a voice or job from another workspace returns 404.- Keys can expire: an expired key returns 401 with code "key_expired". Do not retry; surface it so an operator can rotate the key.- Browser alternative: instead of X-API-Key, send Authorization: Bearer <token> with a short-lived "fin_tok_..." token that YOUR server minted via POST https://fi.production.flamapis.com/flam-voice-svc/api/v1/public/tokens (see the "Create an access token" endpoint). A token grants tts only, is single use (consumed by one successful request), and may be restricted to specific voice_ids. Unknown, expired or already-used token: 401 with code "token_invalid" (mint a new one). Voice outside the token's voice_ids: 403 with code "voice_not_allowed". Only support this mode if the project needs browser-side synthesis.EVENT STREAM FORMATEach event follows the SSE spec: an "event:" line, a "data:" line with JSON, then a blank line. event: start data: {"type":"start","sample_rate":24000,"audio_format":"s16le"} event: chunk data: {"type":"chunk","index":0,"audio_b64":"<base64 PCM>"} event: chunk data: {"type":"chunk","index":1,"audio_b64":"<base64 PCM>"} event: done data: {"type":"done","audio_duration_s":3.42,"generation_id":"665f1a2b3c4d5e6f7a8b9f10","audio_url":"https://storage.googleapis.com/.../speech.wav"}Event types (dispatch on the JSON "type" field):- start: sent once first. sample_rate is the EFFECTIVE output rate and audio_format the PCM encoding of the chunks. Use these, not what you requested, to configure playback.- chunk: one per audio chunk, in order. index is the 0-based position; audio_b64 is base64 raw PCM to append to your buffer. Append in arrival order and do not fail if index is missing.- done: sent once when synthesis is complete; no more chunks follow. Carries audio_duration_s (total seconds of audio) and, when object storage is enabled, generation_id and a public audio_url of the full clip as a WAV file (optional fields).- error: sent if synthesis fails, with a "code" and "message". Codes: "upstream_error", "upstream_busy", "invalid_input", "stream_incomplete" (keep code a string; unknown codes must not crash). The stream ends after it; surface it as a typed error.Parser requirements:- Buffer across network reads; split events on blank lines; accept both \n and \r\n line endings; join multiple "data:" lines of one event with \n; ignore comment lines starting with ":" and unknown event types.- If the stream closes without a done or error event, treat it as an incomplete-stream error, not success.ERRORS BEFORE THE STREAM STARTSA non-200 status means no stream: read the body as JSON (never as SSE). Errors use the standardenvelope: { "status": 400, "error": true, "message": "text too long (max 10000 chars)" }Billing and plan denials do NOT use the envelope. They return a flat JSON body whose "error"field is a string, not a boolean: { "error": "plan limit reached", "feature": "max_voices", "limit": 10 } { "error": "quota_exhausted", "unit": "character", "limit": 100000, "used": 100000 }The "error" string is the denial reason (for example quota_exhausted, insufficient_credits,feature_disabled, or "plan limit reached"). Tell the two shapes apart bychecking whether "error" is a boolean (envelope) or a string (flat denial), and exposefeature / unit / limit / used on your error type when present.A 402 can come in either shape. The plan check before synthesis returns the flat body; the creditcheck inside synthesis returns the standard envelope: { "status": 402, "error": true, "message": "insufficient_credits" }- 400: invalid request, text over 10,000 characters, or the voice is not ready yet. Do not retry.- 401: X-API-Key missing, malformed, invalid or revoked, or code "key_expired" / "token_invalid". Do not retry.- 402: not enough credits or allowance (flat body, or the envelope with message "insufficient_credits"). Do not retry.- 403 with code "insufficient_scope": the key lacks the tts scope. Do not retry.- 403 with code "voice_not_allowed": the Bearer token is restricted to other voices. Do not retry.- 403: the plan does not include the "streaming" feature (flat body, error "feature_disabled"). Do not retry.- 404 with code "not_found" (also returned for a malformed id): voice not found, including voices owned by another workspace. Do not retry.- 422 with code "invalid_input": the input could not be processed. Do not retry.- 429 with code "rate_limited" (over the plan's requests per second) or "concurrency_limited" (the workspace already has its plan's maximum synthesis requests in flight): wait the number of seconds in the Retry-After header, then retry with backoff. See /guides/rate-limits.- 502 with code "upstream_error": the synthesis service failed or is warming up. Retry with backoff.- 503 with code "upstream_busy": the synthesis service is at capacity. Wait the number of seconds in the Retry-After header, then retry with backoff.- Surface failures as one typed error (for example FinesseApiError) carrying: HTTP status, code (when present), message (the envelope "message" or the flat "error" string), optional feature / unit / limit / used, a retryable flag, the request id (the X-Request-Id response header; error bodies also carry it as request_id), and the raw body for debugging. Log the request id with every failure.- Parse error bodies defensively: if a body is not valid JSON, keep the raw text in the error.RETRIES- Retry 429, 502, 503 and network errors ONLY if no event has been received yet (on 429/503 wait the Retry-After seconds first), with exponential backoff plus jitter (at most 3 retries). The first request after a long idle can be slow while the engine warms up; use a generous, configurable time-to-first-event timeout.- Never auto-retry after the stream has started or after an error event: streamed synthesis is never served from cache, so every attempt is billed again. Surface the error and let the caller decide.- Never retry 400, 401, 402, 403, 404 or 422.BILLING- Metered per character of text, same as /speak, against the monthly allowance.- Requires the "streaming" feature on the plan.- Capture X-Billing-Remaining (remaining characters, present when billing is active) as an optional number on the result.ACCEPTANCE CRITERIA- streamSpeech yields typed start / chunk / done / error events in order and decodes chunk audio from base64 to bytes.- The helper returns the concatenated PCM with the effective sample_rate and audio_format from the start event, plus audio_duration_s, audio_url and generation_id from done when present.- Pre-stream failures are parsed as JSON into the typed error; error events and incomplete streams reject; cancellation aborts the HTTP request.- The key is never logged or sent from client-side code.TEST PLAN- Unit tests feeding a fake SSE body split at awkward byte boundaries (mid-line, mid-JSON, CRLF): start + 3 chunks + done; an error event; a stream that ends without done; unknown event ignored; pre-stream 403 flat body and 400 envelope; retry on 502 before the first event; no retry after a chunk was received.- Smoke script:- Get a ready voice id from FLAM_VOICE_ID, or by calling GET https://fi.production.flamapis.com/flam-voice-svc/api/v1/public/voices (same X-API-Key header; voices are in data.voices) and picking the first one whose status is "ready". - Stream "Streaming hello from Finesse.", print the start event, the number of chunks, total PCM bytes, audio_duration_s and audio_url, and the time to the first chunk. Exit non-zero on error.RULES- Implement only what this spec describes. Do not invent parameters, fields, headers, endpoints or error codes. If something is ambiguous, missing, or conflicts with the existing codebase, stop and ask me before guessing.- Match the project's existing style and conventions; do not refactor unrelated code.
{"docsConfig":{"theme":"aspen","$schema":"https://mintlify.com/docs.json","name":"Finesse","description":"Finesse - realtime speech in 60 languages. Clone a voice and stream it in real time across 60 languages, 22 of them Indic.","colors":{"primary":"#2547F0","light":"#4F72FF","dark":"#1E3AD0"},"logo":{"light":"https://mintcdn.com/finesse-docs/u9NNXVA8yD6Y29Xd/logo/finesse-light.png?fit=max\u0026auto=format\u0026n=u9NNXVA8yD6Y29Xd\u0026q=85\u0026s=665b8b35d46e51f6ae805dffc09b6fc1","dark":"https://mintcdn.com/finesse-docs/u9NNXVA8yD6Y29Xd/logo/finesse-dark.png?fit=max\u0026auto=format\u0026n=u9NNXVA8yD6Y29Xd\u0026q=85\u0026s=1f28d4f2a2c26f147ce021c785c0e24a","href":"/introduction"},"favicon":{"light":"https://mintcdn.com/finesse-docs/0zFrmLlrHoW1tpnK/favicon.svg?fit=max\u0026auto=format\u0026n=0zFrmLlrHoW1tpnK\u0026q=85\u0026s=8b7f46bccba82eb14857fc9cc7baba20","dark":"https://mintcdn.com/finesse-docs/0zFrmLlrHoW1tpnK/favicon-dark.svg?fit=max\u0026auto=format\u0026n=0zFrmLlrHoW1tpnK\u0026q=85\u0026s=4d0d37da9ba0022182827b3ee360664c"},"api":{"mdx":{"auth":{"method":"key","name":"X-API-Key"},"server":"https://fi.production.flamapis.com"}},"appearance":{"default":"light","strict":true},"background":{"color":{"light":"#F5F3EE","dark":"#0E0F11"}},"navbar":{"links":[{"href":"/guides/authentication","label":"Get an API key"}],"primary":{"type":"button","label":"Dashboard","href":"https://finesse.flamapp.ai/dashboard"}},"fonts":{"heading":{"family":"Bricolage Grotesque","weight":700},"body":{"family":"Instrument Sans"}},"contextual":{"options":["copy","view"],"display":"header"},"styling":{"latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"finesse-docs","hasAudioNarration":false,"actualSubdomain":"finesse-docs","customDomains":["docs.finesse.flamapp.ai"],"gitSource":{"type":"github","owner":"homingos","repo":"fe-flam-voice","deployBranch":"production","contentDirectory":"docs","isPrivate":true,"mountPath":"","label":""},"entitlements":{},"buildId":"6afaecc7213a1421d385ef81","clientVersion":"0.0.4344","searchFilterCounts":[{"language":"default","tag":"API reference","count":17},{"language":"default","tag":"SDKs","count":13},{"language":"default","tag":"Voices","count":8},{"language":"default","tag":"TypeScript SDK","count":7},{"language":"default","tag":"Reference","count":6},{"language":"default","tag":"Get started","count":5},{"language":"default","tag":"Speech","count":4},{"language":"default","tag":"Essentials","count":3},{"language":"default","tag":"Start here","count":2},{"language":"default","tag":"Integrations","count":2}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"site-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"starter-pricing","enabled":true,"variant":{"name":"treatment","enabled":true,"payload":{"type":"string","value":"treatment"},"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"wildcard-email-auth","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"starterQuestions":[],"googleFontsInlined":true},"customCss":[]}
{"page":{"pagePath":"voice-api/stream-speech","slug":"/voice-api/stream-speech","pageMetadata":{"title":"Stream speech (SSE)","description":"Stream synthesized audio as Server-Sent Events for low-latency playback.","api":"POST /flam-voice-svc/api/v1/public/voices/{id}/stream","href":"/voice-api/stream-speech"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Stream synthesized audio as Server-Sent Events for low-latency playback.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,..._provideComponents(),...props.components},{CodeBlock,CodeGroup,Heading,Note,ParamField,ResponseField}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!CodeGroup)_missingMdxReference(`CodeGroup`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Note)_missingMdxReference(`Note`,true);if(!ParamField)_missingMdxReference(`ParamField`,true);if(!ResponseField)_missingMdxReference(`ResponseField`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`Streams synthesis as `,_jsx(_components.strong,{children:`Server-Sent Events`}),` so you can start playing audio before the full clip is\nready. The request body is identical to `,_jsx(_components.a,{href:`/voice-api/synthesize-speech`,children:_jsx(_components.code,{children:`/speak`})}),`; the response is an\n`,_jsx(_components.code,{children:`text/event-stream`}),` body instead of a single file.`]}),`\n`,_jsx(Heading,{level:`4`,id:`authorization`,children:`Authorization`}),`\n`,_jsx(ParamField,{header:`X-API-Key`,type:`string`,id:`param-x-api-key`,children:_jsxs(_components.p,{children:[`Your workspace API key (`,_jsx(_components.code,{children:`flv_…`}),`), from server-side code. `,_jsx(_components.strong,{children:`Required scope:`}),` `,_jsx(_components.code,{children:`tts`}),`.`]})}),`\n`,_jsx(ParamField,{header:`Authorization`,type:`string`,id:`param-authorization`,children:_jsxs(_components.p,{children:[`Alternative for browsers: `,_jsx(_components.code,{children:`Bearer fin_tok_…`}),`, a short-lived, single-use token your server minted with\n`,_jsx(_components.a,{href:`/voice-api/create-token`,children:`Create an access token`}),`. Send either this or `,_jsx(_components.code,{children:`X-API-Key`}),`.`]})}),`\n`,_jsx(Heading,{level:`4`,id:`path-parameters`,children:`Path parameters`}),`\n`,_jsx(ParamField,{path:`id`,type:`string`,required:true,id:`param-id`,children:_jsx(_components.p,{children:`The voice id.`})}),`\n`,_jsx(Heading,{level:`4`,id:`body`,children:`Body`}),`\n`,_jsx(ParamField,{body:`text`,type:`string`,required:true,initialValue:`Streaming hello from Finesse.`,id:`param-text`,children:_jsxs(_components.p,{children:[`The text to synthesize. Maximum `,_jsx(_components.strong,{children:`10,000 characters`}),`.`]})}),`\n`,_jsx(ParamField,{body:`language`,type:`string`,id:`param-language`,children:_jsxs(_components.p,{children:[`BCP-47 language code (for example `,_jsx(_components.code,{children:`en`}),`, `,_jsx(_components.code,{children:`hi`}),`). Defaults to the voice’s primary language.`]})}),`\n`,_jsx(ParamField,{body:`output_format`,type:`string`,id:`param-output-format`,children:_jsxs(_components.p,{children:[`Chunk encoding. One of `,_jsx(_components.code,{children:`s16le`}),`, `,_jsx(_components.code,{children:`s24le`}),`, `,_jsx(_components.code,{children:`s32le`}),`, `,_jsx(_components.code,{children:`f32le`}),`, `,_jsx(_components.code,{children:`f64le`}),` (raw, headerless PCM), or\n`,_jsx(_components.code,{children:`mulaw`}),` (G.711 µ-law for phone calls, requires `,_jsx(_components.code,{children:`sample_rate: 8000`}),`). Chunks arrive base64-encoded\neither way; the format decides the sample width.`]})}),`\n`,_jsx(ParamField,{body:`sample_rate`,type:`integer`,default:24e3,initialValue:24e3,id:`param-sample-rate`,children:_jsxs(_components.p,{children:[`Output sample rate in Hz. Defaults to the provider’s native rate (`,_jsx(_components.code,{children:`24000`}),`); values above it are\nupsampled. `,_jsx(_components.code,{children:`8000`}),` (telephony) is produced as asked; other rates below `,_jsx(_components.code,{children:`24000`}),` return `,_jsx(_components.code,{children:`24000`}),`. The\neffective rate is reported in the `,_jsx(_components.code,{children:`start`}),` event.`]})}),`\n`,_jsx(ParamField,{body:`num_step`,type:`integer`,default:32,initialValue:32,id:`param-num-step`,children:_jsxs(_components.p,{children:[`Number of inference steps, `,_jsx(_components.code,{children:`1`}),`–`,_jsx(_components.code,{children:`32`}),` (a quality/latency trade-off). Provider default (`,_jsx(_components.code,{children:`32`}),`) if\nomitted.`]})}),`\n`,_jsx(ParamField,{body:`expressiveness`,type:`number`,initialValue:.5,id:`param-expressiveness`,children:_jsxs(_components.p,{children:[`Accepted (`,_jsx(_components.code,{children:`0.0`}),`–`,_jsx(_components.code,{children:`1.0`}),`) but has `,_jsx(_components.strong,{children:`no effect today`}),`: the engine ignores it, so the audio is the\nsame with or without it.`]})}),`\n`,_jsx(Heading,{level:`4`,id:`response-headers`,children:`Response headers`}),`\n`,_jsx(ResponseField,{name:`Content-Type`,type:`string`,id:`param-content-type`,children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`text/event-stream`}),` (with `,_jsx(_components.code,{children:`Cache-Control: no-cache`}),` and `,_jsx(_components.code,{children:`X-Accel-Buffering: no`}),` so proxies don’t\nbuffer the stream).`]})}),`\n`,_jsx(ResponseField,{name:`X-Billing-Remaining`,type:`string`,id:`param-x-billing-remaining`,children:_jsxs(_components.p,{children:[`Your remaining character allowance for the month (present when billing is active). Streaming is\nmetered per character of `,_jsx(_components.code,{children:`text`}),`, same as `,_jsx(_components.a,{href:`/voice-api/synthesize-speech`,children:_jsx(_components.code,{children:`/speak`})}),`.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`event-format`,children:`Event format`}),`\n`,_jsxs(_components.p,{children:[`Each event is delimited per the SSE spec (`,_jsx(_components.code,{children:`event:`}),` line, `,_jsx(_components.code,{children:`data:`}),` JSON line, blank line):`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`12`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`12`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`event: start`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`data: {\"type\":\"start\",\"sample_rate\":24000,\"audio_format\":\"s16le\"}`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`event: chunk`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`data: {\"type\":\"chunk\",\"index\":0,\"audio_b64\":\"\u003cbase64 PCM>\"}`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`event: chunk`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`data: {\"type\":\"chunk\",\"index\":1,\"audio_b64\":\"\u003cbase64 PCM>\"}`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`event: done`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`data: {\"type\":\"done\",\"audio_duration_s\":3.42,\"generation_id\":\"665f1a2b3c4d5e6f7a8b9f10\",\"audio_url\":\"https://storage.googleapis.com/.../speech.wav\"}`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsx(ResponseField,{name:`start`,type:`event`,id:`param-start`,children:_jsxs(_components.p,{children:[`Sent once at the beginning. `,_jsx(_components.code,{children:`sample_rate`}),` is the `,_jsx(_components.strong,{children:`effective`}),` output rate and `,_jsx(_components.code,{children:`audio_format`}),` the\nPCM encoding of the chunks - use these (not what you requested) to configure playback.`]})}),`\n`,_jsx(ResponseField,{name:`chunk`,type:`event`,id:`param-chunk`,children:_jsxs(_components.p,{children:[`One per audio chunk, in order. `,_jsx(_components.code,{children:`index`}),` is the 0-based position; `,_jsx(_components.code,{children:`audio_b64`}),` is base64-encoded raw\nPCM audio to append to your buffer.`]})}),`\n`,_jsx(ResponseField,{name:`done`,type:`event`,id:`param-done`,children:_jsxs(_components.p,{children:[`Sent once when synthesis is complete; no more chunks follow. Carries `,_jsx(_components.code,{children:`audio_duration_s`}),` (total\nseconds of audio), and - when object storage is enabled - `,_jsx(_components.code,{children:`generation_id`}),` and a public `,_jsx(_components.code,{children:`audio_url`}),`\nof the full clip as a WAV file, so you can link or re-download it without reassembling the chunks.`]})}),`\n`,_jsx(ResponseField,{name:`error`,type:`event`,id:`param-error`,children:_jsxs(_components.p,{children:[`Sent if synthesis fails, with a `,_jsx(_components.code,{children:`code`}),` and `,_jsx(_components.code,{children:`message`}),`: `,_jsx(_components.code,{children:`upstream_error`}),` (retry later),\n`,_jsx(_components.code,{children:`upstream_busy`}),` (the synthesis service is at capacity), `,_jsx(_components.code,{children:`invalid_input`}),` (fix the text), or\n`,_jsx(_components.code,{children:`stream_incomplete`}),` (the stream ended before synthesis finished). The stream ends after it.`]})}),`\n`,_jsx(Note,{children:_jsxs(_components.p,{children:[`Streaming requires the `,_jsx(_components.code,{children:`streaming`}),` feature on your plan; without it the request returns `,_jsx(_components.code,{children:`403`}),` when\nbilling enforcement is active, and an exhausted character allowance returns `,_jsx(_components.code,{children:`402`}),` (a flat billing\nbody, or the standard envelope with `,_jsx(_components.code,{children:`message: \"insufficient_credits\"`}),`) - see\n`,_jsx(_components.a,{href:`/voice-api/errors`,children:`Errors`}),`. Streamed synthesis is never served from cache.`]})}),`\n`,_jsxs(CodeGroup,{children:[_jsx(CodeBlock,{filename:`cURL`,numberOfLines:`5`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`5`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`curl`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -N`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -X`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` POST`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"https://fi.production.flamapis.com/flam-voice-svc/api/v1/public/voices/665f1a2b3c4d5e6f7a8b9c0d/stream\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"X-API-Key: `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`$FINESSE_API_KEY`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Content-Type: application/json\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -d`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{\"text\":\"Streaming hello from Finesse.\",\"language\":\"en\"}'`})]}),`\n`]})})}),_jsx(CodeBlock,{filename:`JavaScript`,numberOfLines:`36`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`36`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` id`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"665f1a2b3c4d5e6f7a8b9c0d\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` res`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` fetch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\" `https://fi.production.flamapis.com/flam-voice-svc/api/v1/public/voices/\"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`id`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"/stream`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` method:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"POST\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` headers:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"X-API-Key\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` process`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`env`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`FINESSE_API_KEY`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Content-Type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"application/json\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` body:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` JSON`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`stringify`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`text:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Streaming hello from Finesse.\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`language:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"en\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }),`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` reader`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` res`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`body`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`getReader`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` decoder`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` TextDecoder`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`let`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` buffer`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (;;) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` const`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`done`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`value`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` reader`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`read`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`done`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`break`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` buffer`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` +=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` decoder`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`decode`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`value`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`stream:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` });`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` let`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` sep`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` while`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ((`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`sep`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` buffer`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`indexOf`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`\\\\n\\\\n`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!==`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` -`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` frame`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` buffer`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`slice`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`sep`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` buffer`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` buffer`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`slice`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`sep`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` +`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 2`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` line`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` frame`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`split`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`\\\\n`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`).`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`find`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`((`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`l`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`=>`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` l`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`startsWith`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"data:\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`));`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`line`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`continue`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` ev`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` JSON`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`parse`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`line`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`slice`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`5`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`).`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`trim`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`());`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`ev`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`type`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ===`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"chunk\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` pcm`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` Buffer`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`ev`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`audio_b64`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"base64\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`); `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// append to your audio buffer`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`else`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`ev`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`type`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ===`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"done\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` break`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`else`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`ev`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`type`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ===`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"error\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` throw`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` Error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`ev`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`message`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ??`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` ev`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`code`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),_jsx(CodeBlock,{filename:`Python`,numberOfLines:`20`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`20`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` os, base64, json, requests`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`voice_id `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"665f1a2b3c4d5e6f7a8b9c0d\"`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` requests.post(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"https://fi.production.flamapis.com/flam-voice-svc/api/v1/public/voices/`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`voice_id`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`/stream\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` headers`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"X-API-Key\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: os.environ[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"FINESSE_API_KEY\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`], `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Content-Type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"application/json\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`},`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` json`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"text\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Streaming hello from Finesse.\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"language\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"en\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`},`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` stream`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` res:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` res.raise_for_status()`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` raw `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` res.iter_lines():`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` not`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` raw `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`or`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` not`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` raw.startswith(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`b`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"data:\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` continue`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ev `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` json.loads(raw[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`5`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:].strip())`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ev[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`] `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"chunk\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` pcm `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` base64.b64decode(ev[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"audio_b64\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]) `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# append to your audio buffer`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` elif`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ev[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`] `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"done\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` break`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` elif`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ev[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`] `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"error\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` raise`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` RuntimeError`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(ev.get(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"message\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`or`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ev.get(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"code\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`))`})]}),`\n`]})})})]}),`\n`,_jsx(Heading,{level:`2`,id:`prompt`,children:`Prompt`}),`\n`,_jsx(_components.p,{children:`Copy this into your coding agent (Claude Code, Cursor, Codex…) to implement this endpoint.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`197`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`197`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`You are implementing a typed client for one Finesse Voice API endpoint: \"Stream speech (SSE)\".`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`Everything you need is in this prompt. Do not invent anything that is not specified here.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`WHAT TO BUILD`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- A function streamSpeech(voiceId, params, options) (name it per the project's conventions) that`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` streams synthesis as Server-Sent Events and exposes typed events in order, as an async iterator`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` or callbacks, whichever fits the stack. Support cancellation (AbortSignal or equivalent).`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- A convenience helper that consumes the stream and returns { pcm: bytes, sampleRate, audioFormat,`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` audioDurationS, audioUrl?, generationId? }.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Use a streaming HTTP read (fetch + res.body reader in TypeScript, requests stream=True / httpx`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` stream in Python). Do not add an EventSource dependency: EventSource cannot send POST bodies or`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` custom headers.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Detect the stack first: look for package.json, tsconfig.json, pyproject.toml,`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` requirements.txt, go.mod, Gemfile, composer.json and similar. Use the project's language, HTTP`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` client, module layout, error-handling conventions and test runner. If there is no project yet or`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` the stack is unclear, use TypeScript on Node 18+ with the built-in fetch and no new dependencies.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- If the project already has a Finesse API client module, add this to it (reuse its auth, base`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` URL, error type and retry helper) instead of creating a parallel one.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Keep the base URL (https://fi.production.flamapis.com) in one constant or config value.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`ENDPOINT`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Method: POST`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- URL: https://fi.production.flamapis.com/flam-voice-svc/api/v1/public/voices/{id}/stream`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Request Content-Type: application/json`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Success response Content-Type: text/event-stream (with Cache-Control: no-cache and`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` X-Accel-Buffering: no so proxies do not buffer)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- The voice must be \"ready\" and belong to the key's workspace or be a public platform voice (as`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` returned by the list endpoint).`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`PARAMETERS`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- id (path, string, required): the voice id, a 24-character hex string (for example`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` \"665f1a2b3c4d5e6f7a8b9c0d\"). Validate it locally against /^[0-9a-f]{24}$/i and URL-encode it.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`REQUEST BODY (same fields as the one-shot /speak endpoint, except output_format)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- text (string, required): maximum 10,000 characters (check locally, counting Unicode code points;`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` reject empty text).`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- language (string, optional): BCP-47 code (e.g. \"en\", \"hi\"). Defaults to the voice's`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` primary_language.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- output_format (string, optional): chunk encoding, one of \"s16le\", \"s24le\", \"s32le\", \"f32le\",`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` \"f64le\" (raw, headerless PCM), or \"mulaw\" (G.711 mu-law for phone calls, requires`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` sample_rate 8000). Chunks arrive base64-encoded either way; the format decides the sample width.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` Do not offer \"wav\" for streaming.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- sample_rate (integer, optional, default 24000): output rate in Hz; values above the native 24000`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` are upsampled, 8000 (telephony) is produced as asked, other lower rates return 24000. The`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` EFFECTIVE rate is reported in the start event.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- num_step (integer, optional, default 32): 1-32, quality vs latency.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- expressiveness (number, optional): accepted (0.0-1.0) but has no effect today; the engine`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` ignores it. Do not present it as a working control.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Omit optional fields the caller did not set.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` { \"text\": \"Streaming hello from Finesse.\", \"language\": \"en\" }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`AUTHENTICATION`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Send the header X-API-Key: \u003cworkspace API key> on every request. Keys start with \"flv_\".`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Required scope: tts. Keys carry one or more scopes (voices:read, voices:write, clone,`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` tts); a key without this scope gets 403 with code \"insufficient_scope\". Keys created before`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` scopes existed have all four.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Read the key from the environment variable FINESSE_API_KEY (or the project's existing secrets or`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` config mechanism). Fail fast with a clear error if it is missing, before making any request.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Never hard-code, log or commit the key, and never ship it in browser/client-side code: call this`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` from server-side code only. A key with the tts scope can synthesize with every voice in its`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` workspace.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- A key is bound to one workspace. Referencing a voice or job from another workspace returns 404.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Keys can expire: an expired key returns 401 with code \"key_expired\". Do not retry; surface it so`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` an operator can rotate the key.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Browser alternative: instead of X-API-Key, send Authorization: Bearer \u003ctoken> with a`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` short-lived \"fin_tok_...\" token that YOUR server minted via`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` POST https://fi.production.flamapis.com/flam-voice-svc/api/v1/public/tokens (see the \"Create an`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` access token\" endpoint). A token grants tts only, is single use (consumed by one successful`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` request), and may be restricted to specific voice_ids. Unknown, expired or already-used token:`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` 401 with code \"token_invalid\" (mint a new one). Voice outside the token's voice_ids: 403 with code`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` \"voice_not_allowed\". Only support this mode if the project needs browser-side synthesis.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`EVENT STREAM FORMAT`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`Each event follows the SSE spec: an \"event:\" line, a \"data:\" line with JSON, then a blank line.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` event: start`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` data: {\"type\":\"start\",\"sample_rate\":24000,\"audio_format\":\"s16le\"}`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` event: chunk`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` data: {\"type\":\"chunk\",\"index\":0,\"audio_b64\":\"\u003cbase64 PCM>\"}`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` event: chunk`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` data: {\"type\":\"chunk\",\"index\":1,\"audio_b64\":\"\u003cbase64 PCM>\"}`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` event: done`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` data: {\"type\":\"done\",\"audio_duration_s\":3.42,\"generation_id\":\"665f1a2b3c4d5e6f7a8b9f10\",\"audio_url\":\"https://storage.googleapis.com/.../speech.wav\"}`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`Event types (dispatch on the JSON \"type\" field):`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- start: sent once first. sample_rate is the EFFECTIVE output rate and audio_format the PCM`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` encoding of the chunks. Use these, not what you requested, to configure playback.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- chunk: one per audio chunk, in order. index is the 0-based position; audio_b64 is base64 raw PCM`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` to append to your buffer. Append in arrival order and do not fail if index is missing.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- done: sent once when synthesis is complete; no more chunks follow. Carries audio_duration_s`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` (total seconds of audio) and, when object storage is enabled, generation_id and a public`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` audio_url of the full clip as a WAV file (optional fields).`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- error: sent if synthesis fails, with a \"code\" and \"message\". Codes: \"upstream_error\",`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` \"upstream_busy\", \"invalid_input\", \"stream_incomplete\" (keep code a string; unknown codes must not`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` crash). The stream ends after it; surface it as a typed error.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`Parser requirements:`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Buffer across network reads; split events on blank lines; accept both \\\\n and \\\\r\\\\n line endings;`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` join multiple \"data:\" lines of one event with \\\\n; ignore comment lines starting with \":\" and`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` unknown event types.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- If the stream closes without a done or error event, treat it as an incomplete-stream error, not`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` success.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`ERRORS BEFORE THE STREAM STARTS`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`A non-200 status means no stream: read the body as JSON (never as SSE). Errors use the standard`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`envelope:`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` {`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` \"status\": 400,`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` \"error\": true,`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` \"message\": \"text too long (max 10000 chars)\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`Billing and plan denials do NOT use the envelope. They return a flat JSON body whose \"error\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`field is a string, not a boolean:`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` { \"error\": \"plan limit reached\", \"feature\": \"max_voices\", \"limit\": 10 }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` { \"error\": \"quota_exhausted\", \"unit\": \"character\", \"limit\": 100000, \"used\": 100000 }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`The \"error\" string is the denial reason (for example quota_exhausted, insufficient_credits,`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`feature_disabled, or \"plan limit reached\"). Tell the two shapes apart by`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`checking whether \"error\" is a boolean (envelope) or a string (flat denial), and expose`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`feature / unit / limit / used on your error type when present.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`A 402 can come in either shape. The plan check before synthesis returns the flat body; the credit`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`check inside synthesis returns the standard envelope:`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` { \"status\": 402, \"error\": true, \"message\": \"insufficient_credits\" }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- 400: invalid request, text over 10,000 characters, or the voice is not ready yet. Do not retry.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- 401: X-API-Key missing, malformed, invalid or revoked, or code \"key_expired\" /`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` \"token_invalid\". Do not retry.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- 402: not enough credits or allowance (flat body, or the envelope with message`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` \"insufficient_credits\"). Do not retry.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- 403 with code \"insufficient_scope\": the key lacks the tts scope. Do not retry.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- 403 with code \"voice_not_allowed\": the Bearer token is restricted to other voices. Do not retry.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- 403: the plan does not include the \"streaming\" feature (flat body, error \"feature_disabled\").`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` Do not retry.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- 404 with code \"not_found\" (also returned for a malformed id): voice not found, including voices owned by another workspace. Do not retry.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- 422 with code \"invalid_input\": the input could not be processed. Do not retry.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- 429 with code \"rate_limited\" (over the plan's requests per second) or \"concurrency_limited\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` (the workspace already has its plan's maximum synthesis requests in flight): wait the number of seconds in the Retry-After header, then retry with backoff.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` See /guides/rate-limits.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- 502 with code \"upstream_error\": the synthesis service failed or is warming up. Retry with backoff.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- 503 with code \"upstream_busy\": the synthesis service is at capacity. Wait the number of seconds in the Retry-After header, then retry with backoff.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Surface failures as one typed error (for example FinesseApiError) carrying: HTTP status,`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` code (when present), message`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` (the envelope \"message\" or the flat \"error\" string), optional feature / unit / limit / used, a`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` retryable flag, the request id (the X-Request-Id response header; error bodies also carry it as`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` request_id), and the raw body for debugging. Log the request id with every failure.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Parse error bodies defensively: if a body is not valid JSON, keep the raw text in the error.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`RETRIES`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Retry 429, 502, 503 and network errors ONLY if no event has been received yet (on 429/503 wait`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` the Retry-After seconds first), with exponential backoff plus jitter (at most 3 retries). The first request after a long idle can be slow while`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` the engine warms up; use a generous, configurable time-to-first-event timeout.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Never auto-retry after the stream has started or after an error event: streamed synthesis is`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` never served from cache, so every attempt is billed again. Surface the error and let the caller`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` decide.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Never retry 400, 401, 402, 403, 404 or 422.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`BILLING`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Metered per character of text, same as /speak, against the monthly allowance.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Requires the \"streaming\" feature on the plan.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Capture X-Billing-Remaining (remaining characters, present when billing is active) as an`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` optional number on the result.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`ACCEPTANCE CRITERIA`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- streamSpeech yields typed start / chunk / done / error events in order and decodes chunk audio`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` from base64 to bytes.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- The helper returns the concatenated PCM with the effective sample_rate and audio_format from the`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` start event, plus audio_duration_s, audio_url and generation_id from done when present.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Pre-stream failures are parsed as JSON into the typed error; error events and incomplete streams`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` reject; cancellation aborts the HTTP request.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- The key is never logged or sent from client-side code.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`TEST PLAN`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Unit tests feeding a fake SSE body split at awkward byte boundaries (mid-line, mid-JSON, CRLF):`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` start + 3 chunks + done; an error event; a stream that ends without done; unknown event ignored;`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` pre-stream 403 flat body and 400 envelope; retry on 502 before the first event; no retry after a`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` chunk was received.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Smoke script:`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Get a ready voice id from FLAM_VOICE_ID, or by calling GET https://fi.production.flamapis.com/flam-voice-svc/api/v1/public/voices (same`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` X-API-Key header; voices are in data.voices) and picking the first one whose status is \"ready\".`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` - Stream \"Streaming hello from Finesse.\", print the start event, the number of chunks, total PCM`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` bytes, audio_duration_s and audio_url, and the time to the first chunk. Exit non-zero on error.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`RULES`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Implement only what this spec describes. Do not invent parameters, fields, headers, endpoints or`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` error codes. If something is ambiguous, missing, or conflicts with the existing codebase, stop`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` and ask me before guessing.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`- Match the project's existing style and conventions; do not refactor unrelated code.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Stream speech (SSE)","description":"Stream synthesized audio as Server-Sent Events for low-latency playback.","api":"POST /flam-voice-svc/api/v1/public/voices/{id}/stream","href":"/voice-api/stream-speech"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Authorization","slug":"authorization","depth":4,"children":[]},{"title":"Path parameters","slug":"path-parameters","depth":4,"children":[]},{"title":"Body","slug":"body","depth":4,"children":[]},{"title":"Response headers","slug":"response-headers","depth":4,"children":[]},{"title":"Event format","slug":"event-format","depth":2,"children":[]},{"title":"Prompt","slug":"prompt","depth":2,"children":[]}],"codeExamples":{},"endpoint":{"title":"Stream speech (SSE)","path":"/flam-voice-svc/api/v1/public/voices/{id}/stream","servers":[{"url":"https://fi.production.flamapis.com"}],"method":"post","request":{"security":[{"title":"API Key Auth","parameters":{"header":{"X-API-Key":{"type":"apiKey"}},"query":{},"cookie":{}}}],"parameters":{"query":{},"header":{"X-API-Key":{"schema":[{"type":"string","description":"Your workspace API key ( `flv_…` ), from server-side code. Required scope: `tts` ."}]},"Authorization":{"schema":[{"type":"string","description":"Alternative for browsers: `Bearer fin_tok_…` , a short-lived, single-use token your server minted with Create an access token . Send either this or `X-API-Key` ."}]}},"cookie":{},"path":{"id":{"schema":[{"type":"string","description":"The voice id.","required":true}]}}},"body":{"application/json":{"schemaArray":[{"type":"object","properties":{"text":[{"type":"string","description":"The text to synthesize. Maximum 10,000 characters .","required":true}],"language":[{"type":"string","description":"BCP-47 language code (for example `en` , `hi` ). Defaults to the voice’s primary language."}],"output_format":[{"type":"string","description":"Chunk encoding. One of `s16le` , `s24le` , `s32le` , `f32le` , `f64le` (raw, headerless PCM), or `mulaw` (G.711 µ-law for phone calls, requires `sample_rate: 8000` ). Chunks arrive base64-encoded either way; the format decides the sample width."}],"sample_rate":[{"type":"integer","description":"Output sample rate in Hz. Defaults to the provider’s native rate ( `24000` ); values above it are upsampled. `8000` (telephony) is produced as asked; other rates below `24000` return `24000` . The effective rate is reported in the `start` event."}],"num_step":[{"type":"integer","description":"Number of inference steps, `1` – `32` (a quality/latency trade-off). Provider default ( `32` ) if omitted."}],"expressiveness":[{"type":"number","description":"Accepted ( `0.0` – `1.0` ) but has no effect today : the engine ignores it, so the audio is the same with or without it."}]}}],"examples":{"example":{"value":{"text":"\u003cstring>","language":"\u003cstring>","output_format":"\u003cstring>","sample_rate":123,"num_step":123,"expressiveness":123}}}}}},"response":{"200":{"application/json":{"schemaArray":[{"type":"object","properties":{"Content-Type":[{"type":"string","description":"`text/event-stream` (with `Cache-Control: no-cache` and `X-Accel-Buffering: no` so proxies don’t buffer the stream)."}],"X-Billing-Remaining":[{"type":"string","description":"Your remaining character allowance for the month (present when billing is active). Streaming is metered per character of `text` , same as `/speak` ."}],"start":[{"type":"object","properties":{},"description":"Sent once at the beginning. `sample_rate` is the effective output rate and `audio_format` the PCM encoding of the chunks - use these (not what you requested) to configure playback."}],"chunk":[{"type":"object","properties":{},"description":"One per audio chunk, in order. `index` is the 0-based position; `audio_b64` is base64-encoded raw PCM audio to append to your buffer."}],"done":[{"type":"object","properties":{},"description":"Sent once when synthesis is complete; no more chunks follow. Carries `audio_duration_s` (total seconds of audio), and - when object storage is enabled - `generation_id` and a public `audio_url` of the full clip as a WAV file, so you can link or re-download it without reassembling the chunks."}],"error":[{"type":"object","properties":{},"description":"Sent if synthesis fails, with a `code` and `message` : `upstream_error` (retry later), `upstream_busy` (the synthesis service is at capacity), `invalid_input` (fix the text), or `stream_incomplete` (the stream ended before synthesis finished). The stream ends after it."}]}}],"examples":{"example":{"value":{"Content-Type":"\u003cstring>","X-Billing-Remaining":"\u003cstring>","start":{},"chunk":{},"done":{},"error":{}}}}}}},"deprecated":false}},"jsLinks":[],"subdomain":"finesse-docs","siteName":"Finesse","title":"Stream speech (SSE) - Finesse","contextualStarterQuestions":[],"navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-10-21T19:26:24.311Z","originalFileLocation":"voice-api/stream-speech.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=\"light\";if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"light\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Stream synthesized audio as Server-Sent Events for low-latency playback.\">\u003cmeta data-mint-head name=\"application-name\" content=\"Finesse\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/finesse-docs/9nsqrG5QOUT6LAm6/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/finesse-docs/9nsqrG5QOUT6LAm6/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/finesse-docs/9nsqrG5QOUT6LAm6/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/finesse-docs/9nsqrG5QOUT6LAm6/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/finesse-docs/9nsqrG5QOUT6LAm6/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/finesse-docs/9nsqrG5QOUT6LAm6/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/finesse-docs/9nsqrG5QOUT6LAm6/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/finesse-docs/9nsqrG5QOUT6LAm6/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/finesse-docs/9nsqrG5QOUT6LAm6/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Stream speech (SSE) - Finesse\">\u003cmeta data-mint-head property=\"og:description\" content=\"Stream synthesized audio as Server-Sent Events for low-latency playback.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Finesse\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.finesse.flamapp.ai/voice-api/stream-speech\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://finesse-docs.mintlify.site/_mintlify/api/og/v2?division=Speech\u0026amp;title=Stream+speech+%28SSE%29\u0026amp;description=Stream+synthesized+audio+as+Server-Sent+Events+for+low-latency+playback.\u0026amp;theme=b900d03be7b2e5a1a2310fa6\u0026amp;signature=bb29f161404f8913e3cfeb1b5e7dba24dc14c14ceecabf87559f7757b42bd3dd\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Stream speech (SSE) - Finesse\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Stream synthesized audio as Server-Sent Events for low-latency playback.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://finesse-docs.mintlify.site/_mintlify/api/og/v2?division=Speech\u0026amp;title=Stream+speech+%28SSE%29\u0026amp;description=Stream+synthesized+audio+as+Server-Sent+Events+for+low-latency+playback.\u0026amp;theme=b900d03be7b2e5a1a2310fa6\u0026amp;signature=bb29f161404f8913e3cfeb1b5e7dba24dc14c14ceecabf87559f7757b42bd3dd\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/finesse-docs/9nsqrG5QOUT6LAm6/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Finesse\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#2547F0\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.finesse.flamapp.ai/voice-api/stream-speech\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/voice-api/stream-speech.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.finesse.flamapp.ai/#organization\",\"name\":\"Finesse\",\"url\":\"https://docs.finesse.flamapp.ai\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/finesse-docs/u9NNXVA8yD6Y29Xd/logo/finesse-light.png?fit=max\u0026auto=format\u0026n=u9NNXVA8yD6Y29Xd\u0026q=85\u0026s=665b8b35d46e51f6ae805dffc09b6fc1\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.finesse.flamapp.ai#website\",\"name\":\"Finesse\",\"url\":\"https://docs.finesse.flamapp.ai\",\"publisher\":{\"@id\":\"https://docs.finesse.flamapp.ai/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.finesse.flamapp.ai/voice-api/stream-speech#webpage\",\"url\":\"https://docs.finesse.flamapp.ai/voice-api/stream-speech\",\"name\":\"Stream speech (SSE)\",\"description\":\"Stream synthesized audio as Server-Sent Events for low-latency playback.\",\"dateModified\":\"2026-10-21T19:26:24.311Z\",\"isPartOf\":{\"@id\":\"https://docs.finesse.flamapp.ai#website\"},\"breadcrumb\":{\"@id\":\"https://docs.finesse.flamapp.ai/voice-api/stream-speech#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.finesse.flamapp.ai/voice-api/stream-speech#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Speech\",\"item\":\"https://docs.finesse.flamapp.ai/voice-api/synthesize-speech\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Stream speech (SSE)\",\"item\":\"https://docs.finesse.flamapp.ai/voice-api/stream-speech\"}]},{\"@type\":[\"TechArticle\",\"APIReference\"],\"@id\":\"https://docs.finesse.flamapp.ai/voice-api/stream-speech#apireference\",\"headline\":\"Stream speech (SSE)\",\"name\":\"Stream speech (SSE)\",\"description\":\"Stream synthesized audio as Server-Sent Events for low-latency playback.\",\"url\":\"https://docs.finesse.flamapp.ai/voice-api/stream-speech\",\"mainEntityOfPage\":{\"@id\":\"https://docs.finesse.flamapp.ai/voice-api/stream-speech#webpage\"},\"dateModified\":\"2026-10-21T19:26:24.311Z\",\"publisher\":{\"@id\":\"https://docs.finesse.flamapp.ai/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.finesse.flamapp.ai#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Finesse\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"Finesse\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/voice-api/stream-speech.md","siteName":"Finesse","nav":{"global":null,"tabs":[{"tab":"Get started","pages":[{"title":"Get started","href":"/introduction"}]},{"tab":"SDKs","pages":[{"title":"SDKs","href":"/sdks/overview"}]},{"tab":"API reference","groups":[{"group":"Authentication","icon":"lock","pages":[{"title":"Create an access token","api":"POST /flam-voice-svc/api/v1/public/tokens","tag":"START HERE","href":"/voice-api/create-token"}]},{"group":"Voices","icon":"microphone","pages":[{"title":"List voices","api":"GET /flam-voice-svc/api/v1/public/voices","href":"/voice-api/list-voices"},{"title":"Get a voice","api":"GET /flam-voice-svc/api/v1/public/voices/{id}","href":"/voice-api/get-voice"},{"title":"Create a voice","api":"POST /flam-voice-svc/api/v1/public/voices","href":"/voice-api/create-voice"},{"title":"Clone a voice","api":"POST /flam-voice-svc/api/v1/public/voices/clone","href":"/voice-api/clone-voice"},{"title":"Enroll a voice","api":"POST /flam-voice-svc/api/v1/public/voices/{id}/enroll","href":"/voice-api/enroll-voice"},{"title":"Get a job","api":"GET /flam-voice-svc/api/v1/public/jobs/{id}","href":"/voice-api/get-job"},{"title":"Update a voice","api":"PATCH /flam-voice-svc/api/v1/public/voices/{id}","href":"/voice-api/update-voice"},{"title":"Delete a voice","api":"DELETE /flam-voice-svc/api/v1/public/voices/{id}","href":"/voice-api/delete-voice"}]},{"group":"Speech","icon":"waveform","pages":[{"title":"Synthesize speech","description":"Turn text into a single audio file using a cloned voice.","api":"POST /flam-voice-svc/api/v1/public/voices/{id}/speak","href":"/voice-api/synthesize-speech"},{"title":"Stream speech (SSE)","api":"POST /flam-voice-svc/api/v1/public/voices/{id}/stream","href":"/voice-api/stream-speech"},{"title":"Realtime (WebSocket)","description":"Bidirectional, low-latency synthesis over a WebSocket connection.","href":"/voice-api/realtime-websocket"},{"title":"Create a direct realtime session","api":"POST /flam-voice-svc/api/v1/public/realtime/sessions","href":"/voice-api/realtime-sessions"}]},{"group":"Compatibility","icon":"plug","pages":[{"title":"OpenAI-compatible API","href":"/voice-api/openai-compatible"}]},{"group":"Reference","icon":"book","pages":[{"title":"The Voice object","href":"/voice-api/voice-object"},{"title":"Synthesize parameters","href":"/voice-api/synthesize-parameters"},{"title":"Errors \u0026 response envelope","href":"/voice-api/errors"}]}]},{"tab":"Changelog","pages":[{"title":"Changelog","href":"/changelog/api"}]}]},"basePath":"","title":"Stream speech (SSE) - Finesse","deploymentId":"dpl_EwfxjeKENdVkfzdag8rM6mKzcTUJ","buildId":"dpl_EwfxjeKENdVkfzdag8rM6mKzcTUJ","dynamics":["c2aa737661","2b790eda92","b0f84f53ff"],"chunks":["OpenApiReferenceProvider-B8kPdtB2.js","snippetPresets-C-p1aFQ1.js","utils-B9NnUZSZ.js","style-to-object-BY3JEAdk.js","utils-DFxl7cW2.js","v4-DIgz8zy6.js","addTypeLabelsToSchema-bSr9h7OB.js","conditional-requirements-CFM0id0Q.js","cloneDeep-Bw4Gcy_r.js","_Uint8Array-C68x8Gny.js","isObject-FP1Yky1u.js","ApiExamples-BXsp8PHs.js","usePlaygroundInputsStore-BlAOLmIF.js","shallow-C2F02mqa.js","isEqual-C8iG4q2G.js","CodeSnippets-45lHR04X.js","CodeSnippet-6Cemznl-.js","use-playground-group-access-Cyy8SXp5.js","Page-CeZ_ZB5X.js","api-description-markdown-DiOdv5rp.js","DynamicMarkdown-B_9ywLDq.js","SectionHeading-Cc2r-uqU.js","MethodPill-Df3Tcu4c.js","getPastedJson-B3vrV0wE.js","Check2Icon-YQhSFafd.js","axios-CsQoIw0U.js"]}