import asyncioimport websocketsimport osfrom dotenv import load_dotenvload_dotenv()api_key = os.environ.get('RIME_API_KEY')if not api_key: raise ValueError("RIME_API_KEY environment variable is not set")FILE_PATH = "coda_ws.wav"class RimeClient: def __init__(self, speaker, api_key): self.url = f"wss://users-ws.rime.ai/ws?speaker={speaker}&modelId=coda&audioFormat=wav" self.auth_headers = { "Authorization": f"Bearer {api_key}" } self.audio_data = b'' async def send_tokens(self, websocket, message): for token in message: await websocket.send(token) async def handle_audio(self, websocket): while True: try: audio = await websocket.recv() except websockets.exceptions.ConnectionClosedOK: break self.audio_data += audio async def run(self, message): async with websockets.connect(self.url, additional_headers=self.auth_headers) as websocket: await asyncio.gather( self.send_tokens(websocket, message), self.handle_audio(websocket), ) def save_audio(self, file_path): with open(file_path, 'wb') as f: f.write(self.audio_data)message = [ "This ", "is ", "a ", "test ", "of ", "the ", "coda ", "model ", "using ", "websockets ", "and ", "python.", "<EOS>",]client = RimeClient("astra", api_key=api_key)asyncio.run(client.run(message))print(f"Saving audio to {FILE_PATH}")client.save_audio(FILE_PATH)
Legacy WebSockets
Legacy WebSocket (/ws)
Coda plain-text WebSocket (/ws): send text, receive raw audio bytes.
import asyncioimport websocketsimport osfrom dotenv import load_dotenvload_dotenv()api_key = os.environ.get('RIME_API_KEY')if not api_key: raise ValueError("RIME_API_KEY environment variable is not set")FILE_PATH = "coda_ws.wav"class RimeClient: def __init__(self, speaker, api_key): self.url = f"wss://users-ws.rime.ai/ws?speaker={speaker}&modelId=coda&audioFormat=wav" self.auth_headers = { "Authorization": f"Bearer {api_key}" } self.audio_data = b'' async def send_tokens(self, websocket, message): for token in message: await websocket.send(token) async def handle_audio(self, websocket): while True: try: audio = await websocket.recv() except websockets.exceptions.ConnectionClosedOK: break self.audio_data += audio async def run(self, message): async with websockets.connect(self.url, additional_headers=self.auth_headers) as websocket: await asyncio.gather( self.send_tokens(websocket, message), self.handle_audio(websocket), ) def save_audio(self, file_path): with open(file_path, 'wb') as f: f.write(self.audio_data)message = [ "This ", "is ", "a ", "test ", "of ", "the ", "coda ", "model ", "using ", "websockets ", "and ", "python.", "<EOS>",]client = RimeClient("astra", api_key=api_key)asyncio.run(client.run(message))print(f"Saving audio to {FILE_PATH}")client.save_audio(FILE_PATH)
The Rime API authenticates every request with a bearer token in the Authorization header: Authorization: Bearer YOUR_API_KEY. See API authentication for how to create a key.
This page describes the legacy /ws endpoint, which keeps working for existing integrations. For a new Coda integration, use Coda WebSocket v1.
Include modelId=coda in the connection query. If you omit it, the server routes the request to Mist v3 and speakers outside the Mist v3 catalog can fail with Speaker not found.
Overview
This endpoint accepts bare text and responds with raw audio bytes in the selected format. All synthesis arguments are query parameters on the connection URL.
Messages
Send
Send bare text, not JSON.
This will be converted to audio via websockets
Receive
The server sends raw audio bytes in the audioFormat set on the connection. With pcm, a message can end mid-sample, so keep whole samples.
The text you’d like spoken. Character limit per request is 1,000 via the API and in the dashboard UI.
string
default:"mistv3"
Set this to coda. It is not strictly required, but if you omit it the server defaults to the Mist v3 backend, and speakers outside the Mist v3 catalog fail with a “Speaker not found” error.
string
One of wav, mp3 (or mpeg), ogg (Opus in OGG), webm (Opus in WebM), pcm (or l16), or mulaw (or pcmu). Unrecognized values fall back to wav.
string
default:"eng"
If provided, the language must match the language spoken by the provided speaker. Both the 2-letter ISO 639-1 and the 3-letter ISO 639-2/3 form are accepted:
The sampling rate in Hz. Any positive integer is accepted, and values above the model’s native rate are upsampled. Common choices are 8000 (telephony), 16000, 22050, 24000, and 44100.
float
default:"1.0"
The time scaling factor. Accepted range is 0.4 to 2.5. Values outside this range are clamped without an error. Values above 1.0 slow the audio down, and values below 1.0 speed it up.
string
default:"bySentence"
Controls how text is segmented for synthesis. Available options:
“immediate” - Synthesizes text immediately without waiting for complete sentences
“never” - Never segments the text, waits for explicit flush or EOS
“bySentence” (default) - Waits for complete sentences before synthesis
Note: For backward compatibility, setting immediate=true in query params is equivalent to segment=immediate. If a null value is provided, it will default to “bySentence”.
import asyncioimport websocketsimport osfrom dotenv import load_dotenvload_dotenv()api_key = os.environ.get('RIME_API_KEY')if not api_key: raise ValueError("RIME_API_KEY environment variable is not set")FILE_PATH = "coda_ws.wav"class RimeClient: def __init__(self, speaker, api_key): self.url = f"wss://users-ws.rime.ai/ws?speaker={speaker}&modelId=coda&audioFormat=wav" self.auth_headers = { "Authorization": f"Bearer {api_key}" } self.audio_data = b'' async def send_tokens(self, websocket, message): for token in message: await websocket.send(token) async def handle_audio(self, websocket): while True: try: audio = await websocket.recv() except websockets.exceptions.ConnectionClosedOK: break self.audio_data += audio async def run(self, message): async with websockets.connect(self.url, additional_headers=self.auth_headers) as websocket: await asyncio.gather( self.send_tokens(websocket, message), self.handle_audio(websocket), ) def save_audio(self, file_path): with open(file_path, 'wb') as f: f.write(self.audio_data)message = [ "This ", "is ", "a ", "test ", "of ", "the ", "coda ", "model ", "using ", "websockets ", "and ", "python.", "<EOS>",]client = RimeClient("astra", api_key=api_key)asyncio.run(client.run(message))print(f"Saving audio to {FILE_PATH}")client.save_audio(FILE_PATH)
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Rime Docs","colors":{"primary":"#1DADC7","light":"#4FC3D9","dark":"#147D91"},"logo":{"light":"https://mintcdn.com/rimelabs/qBNCx7nLDEv-FtZq/logo/light.png?fit=max\u0026auto=format\u0026n=qBNCx7nLDEv-FtZq\u0026q=85\u0026s=b74ee12f1a1075334db19359152c2f8a","dark":"https://mintcdn.com/rimelabs/qBNCx7nLDEv-FtZq/logo/dark.png?fit=max\u0026auto=format\u0026n=qBNCx7nLDEv-FtZq\u0026q=85\u0026s=d13aea3ecd100ed7ca31c828e93b123f","href":"/"},"favicon":"https://mintcdn.com/rimelabs/Z6D4LmkrIeBeHoml/rime-social-logo.png?fit=max\u0026auto=format\u0026n=Z6D4LmkrIeBeHoml\u0026q=85\u0026s=41aa58d6143a74b8c11b8d9713e77344","api":{"playground":{"display":"none"}},"background":{"color":{"light":"#F0E9DD","dark":"#2E2A25"}},"navbar":{"links":[{"href":"https://www.rimestat.us","label":"Status"}],"primary":{"type":"button","label":"Dashboard","href":"https://app.rime.ai"}},"footer":{"links":[{"header":"Rime","items":[{"label":"Status","href":"https://www.rimestat.us"},{"label":"Dashboard","href":"https://app.rime.ai"}]}]},"integrations":{"posthog":{"apiKey":"phc_BzP0KaTCqAgNZjeq3B4EjaQPRKzthbvQZxTXBh6K7Yp","apiHost":"https://n.rime.ai","sessionRecording":true}},"errors":{"404":{"redirect":false,"title":"We can't find that page.","description":"This page does not exist or has moved.\n\n**[API reference](/docs/api-reference)**: every TTS, WebSocket, and utility endpoint\n\n**[WebSocket overview](/docs/websockets)**: endpoint and transport choices\n\n**[Five-minute quickstart](/docs/quickstart-five-minute)**: generate an audio clip\n\n**[Models](/docs/models)**: Coda and Mist v3\n\n**[Voices](/docs/voices)**: the current voice catalog\n\n**[API authentication](/docs/api-authentication)**: create and use API keys\n\n**[Changelog](/docs/changelog)**: recent changes and release notes\n\nThe machine-readable index is available at [/llms.txt](/llms.txt).\n\n[Report a broken link](mailto:support@rime.ai)."}},"contextual":{"options":["copy","view","chatgpt","claude","cursor","vscode","mcp","add-mcp"],"display":"header"},"styling":{"latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"rimelabs","hasAudioNarration":false,"actualSubdomain":"rimelabs","customDomains":["docs.rime.ai"],"gitSource":{"type":"github","owner":"rimelabs","repo":"rime","deployBranch":"main","contentDirectory":"web/docs","isPrivate":true,"mountPath":"","label":""},"entitlements":{"AI_CHAT":{"status":"ENABLED"},"WEB_MCP":{"status":"ENABLED"},"NARRATION":{"status":"ENABLED"}},"buildId":"6af90bdad49d28f986f38c18","clientVersion":"0.0.4160","searchFilterCounts":[{"language":"default","tag":"Documentation","count":93},{"language":"default","tag":"Build with Rime","count":75},{"language":"default","tag":"Text-to-speech","count":49},{"language":"default","tag":"API Reference","count":22},{"language":"default","tag":"Customizing speech","count":21},{"language":"default","tag":"Prism","count":21},{"language":"default","tag":"Integrations","count":12},{"language":"default","tag":"MCP Server","count":12},{"language":"default","tag":"CLI Reference","count":10},{"language":"default","tag":"Pronunciation","count":10}]},"assistantConfig":{},"basePath":"","hasChatPermissions":true,"hasWebMcpPermissions":true,"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":"workos-onboarding","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":"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":"assistant-v5","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":"workos-sso-scim","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":"workos-signup","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":"workos-enabled","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":"sso-setup-deadline-banner","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":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[{"filePath":"style.css","content":".chat-assistant-floating-input,chat-assistant-floating-input{display:none!important}a[href=\"/\"]:has(>.nav-logo){display:inline-flex;align-items:center;gap:0.5rem}a[href=\"/\"]:has(>.nav-logo)::after{color:rgb(24 24 27);content:\"docs\" / \"\";font-size:1rem;font-weight:600;letter-spacing:-0.025em;line-height:1}html.dark a[href=\"/\"]:has(>.nav-logo)::after{color:rgb(244 244 245)}html[data-current-path=\"/\"] .nav-tabs-item[data-active=\"true\"]{color:rgb(75 85 99);text-shadow:none}html.dark[data-current-path=\"/\"] .nav-tabs-item[data-active=\"true\"]{color:rgb(156 163 175)}html[data-current-path=\"/\"] .nav-tabs-item[data-active=\"true\"]>div{background-color:transparent!important}#topbar-cta-button a>span.absolute{background-color:#24211d!important}#topbar-cta-button a span,#topbar-cta-button a svg{color:#f8f3ea!important}html.dark #topbar-cta-button a>span.absolute{background-color:#f8f3ea!important}html.dark #topbar-cta-button a span,html.dark #topbar-cta-button a svg{color:#24211d!important}"}],"page":{"pagePath":"api-reference/coda/websockets","slug":"/api-reference/coda/websockets","pageMetadata":{"og:title":"Coda WebSockets API | Real-Time TTS | Rime Docs","title":"Legacy WebSocket (/ws)","sidebarTitle":"Legacy /ws","description":"Coda plain-text WebSocket (/ws): send text, receive raw audio bytes.","api":"GET wss://users-ws.rime.ai/ws","authMethod":"bearer","href":"/api-reference/coda/websockets"},"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: \"Coda plain-text WebSocket (/ws): send text, receive raw audio bytes.\"\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`,li:`li`,p:`p`,pre:`pre`,span:`span`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Note,ParamField,Table,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Note)_missingMdxReference(`Note`,true);if(!ParamField)_missingMdxReference(`ParamField`,true);if(!Table)_missingMdxReference(`Table`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`The Rime API authenticates every request with a bearer token in the `,_jsx(_components.code,{children:`Authorization`}),` header: `,_jsx(_components.code,{children:`Authorization: Bearer YOUR_API_KEY`}),`. See `,_jsx(_components.a,{href:`/docs/api-authentication`,children:`API authentication`}),` for how to create a key.`]}),`\n`,_jsx(Note,{children:_jsxs(_components.p,{children:[`This page describes the legacy `,_jsx(_components.code,{children:`/ws`}),` endpoint, which keeps working for existing integrations. For a new Coda integration, use `,_jsx(_components.a,{href:`/api-reference/coda/websocket-v1`,children:`Coda WebSocket v1`}),`.`]})}),`\n`,_jsxs(Warning,{children:[`Include `,_jsx(_components.code,{children:`modelId=coda`}),` in the connection query. If you omit it, the server routes the request to Mist v3 and speakers outside the Mist v3 catalog can fail with `,_jsx(_components.code,{children:`Speaker not found`}),`.`]}),`\n`,_jsx(Heading,{level:`2`,id:`overview`,children:`Overview`}),`\n`,_jsx(_components.p,{children:`This endpoint accepts bare text and responds with raw audio bytes in the selected format. All synthesis arguments are query parameters on the connection URL.`}),`\n`,_jsx(Heading,{level:`2`,id:`messages`,children:`Messages`}),`\n`,_jsx(Heading,{level:`3`,id:`send`,children:`Send`}),`\n`,_jsx(_components.p,{children:`Send bare text, not JSON.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`2`,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:`2`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`This will be converted to audio via websockets`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsx(Heading,{level:`3`,id:`receive`,children:`Receive`}),`\n`,_jsxs(_components.p,{children:[`The server sends raw audio bytes in the `,_jsx(_components.code,{children:`audioFormat`}),` set on the connection. With `,_jsx(_components.code,{children:`pcm`}),`, a message can end mid-sample, so `,_jsx(_components.a,{href:`/docs/streaming#keep-whole-samples-in-raw-pcm`,children:`keep whole samples`}),`.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`4`,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:`4`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`\u003cFF>^@^@^@9LAME3.100^AP^@^@^@^@^@^@^@^@^T\u003cA0>$^D>\"^@^@\u003cA0>^@^@\u003cA8>\u003cC0>\u003cBA>\u003c9D>G^N^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`^@^@^@^@^@^@^@^@^@^@`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsx(Heading,{level:`2`,id:`commands`,children:`Commands`}),`\n`,_jsx(_components.p,{children:`Send these strings as a whole message to act on the server’s text buffer.`}),`\n`,_jsx(Heading,{level:`3`,id:`\u003cclear>`,children:_jsx(_components.code,{children:`\u003cCLEAR>`})}),`\n`,_jsx(_components.p,{children:`Discards the buffered text. Use it when the user interrupts.`}),`\n`,_jsx(Heading,{level:`3`,id:`\u003cflush>`,children:_jsx(_components.code,{children:`\u003cFLUSH>`})}),`\n`,_jsx(_components.p,{children:`Synthesizes whatever text is buffered and sends the audio.`}),`\n`,_jsx(Heading,{level:`3`,id:`\u003ceos>`,children:_jsx(_components.code,{children:`\u003cEOS>`})}),`\n`,_jsx(_components.p,{children:`Synthesizes whatever text is buffered, sends the audio, then closes the connection.`}),`\n`,_jsx(Heading,{level:`2`,id:`variable-parameters`,children:`Variable parameters`}),`\n`,_jsx(ParamField,{body:`speaker`,type:`string`,required:true,id:`param-speaker`,children:_jsxs(_components.p,{children:[`Must be a `,_jsx(_components.code,{children:`coda`}),` voice from the `,_jsx(_components.a,{href:`/docs/voices`,children:`Rime voice catalog`}),`.`]})}),`\n`,_jsx(ParamField,{body:`text`,type:`string`,required:true,id:`param-text`,children:_jsx(_components.p,{children:`The text you’d like spoken. Character limit per request is 1,000 via the API and in the dashboard UI.`})}),`\n`,_jsx(ParamField,{body:`modelId`,type:`string`,default:`mistv3`,id:`param-model-id`,children:_jsxs(_components.p,{children:[`Set this to `,_jsx(_components.code,{children:`coda`}),`. It is not strictly required, but if you omit it the server defaults to the Mist v3 backend, and speakers outside the Mist v3 catalog fail with a “Speaker not found” error.`]})}),`\n`,_jsx(ParamField,{body:`audioFormat`,type:`string`,id:`param-audio-format`,children:_jsxs(_components.p,{children:[`One of `,_jsx(_components.code,{children:`wav`}),`, `,_jsx(_components.code,{children:`mp3`}),` (or `,_jsx(_components.code,{children:`mpeg`}),`), `,_jsx(_components.code,{children:`ogg`}),` (Opus in OGG), `,_jsx(_components.code,{children:`webm`}),` (Opus in WebM), `,_jsx(_components.code,{children:`pcm`}),` (or `,_jsx(_components.code,{children:`l16`}),`), or `,_jsx(_components.code,{children:`mulaw`}),` (or `,_jsx(_components.code,{children:`pcmu`}),`). Unrecognized values fall back to `,_jsx(_components.code,{children:`wav`}),`.`]})}),`\n`,_jsxs(ParamField,{body:`lang`,type:`string`,default:`eng`,id:`param-lang`,children:[_jsx(_components.p,{children:`If provided, the language must match the language spoken by the provided speaker. Both the 2-letter ISO 639-1 and the 3-letter ISO 639-2/3 form are accepted:`}),_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`639-1`}),_jsx(_components.th,{children:`639-2/3`}),_jsx(_components.th,{children:`Language`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`en`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`eng`})}),_jsx(_components.td,{children:`English`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`es`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`spa`})}),_jsx(_components.td,{children:`Spanish`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`fr`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`fra`})}),_jsx(_components.td,{children:`French`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`pt`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`por`})}),_jsx(_components.td,{children:`Portuguese`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`de`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`ger`})}),_jsx(_components.td,{children:`German`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`ja`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`jpn`})}),_jsx(_components.td,{children:`Japanese`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`ar`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`ara`})}),_jsx(_components.td,{children:`Arabic`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`hi`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`hin`})}),_jsx(_components.td,{children:`Hindi`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`it`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`ita`})}),_jsx(_components.td,{children:`Italian`})]})]})]}),_jsxs(_components.p,{children:[`See `,_jsx(_components.a,{href:`/docs/voices`,children:`the voices documentation`}),` for which speakers support each language.`]})]}),`\n`,_jsx(ParamField,{body:`samplingRate`,type:`int`,default:`24000`,id:`param-sampling-rate`,children:_jsx(_components.p,{children:`The sampling rate in Hz. Any positive integer is accepted, and values above the model’s native rate are upsampled. Common choices are 8000 (telephony), 16000, 22050, 24000, and 44100.`})}),`\n`,_jsx(ParamField,{body:`timeScaleFactor`,type:`float`,default:`1.0`,id:`param-time-scale-factor`,children:_jsx(_components.p,{children:`The time scaling factor. Accepted range is 0.4 to 2.5. Values outside this range are clamped without an error. Values above 1.0 slow the audio down, and values below 1.0 speed it up.`})}),`\n`,_jsxs(ParamField,{body:`segment`,type:`string`,default:`bySentence`,id:`param-segment`,children:[_jsx(_components.p,{children:`Controls how text is segmented for synthesis. Available options:`}),_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`“immediate” - Synthesizes text immediately without waiting for complete sentences`}),`\n`,_jsx(_components.li,{children:`“never” - Never segments the text, waits for explicit flush or EOS`}),`\n`,_jsx(_components.li,{children:`“bySentence” (default) - Waits for complete sentences before synthesis`}),`\n`]}),_jsxs(_components.p,{children:[`Note: For backward compatibility, setting `,_jsx(_components.code,{children:`immediate=true`}),` in query params is equivalent to `,_jsx(_components.code,{children:`segment=immediate`}),`. If a null value is provided, it will default to “bySentence”.`]})]})]})}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":{"og:title":"Coda WebSockets API | Real-Time TTS | Rime Docs","title":"Legacy WebSocket (/ws)","sidebarTitle":"Legacy /ws","description":"Coda plain-text WebSocket (/ws): send text, receive raw audio bytes.","api":"GET wss://users-ws.rime.ai/ws","authMethod":"bearer","href":"/api-reference/coda/websockets"}}},"mdxSourceWithNoJs":{"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`,li:`li`,p:`p`,pre:`pre`,span:`span`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Note,ParamField,RequestExample,Table,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Note)_missingMdxReference(`Note`,true);if(!ParamField)_missingMdxReference(`ParamField`,true);if(!RequestExample)_missingMdxReference(`RequestExample`,true);if(!Table)_missingMdxReference(`Table`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`The Rime API authenticates every request with a bearer token in the `,_jsx(_components.code,{children:`Authorization`}),` header: `,_jsx(_components.code,{children:`Authorization: Bearer YOUR_API_KEY`}),`. See `,_jsx(_components.a,{href:`/docs/api-authentication`,children:`API authentication`}),` for how to create a key.`]}),`\n`,_jsx(Note,{children:_jsxs(_components.p,{children:[`This page describes the legacy `,_jsx(_components.code,{children:`/ws`}),` endpoint, which keeps working for existing integrations. For a new Coda integration, use `,_jsx(_components.a,{href:`/api-reference/coda/websocket-v1`,children:`Coda WebSocket v1`}),`.`]})}),`\n`,_jsxs(Warning,{children:[`Include `,_jsx(_components.code,{children:`modelId=coda`}),` in the connection query. If you omit it, the server routes the request to Mist v3 and speakers outside the Mist v3 catalog can fail with `,_jsx(_components.code,{children:`Speaker not found`}),`.`]}),`\n`,_jsx(Heading,{level:`2`,id:`overview`,children:`Overview`}),`\n`,_jsx(_components.p,{children:`This endpoint accepts bare text and responds with raw audio bytes in the selected format. All synthesis arguments are query parameters on the connection URL.`}),`\n`,_jsx(Heading,{level:`2`,id:`messages`,children:`Messages`}),`\n`,_jsx(Heading,{level:`3`,id:`send`,children:`Send`}),`\n`,_jsx(_components.p,{children:`Send bare text, not JSON.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`2`,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:`2`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`This will be converted to audio via websockets`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsx(Heading,{level:`3`,id:`receive`,children:`Receive`}),`\n`,_jsxs(_components.p,{children:[`The server sends raw audio bytes in the `,_jsx(_components.code,{children:`audioFormat`}),` set on the connection. With `,_jsx(_components.code,{children:`pcm`}),`, a message can end mid-sample, so `,_jsx(_components.a,{href:`/docs/streaming#keep-whole-samples-in-raw-pcm`,children:`keep whole samples`}),`.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`4`,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:`4`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`\u003cFF>^@^@^@9LAME3.100^AP^@^@^@^@^@^@^@^@^T\u003cA0>$^D>\"^@^@\u003cA0>^@^@\u003cA8>\u003cC0>\u003cBA>\u003c9D>G^N^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`^@^@^@^@^@^@^@^@^@^@`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsx(Heading,{level:`2`,id:`commands`,children:`Commands`}),`\n`,_jsx(_components.p,{children:`Send these strings as a whole message to act on the server’s text buffer.`}),`\n`,_jsx(Heading,{level:`3`,id:`\u003cclear>`,children:_jsx(_components.code,{children:`\u003cCLEAR>`})}),`\n`,_jsx(_components.p,{children:`Discards the buffered text. Use it when the user interrupts.`}),`\n`,_jsx(Heading,{level:`3`,id:`\u003cflush>`,children:_jsx(_components.code,{children:`\u003cFLUSH>`})}),`\n`,_jsx(_components.p,{children:`Synthesizes whatever text is buffered and sends the audio.`}),`\n`,_jsx(Heading,{level:`3`,id:`\u003ceos>`,children:_jsx(_components.code,{children:`\u003cEOS>`})}),`\n`,_jsx(_components.p,{children:`Synthesizes whatever text is buffered, sends the audio, then closes the connection.`}),`\n`,_jsx(Heading,{level:`2`,id:`variable-parameters`,children:`Variable parameters`}),`\n`,_jsx(ParamField,{body:`speaker`,type:`string`,required:true,id:`param-speaker`,children:_jsxs(_components.p,{children:[`Must be a `,_jsx(_components.code,{children:`coda`}),` voice from the `,_jsx(_components.a,{href:`/docs/voices`,children:`Rime voice catalog`}),`.`]})}),`\n`,_jsx(ParamField,{body:`text`,type:`string`,required:true,id:`param-text`,children:_jsx(_components.p,{children:`The text you’d like spoken. Character limit per request is 1,000 via the API and in the dashboard UI.`})}),`\n`,_jsx(ParamField,{body:`modelId`,type:`string`,default:`mistv3`,id:`param-model-id`,children:_jsxs(_components.p,{children:[`Set this to `,_jsx(_components.code,{children:`coda`}),`. It is not strictly required, but if you omit it the server defaults to the Mist v3 backend, and speakers outside the Mist v3 catalog fail with a “Speaker not found” error.`]})}),`\n`,_jsx(ParamField,{body:`audioFormat`,type:`string`,id:`param-audio-format`,children:_jsxs(_components.p,{children:[`One of `,_jsx(_components.code,{children:`wav`}),`, `,_jsx(_components.code,{children:`mp3`}),` (or `,_jsx(_components.code,{children:`mpeg`}),`), `,_jsx(_components.code,{children:`ogg`}),` (Opus in OGG), `,_jsx(_components.code,{children:`webm`}),` (Opus in WebM), `,_jsx(_components.code,{children:`pcm`}),` (or `,_jsx(_components.code,{children:`l16`}),`), or `,_jsx(_components.code,{children:`mulaw`}),` (or `,_jsx(_components.code,{children:`pcmu`}),`). Unrecognized values fall back to `,_jsx(_components.code,{children:`wav`}),`.`]})}),`\n`,_jsxs(ParamField,{body:`lang`,type:`string`,default:`eng`,id:`param-lang`,children:[_jsx(_components.p,{children:`If provided, the language must match the language spoken by the provided speaker. Both the 2-letter ISO 639-1 and the 3-letter ISO 639-2/3 form are accepted:`}),_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`639-1`}),_jsx(_components.th,{children:`639-2/3`}),_jsx(_components.th,{children:`Language`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`en`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`eng`})}),_jsx(_components.td,{children:`English`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`es`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`spa`})}),_jsx(_components.td,{children:`Spanish`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`fr`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`fra`})}),_jsx(_components.td,{children:`French`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`pt`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`por`})}),_jsx(_components.td,{children:`Portuguese`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`de`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`ger`})}),_jsx(_components.td,{children:`German`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`ja`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`jpn`})}),_jsx(_components.td,{children:`Japanese`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`ar`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`ara`})}),_jsx(_components.td,{children:`Arabic`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`hi`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`hin`})}),_jsx(_components.td,{children:`Hindi`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`it`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`ita`})}),_jsx(_components.td,{children:`Italian`})]})]})]}),_jsxs(_components.p,{children:[`See `,_jsx(_components.a,{href:`/docs/voices`,children:`the voices documentation`}),` for which speakers support each language.`]})]}),`\n`,_jsx(ParamField,{body:`samplingRate`,type:`int`,default:`24000`,id:`param-sampling-rate`,children:_jsx(_components.p,{children:`The sampling rate in Hz. Any positive integer is accepted, and values above the model’s native rate are upsampled. Common choices are 8000 (telephony), 16000, 22050, 24000, and 44100.`})}),`\n`,_jsx(ParamField,{body:`timeScaleFactor`,type:`float`,default:`1.0`,id:`param-time-scale-factor`,children:_jsx(_components.p,{children:`The time scaling factor. Accepted range is 0.4 to 2.5. Values outside this range are clamped without an error. Values above 1.0 slow the audio down, and values below 1.0 speed it up.`})}),`\n`,_jsxs(ParamField,{body:`segment`,type:`string`,default:`bySentence`,id:`param-segment`,children:[_jsx(_components.p,{children:`Controls how text is segmented for synthesis. Available options:`}),_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`“immediate” - Synthesizes text immediately without waiting for complete sentences`}),`\n`,_jsx(_components.li,{children:`“never” - Never segments the text, waits for explicit flush or EOS`}),`\n`,_jsx(_components.li,{children:`“bySentence” (default) - Waits for complete sentences before synthesis`}),`\n`]}),_jsxs(_components.p,{children:[`Note: For backward compatibility, setting `,_jsx(_components.code,{children:`immediate=true`}),` in query params is equivalent to `,_jsx(_components.code,{children:`segment=immediate`}),`. If a null value is provided, it will default to “bySentence”.`]})]}),`\n`,_jsx(RequestExample,{children:_jsx(CodeBlock,{filename:`Python`,numberOfLines:`64`,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:`64`,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:` asyncio`})]}),`\n`,_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:` websockets`})]}),`\n`,_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`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` dotenv `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` load_dotenv`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`load_dotenv()`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`api_key `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` os.environ.get(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'RIME_API_KEY'`}),_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:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` not`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` api_key:`})]}),`\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:` ValueError`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"RIME_API_KEY environment variable is not set\"`}),_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:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`FILE_PATH`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"coda_ws.wav\"`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`class`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#4EC9B0`},children:` RimeClient`}),_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:` def`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` __init__`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`speaker`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`api_key`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.url `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"wss://users-ws.rime.ai/ws?speaker=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`speaker`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\u0026modelId=coda\u0026audioFormat=wav\"`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.auth_headers `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_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:` \"Authorization\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Bearer `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`api_key`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},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:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.audio_data `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` b`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`''`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` async`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` send_tokens`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`websocket`}),_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:`#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:` token `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` message:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` websocket.send(token)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` async`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` handle_audio`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`websocket`}),_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:`#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\":`#C586C0`},children:` try`}),_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:` audio `}),_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\":`#D4D4D4`},children:` websocket.recv()`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` except`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` websockets.exceptions.ConnectionClosedOK:`})]}),`\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:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.audio_data `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`+=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` audio`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` async`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` run`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`self`}),_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:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` async`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` websockets.connect(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.url, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`additional_headers`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.auth_headers) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` websocket:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` asyncio.gather(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.send_tokens(websocket, message),`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.handle_audio(websocket),`})]}),`\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:` def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` save_audio`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`file_path`}),_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:` with`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` open`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(file_path, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'wb'`}),_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:` f:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` f.write(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.audio_data)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`message `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_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:` \"This \"`}),_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:` \"is \"`}),_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:` \"a \"`}),_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:` \"test \"`}),_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:` \"of \"`}),_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:` \"the \"`}),_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:` \"coda \"`}),_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:` \"model \"`}),_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:` \"using \"`}),_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:` \"websockets \"`}),_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:` \"and \"`}),_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:` \"python.\"`}),_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:` \"\u003cEOS>\"`}),_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:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`client `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` RimeClient(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"astra\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`api_key`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`api_key)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`asyncio.run(client.run(message))`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Saving audio to `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`FILE_PATH`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},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:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`client.save_audio(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`FILE_PATH`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`]})})})})]})}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":{"og:title":"Coda WebSockets API | Real-Time TTS | Rime Docs","title":"Legacy WebSocket (/ws)","sidebarTitle":"Legacy /ws","description":"Coda plain-text WebSocket (/ws): send text, receive raw audio bytes.","api":"GET wss://users-ws.rime.ai/ws","authMethod":"bearer","href":"/api-reference/coda/websockets"}}}},"mdxExtracts":{"tableOfContents":[{"title":"Overview","slug":"overview","depth":2,"children":[]},{"title":"Messages","slug":"messages","depth":2,"children":[{"title":"Send","slug":"send","depth":3,"children":[]},{"title":"Receive","slug":"receive","depth":3,"children":[]}]},{"title":"Commands","slug":"commands","depth":2,"children":[{"title":"\u003cCLEAR>","slug":"\u003cclear>","depth":3,"children":[]},{"title":"\u003cFLUSH>","slug":"\u003cflush>","depth":3,"children":[]},{"title":"\u003cEOS>","slug":"\u003ceos>","depth":3,"children":[]}]},{"title":"Variable parameters","slug":"variable-parameters","depth":2,"children":[]}],"codeExamples":{"request":{"type":"RequestExample","children":[{"filename":"Python","html":"\u003cpre class=\"shiki shiki-themes github-light-default dark-plus\" style=\"background-color:#ffffff;--shiki-dark-bg:#0B0C0E;color:#1f2328;--shiki-dark:#D4D4D4\" language=\"python\">\u003ccode language=\"python\" numberOfLines=\"64\">\u003cspan class=\"line\">\u003cspan style=\"color:#CF222E;--shiki-dark:#C586C0\">import\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\"> asyncio\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CF222E;--shiki-dark:#C586C0\">import\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\"> websockets\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CF222E;--shiki-dark:#C586C0\">import\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\"> os\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CF222E;--shiki-dark:#C586C0\">from\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\"> dotenv \u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#C586C0\">import\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\"> load_dotenv\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">load_dotenv()\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">api_key \u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#D4D4D4\">=\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\"> os.environ.get(\u003c/span>\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\">'RIME_API_KEY'\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">)\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CF222E;--shiki-dark:#C586C0\">if\u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#569CD6\"> not\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\"> api_key:\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CF222E;--shiki-dark:#C586C0\"> raise\u003c/span>\u003cspan style=\"color:#0550AE;--shiki-dark:#4EC9B0\"> ValueError\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">(\u003c/span>\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\">\"RIME_API_KEY environment variable is not set\"\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">)\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#0550AE;--shiki-dark:#D4D4D4\">FILE_PATH\u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#D4D4D4\"> =\u003c/span>\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\"> \"coda_ws.wav\"\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CF222E;--shiki-dark:#569CD6\">class\u003c/span>\u003cspan style=\"color:#953800;--shiki-dark:#4EC9B0\"> RimeClient\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">:\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CF222E;--shiki-dark:#569CD6\"> def\u003c/span>\u003cspan style=\"color:#0550AE;--shiki-dark:#DCDCAA\"> __init__\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">(\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#9CDCFE\">self\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">, \u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#9CDCFE\">speaker\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">, \u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#9CDCFE\">api_key\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">):\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#0550AE;--shiki-dark:#569CD6\"> self\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">.url \u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#D4D4D4\">=\u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#569CD6\"> f\u003c/span>\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\">\"wss://users-ws.rime.ai/ws?speaker=\u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#569CD6\">{\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">speaker\u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#569CD6\">}\u003c/span>\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\">\u0026#x26;modelId=coda\u0026#x26;audioFormat=wav\"\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#0550AE;--shiki-dark:#569CD6\"> self\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">.auth_headers \u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#D4D4D4\">=\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\"> {\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\"> \"Authorization\"\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">: \u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#569CD6\">f\u003c/span>\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\">\"Bearer \u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#569CD6\">{\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">api_key\u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#569CD6\">}\u003c/span>\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\">\"\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\"> }\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#0550AE;--shiki-dark:#569CD6\"> self\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">.audio_data \u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#D4D4D4\">=\u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#569CD6\"> b\u003c/span>\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\">''\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CF222E;--shiki-dark:#569CD6\"> async\u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#569CD6\"> def\u003c/span>\u003cspan style=\"color:#8250DF;--shiki-dark:#DCDCAA\"> send_tokens\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">(\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#9CDCFE\">self\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">, \u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#9CDCFE\">websocket\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">, \u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#9CDCFE\">message\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">):\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CF222E;--shiki-dark:#C586C0\"> for\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\"> token \u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#C586C0\">in\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\"> message:\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CF222E;--shiki-dark:#C586C0\"> await\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\"> websocket.send(token)\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CF222E;--shiki-dark:#569CD6\"> async\u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#569CD6\"> def\u003c/span>\u003cspan style=\"color:#8250DF;--shiki-dark:#DCDCAA\"> handle_audio\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">(\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#9CDCFE\">self\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">, \u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#9CDCFE\">websocket\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">):\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CF222E;--shiki-dark:#C586C0\"> while\u003c/span>\u003cspan style=\"color:#0550AE;--shiki-dark:#569CD6\"> True\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">:\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CF222E;--shiki-dark:#C586C0\"> try\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">:\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\"> audio \u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#D4D4D4\">=\u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#C586C0\"> await\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\"> websocket.recv()\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CF222E;--shiki-dark:#C586C0\"> except\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\"> websockets.exceptions.ConnectionClosedOK:\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CF222E;--shiki-dark:#C586C0\"> break\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#0550AE;--shiki-dark:#569CD6\"> self\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">.audio_data \u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#D4D4D4\">+=\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\"> audio\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CF222E;--shiki-dark:#569CD6\"> async\u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#569CD6\"> def\u003c/span>\u003cspan style=\"color:#8250DF;--shiki-dark:#DCDCAA\"> run\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">(\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#9CDCFE\">self\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">, \u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#9CDCFE\">message\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">):\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CF222E;--shiki-dark:#C586C0\"> async\u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#C586C0\"> with\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\"> websockets.connect(\u003c/span>\u003cspan style=\"color:#0550AE;--shiki-dark:#569CD6\">self\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">.url, \u003c/span>\u003cspan style=\"color:#953800;--shiki-dark:#9CDCFE\">additional_headers\u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#D4D4D4\">=\u003c/span>\u003cspan style=\"color:#0550AE;--shiki-dark:#569CD6\">self\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">.auth_headers) \u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#C586C0\">as\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\"> websocket:\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CF222E;--shiki-dark:#C586C0\"> await\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\"> asyncio.gather(\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#0550AE;--shiki-dark:#569CD6\"> self\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">.send_tokens(websocket, message),\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#0550AE;--shiki-dark:#569CD6\"> self\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">.handle_audio(websocket),\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\"> )\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CF222E;--shiki-dark:#569CD6\"> def\u003c/span>\u003cspan style=\"color:#8250DF;--shiki-dark:#DCDCAA\"> save_audio\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">(\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#9CDCFE\">self\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">, \u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#9CDCFE\">file_path\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">):\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CF222E;--shiki-dark:#C586C0\"> with\u003c/span>\u003cspan style=\"color:#0550AE;--shiki-dark:#DCDCAA\"> open\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">(file_path, \u003c/span>\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\">'wb'\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">) \u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#C586C0\">as\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\"> f:\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\"> f.write(\u003c/span>\u003cspan style=\"color:#0550AE;--shiki-dark:#569CD6\">self\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">.audio_data)\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">message \u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#D4D4D4\">=\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\"> [\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\"> \"This \"\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">,\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\"> \"is \"\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">,\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\"> \"a \"\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">,\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\"> \"test \"\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">,\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\"> \"of \"\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">,\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\"> \"the \"\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">,\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\"> \"coda \"\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">,\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\"> \"model \"\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">,\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\"> \"using \"\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">,\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\"> \"websockets \"\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">,\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\"> \"and \"\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">,\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\"> \"python.\"\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">,\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\"> \"\u0026#x3C;EOS>\"\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">,\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">]\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">client \u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#D4D4D4\">=\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\"> RimeClient(\u003c/span>\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\">\"astra\"\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">, \u003c/span>\u003cspan style=\"color:#953800;--shiki-dark:#9CDCFE\">api_key\u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#D4D4D4\">=\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">api_key)\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">asyncio.run(client.run(message))\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#0550AE;--shiki-dark:#DCDCAA\">print\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">(\u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#569CD6\">f\u003c/span>\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\">\"Saving audio to \u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#569CD6\">{\u003c/span>\u003cspan style=\"color:#0550AE;--shiki-dark:#D4D4D4\">FILE_PATH\u003c/span>\u003cspan style=\"color:#CF222E;--shiki-dark:#569CD6\">}\u003c/span>\u003cspan style=\"color:#0A3069;--shiki-dark:#CE9178\">\"\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">)\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">client.save_audio(\u003c/span>\u003cspan style=\"color:#0550AE;--shiki-dark:#D4D4D4\">FILE_PATH\u003c/span>\u003cspan style=\"color:#1F2328;--shiki-dark:#D4D4D4\">)\u003c/span>\u003c/span>\n\u003c/code>\u003c/pre>"}],"attributes":[]}},"endpoint":{"title":"Legacy WebSocket (/ws)","path":"/ws","servers":[{"url":"wss://users-ws.rime.ai"}],"method":"get","request":{"security":[{"title":"Bearer Auth","parameters":{"header":{"Authorization":{"type":"http","scheme":"bearer","description":"Bearer authentication header of the form `Bearer \u003ctoken>`, where `\u003ctoken>` is your auth token."}},"query":{},"cookie":{}}}],"parameters":{"query":{},"header":{},"cookie":{},"path":{}},"body":{"application/json":{"schemaArray":[{"type":"object","properties":{"speaker":[{"type":"string","description":"Must be a `coda` voice from the Rime voice catalog .","required":true}],"text":[{"type":"string","description":"The text you’d like spoken. Character limit per request is 1,000 via the API and in the dashboard UI.","required":true}],"modelId":[{"type":"string","description":"Set this to `coda` . It is not strictly required, but if you omit it the server defaults to the Mist v3 backend, and speakers outside the Mist v3 catalog fail with a “Speaker not found” error."}],"audioFormat":[{"type":"string","description":"One of `wav` , `mp3` (or `mpeg` ), `ogg` (Opus in OGG), `webm` (Opus in WebM), `pcm` (or `l16` ), or `mulaw` (or `pcmu` ). Unrecognized values fall back to `wav` ."}],"lang":[{"type":"string","description":"If provided, the language must match the language spoken by the provided speaker. Both the 2-letter ISO 639-1 and the 3-letter ISO 639-2/3 form are accepted: 639-1 639-2/3 Language `en` `eng` English `es` `spa` Spanish `fr` `fra` French `pt` `por` Portuguese `de` `ger` German `ja` `jpn` Japanese `ar` `ara` Arabic `hi` `hin` Hindi `it` `ita` Italian See the voices documentation for which speakers support each language."}],"samplingRate":[{"type":"integer","description":"The sampling rate in Hz. Any positive integer is accepted, and values above the model’s native rate are upsampled. Common choices are 8000 (telephony), 16000, 22050, 24000, and 44100."}],"timeScaleFactor":[{"type":"number","description":"The time scaling factor. Accepted range is 0.4 to 2.5. Values outside this range are clamped without an error. Values above 1.0 slow the audio down, and values below 1.0 speed it up."}],"segment":[{"type":"string","description":"Controls how text is segmented for synthesis. Available options: “immediate” - Synthesizes text immediately without waiting for complete sentences “never” - Never segments the text, waits for explicit flush or EOS “bySentence” (default) - Waits for complete sentences before synthesis Note: For backward compatibility, setting `immediate=true` in query params is equivalent to `segment=immediate` . If a null value is provided, it will default to “bySentence”."}]}}],"examples":{"example":{"value":{"speaker":"\u003cstring>","text":"\u003cstring>","modelId":"\u003cstring>","audioFormat":"\u003cstring>","lang":"\u003cstring>","samplingRate":123,"timeScaleFactor":123,"segment":"\u003cstring>"}}}}}},"response":{},"deprecated":false}},"jsLinks":[],"subdomain":"rimelabs","siteName":"Rime Docs","title":"Coda WebSockets API | Real-Time TTS | Rime Docs","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-10-22T16:11:34.359Z","originalFileLocation":"api-reference/coda/websockets.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;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=\"system\"}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=\"Coda plain-text WebSocket (/ws): send text, receive raw audio bytes.\">\u003cmeta data-mint-head name=\"application-name\" content=\"Rime Docs\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/rimelabs/yDOD7F9UdOtEHeIJ/_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/rimelabs/yDOD7F9UdOtEHeIJ/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/rimelabs/yDOD7F9UdOtEHeIJ/_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/rimelabs/yDOD7F9UdOtEHeIJ/_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/rimelabs/yDOD7F9UdOtEHeIJ/_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/rimelabs/yDOD7F9UdOtEHeIJ/_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/rimelabs/yDOD7F9UdOtEHeIJ/_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/rimelabs/yDOD7F9UdOtEHeIJ/_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/rimelabs/yDOD7F9UdOtEHeIJ/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Coda WebSockets API | Real-Time TTS | Rime Docs\">\u003cmeta data-mint-head property=\"og:description\" content=\"Coda plain-text WebSocket (/ws): send text, receive raw audio bytes.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Rime Docs\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.rime.ai/api-reference/coda/websockets\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://rimelabs.mintlify.site/_mintlify/api/og/v2?division=Legacy+WebSockets\u0026amp;title=Legacy+WebSocket+%28%2Fws%29\u0026amp;description=Coda+plain-text+WebSocket+%28%2Fws%29%3A+send+text%2C+receive+raw+audio+bytes.\u0026amp;theme=219ecb54f4eb0df981d92f9e\u0026amp;signature=8e61f50535f93ce8a3108ff7575d9b7932ff8b2b9e067b8a8d6701d689e7159c\">\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=\"Coda WebSockets API | Real-Time TTS | Rime Docs\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Coda plain-text WebSocket (/ws): send text, receive raw audio bytes.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://rimelabs.mintlify.site/_mintlify/api/og/v2?division=Legacy+WebSockets\u0026amp;title=Legacy+WebSocket+%28%2Fws%29\u0026amp;description=Coda+plain-text+WebSocket+%28%2Fws%29%3A+send+text%2C+receive+raw+audio+bytes.\u0026amp;theme=219ecb54f4eb0df981d92f9e\u0026amp;signature=8e61f50535f93ce8a3108ff7575d9b7932ff8b2b9e067b8a8d6701d689e7159c\">\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/rimelabs/yDOD7F9UdOtEHeIJ/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Rime Docs\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#1DADC7\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.rime.ai/api-reference/coda/websockets\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/api-reference/coda/websockets.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.rime.ai/#organization\",\"name\":\"Rime Docs\",\"url\":\"https://docs.rime.ai\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/rimelabs/qBNCx7nLDEv-FtZq/logo/light.png?fit=max\u0026auto=format\u0026n=qBNCx7nLDEv-FtZq\u0026q=85\u0026s=b74ee12f1a1075334db19359152c2f8a\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.rime.ai#website\",\"name\":\"Rime Docs\",\"url\":\"https://docs.rime.ai\",\"publisher\":{\"@id\":\"https://docs.rime.ai/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.rime.ai/api-reference/coda/websockets#webpage\",\"url\":\"https://docs.rime.ai/api-reference/coda/websockets\",\"name\":\"Legacy WebSocket (/ws)\",\"description\":\"Coda plain-text WebSocket (/ws): send text, receive raw audio bytes.\",\"dateModified\":\"2026-10-22T16:11:34.359Z\",\"isPartOf\":{\"@id\":\"https://docs.rime.ai#website\"},\"breadcrumb\":{\"@id\":\"https://docs.rime.ai/api-reference/coda/websockets#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.rime.ai/api-reference/coda/websockets#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Coda API reference\",\"item\":\"https://docs.rime.ai/api-reference/coda/http\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Legacy WebSocket (/ws)\",\"item\":\"https://docs.rime.ai/api-reference/coda/websockets\"}]},{\"@type\":[\"TechArticle\",\"APIReference\"],\"@id\":\"https://docs.rime.ai/api-reference/coda/websockets#apireference\",\"headline\":\"Legacy WebSocket (/ws)\",\"name\":\"Legacy WebSocket (/ws)\",\"description\":\"Coda plain-text WebSocket (/ws): send text, receive raw audio bytes.\",\"url\":\"https://docs.rime.ai/api-reference/coda/websockets\",\"mainEntityOfPage\":{\"@id\":\"https://docs.rime.ai/api-reference/coda/websockets#webpage\"},\"dateModified\":\"2026-10-22T16:11:34.359Z\",\"publisher\":{\"@id\":\"https://docs.rime.ai/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.rime.ai#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Rime Docs\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"Rime Docs\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/api-reference/coda/websockets.md","siteName":"Rime Docs","nav":{"global":null,"tabs":[{"tab":"Home","hidden":true,"searchable":true,"pages":[{"title":"Home","href":""}]},{"tab":"Documentation","pages":[{"title":"Documentation","href":"/docs/introduction"}]},{"tab":"API Reference","groups":[{"group":"Overview","pages":[{"title":"API reference index","href":"/docs/api-reference"},{"title":"API cheat sheet","icon":"list-check","href":"/docs/api-cheat-sheet"}]},{"group":"Coda API reference","pages":[{"title":"Streaming HTTP","api":"POST https://coda.api.rime.ai/","href":"/api-reference/coda/http"},{"group":"WebSocket v1","pages":[{"title":"Coda WebSocket API","sidebarTitle":"API reference","href":"/api-reference/coda/websocket-v1"},{"title":"JSON quickstart","href":"/api-reference/coda/websocket-v1-json"},{"title":"Protobuf quickstart","href":"/api-reference/coda/websocket-v1-protobuf"},{"title":"LiveKit integration","description":"Use Coda WebSocket v1 as the speech for a LiveKit agent with the Rime plugin. The guide also covers plugin parameters, the stream lifecycle, and moving from /ws3.","href":"/api-reference/coda/websocket-v1-livekit"}]},{"group":"Legacy WebSockets","pages":[{"title":"Legacy WebSocket (/ws)","sidebarTitle":"Legacy /ws","api":"GET wss://users-ws.rime.ai/ws","href":"/api-reference/coda/websockets"},{"title":"Legacy JSON WebSocket (/ws3)","sidebarTitle":"Legacy /ws3 JSON","description":"Coda JSON WebSocket (/ws3): structured events with base64 audio chunks and word-level timestamps.","api":"GET wss://users-ws.rime.ai/ws3","href":"/api-reference/coda/websockets-json"}]}]},{"group":"Mist v3 API reference","pages":[{"title":"Streaming HTTP","api":"POST https://mist.api.rime.ai/","href":"/api-reference/mistv3/http"},{"group":"WebSocket v1","pages":[{"title":"Mist v3 WebSocket API","sidebarTitle":"API reference","href":"/api-reference/mistv3/websocket-v1"}]},{"group":"Legacy WebSockets","pages":[{"title":"Websockets","api":"GET wss://users-ws.rime.ai/ws","href":"/api-reference/mistv3/websockets"},{"title":"Websockets JSON","api":"GET wss://users-ws.rime.ai/ws3","href":"/api-reference/mistv3/websockets-json"}]}]},{"group":"Speech-to-text API reference","pages":[{"title":"Streaming WebSocket","href":"/api-reference/stt/websockets"},{"title":"gRPC","href":"/api-reference/stt/grpc"}]},{"group":"Prism API reference","pages":[{"title":"Prism WebSocket","href":"/api-reference/prism/websocket"},{"title":"Prism LiveKit plugin reference","sidebarTitle":"LiveKit plugin","icon":"video","href":"/api-reference/prism/livekit"}]},{"group":"API Metadata","pages":[{"title":"List All Voices","api":"GET https://users.rime.ai/data/voices/all-v2.json","href":"/api-reference/data/voices-v2"},{"title":"List Voice Details","api":"GET https://users.rime.ai/data/voices/voice_details.json","href":"/api-reference/data/voice-details"}]},{"group":"Other APIs","pages":[{"title":"Coverage","sidebarTitle":"Vocabulary Coverage","api":"POST https://users.rime.ai/oov","href":"/api-reference/other/oov"},{"title":"Phonemize","sidebarTitle":"Phonemize Audio","api":"POST https://optimize.rime.ai/phonemize","href":"/api-reference/other/phonemize"},{"title":"Text Normalization","api":"POST https://optimize.rime.ai/textnorm","href":"/api-reference/other/textnorm"}]}]},{"tab":"SDK Reference","pages":[{"title":"SDK Reference","href":"/api-reference/sdk/overview"}]},{"tab":"CLI Reference","pages":[{"title":"CLI Reference","href":"/cli-reference/overview"}]},{"tab":"MCP Server","pages":[{"title":"MCP Server","href":"/mcp-reference/overview"}]}]},"basePath":"","title":"Coda WebSockets API | Real-Time TTS | Rime Docs","buildId":"dpl_GRSyrvXT6FFTpZZTGz5iZPp3D2zE","deploymentId":"dpl_GRSyrvXT6FFTpZZTGz5iZPp3D2zE","dynamics":["c2aa737661","2b790eda92","b0f84f53ff"],"chunks":["OpenApiReferenceProvider-BFmjTMeT.js","utils-BWr-sjpP.js","cloneDeep-izs3Hzxb.js","_Uint8Array-BVIqJ90l.js","isObjectLike-C8vmzPEN.js","isArray-Dcu1dQ5t.js","utils-LafIDf0N.js","toString-BX-iyh8G.js","isSymbol-CSH9U2Gm.js","addUniqueKeysToSchema-MJNzuxek.js","snippetPresets-DPZEtUvW.js","style-to-object-BY3JEAdk.js","v4-DIgz8zy6.js","conditional-requirements-CFM0id0Q.js","ApiExamples-DQ2UhGIs.js","isEqual-BfaiBbcl.js","usePlaygroundInputsStore-DUUJTUkE.js","shallow-BTf5bw35.js","getApiPlaygroundDisplay-h2POYYOO.js","CodeSnippet-C4qEftRe.js","CodeSnippets-CsSrOqMC.js","Page-CWFqNdGh.js","getPastedJson-DU6W6y78.js","icon-2ZYNQ78y.js","MethodPill-BMXJzYMm.js","DuplicateIcon-DNjdEpYZ.js","createIcon-WdPVhKxl.js","DynamicMarkdown-Z_y464fM.js","SectionHeading-Bcrd8azU.js","axios-vUo_bRtp.js"]}