Avoid: Sending chunks too rapidly (< 20ms) or too slowly (> 200ms)
Consistency: Maintain regular intervals for predictable latency
// Good: Consistent 50ms intervalssetTimeout(sendChunk, 50);// Avoid: Variable or very short intervalssetTimeout(sendChunk, Math.random() * 10); // Too fast and inconsistent
Use case: Store in database, display as confirmed text
if (message.is_final) { // Store final transcript saveTranscript(message.full_transcript); // Update UI with confirmed text displayFinalTranscript(message.full_transcript);}
To properly close a session, send the end token and wait for the server to respond with is_last=true before closing the WebSocket connection:
function endTranscription(ws) { // Send end signal ws.send(JSON.stringify({ type: "end" })); // Wait for is_last=true response before closing ws.onmessage = (event) => { const message = JSON.parse(event.data); if (message.is_last === true) { ws.close(1000, "Transcription complete"); } };}
Do not close the WebSocket immediately after sending the end token. Always wait for the is_last=true response to ensure all audio has been processed and final transcripts are received.
Implement connection pooling for multiple sessions
Add rate limiting to prevent overwhelming the API
Log session IDs for debugging and support
Monitor transcription quality and latency metrics
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Waves","colors":{"primary":"#217D80","light":"#008080","dark":"#004D4D"},"logo":{"light":"https://mintcdn.com/own-c8c61ef7/OyDyIUQRfHl2dfUg/logo/logo_dark.png?fit=max\u0026auto=format\u0026n=OyDyIUQRfHl2dfUg\u0026q=85\u0026s=e8cbff613d2641b35a78860686605f3d","dark":"https://mintcdn.com/own-c8c61ef7/OyDyIUQRfHl2dfUg/logo/logo_light.png?fit=max\u0026auto=format\u0026n=OyDyIUQRfHl2dfUg\u0026q=85\u0026s=080693f4ba2d1003e04c19f1d1526c0c"},"favicon":"/logo/favi.svg","api":{"openapi":["openapi-spec/tts-api.yaml","openapi-spec/voices-api.yaml","openapi-spec/pronunciation-dictionaries-api.yaml","openapi-spec/asr-openapi.yaml","openapi-spec/pulse-stt-openapi.yaml"]},"navbar":{"links":[{"href":"mailto:support@smallest.ai","label":"Support"},{"href":"https://discord.gg/5evETqguJs","label":"Community"},{"href":"https://smallest.ai/blog","label":"Blog"},{"href":"https://smallest.ai?utm_source=documentation\u0026utm_medium=topButton","label":"Home"}],"primary":{"type":"button","label":"Platform","href":"https://atoms.smallest.ai/dashboard?utm_source=documentation\u0026utm_medium=topButton"}},"footer":{"socials":{"twitter":"https://twitter.com/smallest_AI","linkedin":"https://www.linkedin.com/company/smallest"}},"integrations":{"gtm":{"tagId":"GTM-T9S9PBGF"},"mixpanel":{"projectToken":"005a880f58fbad433a357b2bfc7f4d54"},"posthog":{"apiKey":"phc_wnu3OcaTwuHlc3N7PQy9JSH97Pn18KFbPtCBWYTVvta"}},"styling":{"latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"own-c8c61ef7","hasAudioNarration":false,"actualSubdomain":"own-c8c61ef7","customDomains":[],"gitSource":{"type":"github","owner":"aditya290390","repo":"docs","deployBranch":"main","contentDirectory":"","isPrivate":false,"mountPath":"","label":""},"entitlements":{},"buildId":"6ae9421852cb1006ce9c7dcc:success","clientVersion":"0.0.4102","searchFilterCounts":[{"language":"default","tag":"Documentation","count":90},{"language":"default","tag":"API Reference","count":43},{"language":"default","tag":"Self Host","count":37},{"language":"default","tag":"Speech to Text","count":30},{"language":"default","tag":"Voice Cloning","count":24},{"language":"default","tag":"Text to Speech","count":18},{"language":"default","tag":"Getting Started","count":16},{"language":"default","tag":"Kubernetes Setup","count":16},{"language":"default","tag":"Docker Setup","count":14},{"language":"default","tag":"Prerequisites","count":12}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","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},{"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}],"googleFontsInlined":false},"customCss":[{"filePath":"style.css","content":"#banner{font-size:16px;line-height:1.5;text-align:center;background-color:#217D80}.nav-logo,.nav-logo img{height:auto!important;max-height:40px!important;width:auto!important}#sidebar-content{scrollbar-width:thin!important;scrollbar-color:gray transparent!important}"}],"page":{"pagePath":"v4.0.0/content/speech-to-text/realtime/best-practices","slug":"/v4.0.0/content/speech-to-text/realtime/best-practices","pageMetadata":{"title":"Best Practices","description":"Optimize your real-time WebSocket transcription for low latency and high accuracy","href":"/v4.0.0/content/speech-to-text/realtime/best-practices","hidden":false},"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: \"Optimize your real-time WebSocket transcription for low latency and high accuracy\"\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={code:`code`,li:`li`,ol:`ol`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsx(Heading,{level:`1`,id:`real-time-streaming-best-practices`,children:`Real-time streaming best practices`}),`\n`,_jsx(_components.p,{children:`Follow these recommendations to keep Pulse STT latencies low while preserving transcript fidelity in real-time scenarios.`}),`\n`,_jsx(Heading,{level:`2`,id:`chunk-size-and-streaming-rate`,children:`Chunk Size and Streaming Rate`}),`\n`,_jsx(Heading,{level:`3`,id:`recommended-chunk-size`,children:`Recommended Chunk Size`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Optimal`}),`: 4096 bytes per chunk`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Range`}),`: 1024 to 8192 bytes`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Consistency`}),`: Maintain consistent chunk sizes when possible`]}),`\n`]}),`\n`,_jsx(_components.p,{children:`Sending audio in 4096-byte chunks provides the best balance between latency and processing efficiency.`}),`\n`,_jsx(Heading,{level:`3`,id:`streaming-rate`,children:`Streaming Rate`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Interval`}),`: Send chunks every 50-100ms`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Avoid`}),`: Sending chunks too rapidly (\u003c 20ms) or too slowly (> 200ms)`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Consistency`}),`: Maintain regular intervals for predictable latency`]}),`\n`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`5`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`5`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Good: Consistent 50ms intervals`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`setTimeout`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`sendChunk`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`50`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Avoid: Variable or very short intervals`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`setTimeout`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`sendChunk`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`Math`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`random`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`() `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`*`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 10`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`); `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Too fast and inconsistent`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`handling-partial-vs-final-transcripts`,children:`Handling Partial vs Final Transcripts`}),`\n`,_jsx(_components.p,{children:`The API sends two types of transcripts:`}),`\n`,_jsxs(Heading,{level:`3`,id:`partial-transcripts-is_final-false`,children:[`Partial Transcripts (`,_jsx(_components.code,{children:`is_final: false`}),`)`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Purpose`}),`: Show interim results for immediate user feedback`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Behavior`}),`: May change as more audio is processed`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Use case`}),`: Display “live” transcription as the user speaks`]}),`\n`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`4`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`4`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`message`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`is_final`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // Show partial transcript with visual indicator (e.g., grayed out)`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` displayPartialTranscript`}),_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:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`transcript`}),_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`]})})}),`\n`,_jsxs(Heading,{level:`3`,id:`final-transcripts-is_final-true`,children:[`Final Transcripts (`,_jsx(_components.code,{children:`is_final: true`}),`)`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Purpose`}),`: Confirmed transcription for a segment`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Behavior`}),`: Stable and won’t change`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Use case`}),`: Store in database, display as confirmed text`]}),`\n`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`6`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`6`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`message`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`is_final`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // Store final transcript`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` saveTranscript`}),_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:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`full_transcript`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // Update UI with confirmed text`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` displayFinalTranscript`}),_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:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`full_transcript`}),_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`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`audio-preprocessing`,children:`Audio Preprocessing`}),`\n`,_jsx(Heading,{level:`3`,id:`before-streaming`,children:`Before Streaming`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Convert to correct format`}),`: Ensure audio matches the `,_jsx(_components.code,{children:`encoding`}),` parameter (linear16, linear32, alaw, mulaw, opus, ogg_opus)`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Set sample rate`}),`: Match the `,_jsx(_components.code,{children:`sample_rate`}),` parameter in your WebSocket URL`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Mono channel`}),`: Downmix stereo/multi-channel to mono`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Normalize levels`}),`: Prevent clipping and ensure consistent volume`]}),`\n`]}),`\n`,_jsx(Heading,{level:`3`,id:`example-preprocessing`,children:`Example Preprocessing`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`25`,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:`25`,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:` numpy `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` np`})]}),`\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:` soundfile `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sf`})]}),`\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:` preprocess_audio`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`input_path`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`target_sample_rate`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`16000`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"\"\"Preprocess audio for WebSocket streaming\"\"\"`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` audio, sample_rate `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sf.read(input_path)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` `})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # Convert to mono`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` len`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(audio.shape) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`>`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` audio `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` np.mean(audio, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`axis`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` `})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # Resample if needed`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sample_rate `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` target_sample_rate:`})]}),`\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:` scipy `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` signal`})]}),`\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:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` signal.resample(audio, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`int`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`len`}),_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:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` target_sample_rate `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`/`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sample_rate))`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` `})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # Normalize to prevent clipping`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` max_val `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` np.abs(audio).max()`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` max_val `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`>`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\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:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` audio `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`/`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` max_val `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`*`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 0.95`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` `})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # Convert to 16-bit PCM`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` audio_int16 `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},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:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 32767`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`).astype(np.int16)`})]}),`\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:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` audio_int16, target_sample_rate`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`error-handling-and-reconnection`,children:`Error Handling and Reconnection`}),`\n`,_jsx(Heading,{level:`3`,id:`connection-errors`,children:`Connection Errors`}),`\n`,_jsx(_components.p,{children:`Implement robust error handling for network issues:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`25`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`25`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`let`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` reconnectAttempts`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` maxReconnectAttempts`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 5`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`function`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` connect`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`() {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` ws`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` WebSocket`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`url`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`toString`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`());`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` `})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` ws`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`onerror`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`=>`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"WebSocket error:\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` };`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` `})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` ws`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`onclose`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`event`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`=>`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`event`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`code`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` !==`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1000`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` \u0026\u0026`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` reconnectAttempts`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` \u003c`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` maxReconnectAttempts`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` reconnectAttempts`}),_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:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` delay`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` Math`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`min`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1000`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` *`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` Math`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`pow`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`2`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`reconnectAttempts`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`), `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`30000`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`Reconnecting in \"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`delay`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"ms...`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` setTimeout`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`connect`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`delay`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` };`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` `})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` ws`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`onopen`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` () `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`=>`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` reconnectAttempts`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`; `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Reset on successful connection`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` };`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` `})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` ws`}),_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`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`handling-connection-drops`,children:`Handling Connection Drops`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Detect drops`}),`: Monitor connection state and implement heartbeat/ping`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Buffer audio`}),`: Store audio chunks during disconnection`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Resume streaming`}),`: Continue from where you left off after reconnection`]}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`session-management`,children:`Session Management`}),`\n`,_jsx(Heading,{level:`3`,id:`session-lifecycle`,children:`Session Lifecycle`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Establish connection`}),`: Create WebSocket with proper authentication`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Stream audio`}),`: Send chunks at regular intervals`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Handle responses`}),`: Process partial and final transcripts`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`End session`}),`: Send `,_jsx(_components.code,{children:`{\"type\": \"end\"}`}),` when done`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Close connection`}),`: Gracefully close the WebSocket`]}),`\n`]}),`\n`,_jsx(Heading,{level:`3`,id:`graceful-shutdown`,children:`Graceful Shutdown`}),`\n`,_jsxs(_components.p,{children:[`To properly close a session, send the end token and wait for the server to respond with `,_jsx(_components.code,{children:`is_last=true`}),` before closing the WebSocket connection:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`12`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`12`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`function`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` endTranscription`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`ws`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // Send end signal`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` ws`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`send`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`JSON`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`stringify`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`type:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"end\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }));`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` `})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // Wait for is_last=true response before closing`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` ws`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`onmessage`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`event`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`=>`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` message`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` JSON`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`parse`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`event`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`data`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`message`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`is_last`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ===`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` ws`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`close`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1000`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Transcription complete\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` };`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`Do not close the WebSocket immediately after sending the end token. Always wait for the `,_jsx(_components.code,{children:`is_last=true`}),` response to ensure all audio has been processed and final transcripts are received.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`latency-optimization`,children:`Latency Optimization`}),`\n`,_jsx(Heading,{level:`3`,id:`minimize-processing-delays`,children:`Minimize Processing Delays`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Preprocess offline`}),`: Convert audio format before streaming`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Use optimal encoding`}),`: `,_jsx(_components.code,{children:`linear16`}),` at 16 kHz for best latency/quality balance`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Consistent chunking`}),`: Avoid variable chunk sizes that cause processing delays`]}),`\n`]}),`\n`,_jsx(Heading,{level:`3`,id:`network-optimization`,children:`Network Optimization`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Stable connection`}),`: Use reliable network connections`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Monitor bandwidth`}),`: Ensure sufficient bandwidth for audio streaming`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Reduce overhead`}),`: Minimize unnecessary data in WebSocket messages`]}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`quality-checklist`,children:`Quality Checklist`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Use 16 kHz mono linear16`}),` whenever possible for optimal latency`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Stream in 4096-byte chunks`}),` at 50-100ms intervals`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Handle partial transcripts`}),` for immediate user feedback`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Store final transcripts`}),` for accuracy and persistence`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Implement reconnection logic`}),` for production reliability`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Monitor session state`}),` to detect and handle errors gracefully`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Test with real audio`}),` to validate latency and accuracy`]}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`performance-tips`,children:`Performance Tips`}),`\n`,_jsx(Heading,{level:`3`,id:`for-low-latency`,children:`For Low Latency`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`Use `,_jsx(_components.code,{children:`linear16`}),` encoding at 16 kHz`]}),`\n`,_jsx(_components.li,{children:`Stream chunks every 50ms`}),`\n`,_jsx(_components.li,{children:`Process responses asynchronously`}),`\n`,_jsx(_components.li,{children:`Avoid blocking operations in message handlers`}),`\n`]}),`\n`,_jsx(Heading,{level:`3`,id:`for-high-accuracy`,children:`For High Accuracy`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`Use higher sample rates (44.1 kHz or 48 kHz) when latency allows`}),`\n`,_jsxs(_components.li,{children:[`Enable `,_jsx(_components.code,{children:`word_timestamps`}),` for precise timing`]}),`\n`,_jsxs(_components.li,{children:[`Wait for `,_jsx(_components.code,{children:`is_final=true`}),` before committing transcripts`]}),`\n`,_jsxs(_components.li,{children:[`Use `,_jsx(_components.code,{children:`full_transcript`}),` for complete session text`]}),`\n`]}),`\n`,_jsx(Heading,{level:`3`,id:`for-production`,children:`For Production`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`Implement connection pooling for multiple sessions`}),`\n`,_jsx(_components.li,{children:`Add rate limiting to prevent overwhelming the API`}),`\n`,_jsx(_components.li,{children:`Log session IDs for debugging and support`}),`\n`,_jsx(_components.li,{children:`Monitor transcription quality and latency metrics`}),`\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":{"title":"Best Practices","description":"Optimize your real-time WebSocket transcription for low latency and high accuracy","href":"/v4.0.0/content/speech-to-text/realtime/best-practices","hidden":false}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Real-time streaming best practices","slug":"real-time-streaming-best-practices","depth":1,"children":[]},{"title":"Chunk Size and Streaming Rate","slug":"chunk-size-and-streaming-rate","depth":2,"children":[{"title":"Recommended Chunk Size","slug":"recommended-chunk-size","depth":3,"children":[]},{"title":"Streaming Rate","slug":"streaming-rate","depth":3,"children":[]}]},{"title":"Handling Partial vs Final Transcripts","slug":"handling-partial-vs-final-transcripts","depth":2,"children":[{"title":"Partial Transcripts (is_final: false)","slug":"partial-transcripts-is_final-false","depth":3,"children":[]},{"title":"Final Transcripts (is_final: true)","slug":"final-transcripts-is_final-true","depth":3,"children":[]}]},{"title":"Audio Preprocessing","slug":"audio-preprocessing","depth":2,"children":[{"title":"Before Streaming","slug":"before-streaming","depth":3,"children":[]},{"title":"Example Preprocessing","slug":"example-preprocessing","depth":3,"children":[]}]},{"title":"Error Handling and Reconnection","slug":"error-handling-and-reconnection","depth":2,"children":[{"title":"Connection Errors","slug":"connection-errors","depth":3,"children":[]},{"title":"Handling Connection Drops","slug":"handling-connection-drops","depth":3,"children":[]}]},{"title":"Session Management","slug":"session-management","depth":2,"children":[{"title":"Session Lifecycle","slug":"session-lifecycle","depth":3,"children":[]},{"title":"Graceful Shutdown","slug":"graceful-shutdown","depth":3,"children":[]}]},{"title":"Latency Optimization","slug":"latency-optimization","depth":2,"children":[{"title":"Minimize Processing Delays","slug":"minimize-processing-delays","depth":3,"children":[]},{"title":"Network Optimization","slug":"network-optimization","depth":3,"children":[]}]},{"title":"Quality Checklist","slug":"quality-checklist","depth":2,"children":[]},{"title":"Performance Tips","slug":"performance-tips","depth":2,"children":[{"title":"For Low Latency","slug":"for-low-latency","depth":3,"children":[]},{"title":"For High Accuracy","slug":"for-high-accuracy","depth":3,"children":[]},{"title":"For Production","slug":"for-production","depth":3,"children":[]}]}],"codeExamples":{}},"jsLinks":[],"subdomain":"own-c8c61ef7","siteName":"Waves","title":"Best Practices - Waves","navMaps":{"firstHrefInVersion":{"v4.0.0":{"href":"/v4.0.0/content/speech-to-text/realtime/best-practices","matchLevel":0},"v3.0.1":{"href":"/v3.0.1/content/introduction/introduction","matchLevel":4},"v2.2.0":{"href":"/v2.2.0/content/introduction/introduction","matchLevel":4}},"firstHrefInLanguage":{}},"lastModified":"2026-01-27T12:44:47.440Z","originalFileLocation":"v4.0.0/content/speech-to-text/realtime/best-practices.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=\"Optimize your real-time WebSocket transcription for low latency and high accuracy\">\u003cmeta data-mint-head name=\"application-name\" content=\"Waves\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/own-c8c61ef7/WUl4I9oXKsDOL7nt/_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/own-c8c61ef7/WUl4I9oXKsDOL7nt/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/own-c8c61ef7/WUl4I9oXKsDOL7nt/_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/own-c8c61ef7/WUl4I9oXKsDOL7nt/_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/own-c8c61ef7/WUl4I9oXKsDOL7nt/_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/own-c8c61ef7/WUl4I9oXKsDOL7nt/_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/own-c8c61ef7/WUl4I9oXKsDOL7nt/_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/own-c8c61ef7/WUl4I9oXKsDOL7nt/_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/own-c8c61ef7/WUl4I9oXKsDOL7nt/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Best Practices - Waves\">\u003cmeta data-mint-head property=\"og:description\" content=\"Optimize your real-time WebSocket transcription for low latency and high accuracy\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Waves\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://own-c8c61ef7.mintlify.app/v4.0.0/content/speech-to-text/realtime/best-practices\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://own-c8c61ef7.mintlify.site/_mintlify/api/og/v2?division=Realtime+%28WebSocket%29\u0026amp;title=Best+Practices\u0026amp;description=Optimize+your+real-time+WebSocket+transcription+for+low+latency+and+high+accuracy\u0026amp;theme=28e191bba2c133384bdb739d\u0026amp;signature=6bbab9ccf2340055dc92a38361a99172cca8c9848693ca93759000a8b11adead\">\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=\"Best Practices - Waves\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Optimize your real-time WebSocket transcription for low latency and high accuracy\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://own-c8c61ef7.mintlify.site/_mintlify/api/og/v2?division=Realtime+%28WebSocket%29\u0026amp;title=Best+Practices\u0026amp;description=Optimize+your+real-time+WebSocket+transcription+for+low+latency+and+high+accuracy\u0026amp;theme=28e191bba2c133384bdb739d\u0026amp;signature=6bbab9ccf2340055dc92a38361a99172cca8c9848693ca93759000a8b11adead\">\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/own-c8c61ef7/WUl4I9oXKsDOL7nt/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Waves\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#217D80\">\u003clink data-mint-head rel=\"canonical\" href=\"https://own-c8c61ef7.mintlify.app/v4.0.0/content/speech-to-text/realtime/best-practices\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/v4.0.0/content/speech-to-text/realtime/best-practices.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://own-c8c61ef7.mintlify.app/#organization\",\"name\":\"Waves\",\"url\":\"https://own-c8c61ef7.mintlify.app\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/own-c8c61ef7/OyDyIUQRfHl2dfUg/logo/logo_dark.png?fit=max\u0026auto=format\u0026n=OyDyIUQRfHl2dfUg\u0026q=85\u0026s=e8cbff613d2641b35a78860686605f3d\"}},{\"@type\":\"WebSite\",\"@id\":\"https://own-c8c61ef7.mintlify.app#website\",\"name\":\"Waves\",\"url\":\"https://own-c8c61ef7.mintlify.app\",\"publisher\":{\"@id\":\"https://own-c8c61ef7.mintlify.app/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://own-c8c61ef7.mintlify.app/v4.0.0/content/speech-to-text/realtime/best-practices#webpage\",\"url\":\"https://own-c8c61ef7.mintlify.app/v4.0.0/content/speech-to-text/realtime/best-practices\",\"name\":\"Best Practices\",\"description\":\"Optimize your real-time WebSocket transcription for low latency and high accuracy\",\"dateModified\":\"2026-01-27T12:44:47.440Z\",\"isPartOf\":{\"@id\":\"https://own-c8c61ef7.mintlify.app#website\"},\"breadcrumb\":{\"@id\":\"https://own-c8c61ef7.mintlify.app/v4.0.0/content/speech-to-text/realtime/best-practices#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://own-c8c61ef7.mintlify.app/v4.0.0/content/speech-to-text/realtime/best-practices#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Speech to Text\",\"item\":\"https://own-c8c61ef7.mintlify.app/v4.0.0/content/speech-to-text/overview\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Realtime (WebSocket)\",\"item\":\"https://own-c8c61ef7.mintlify.app/v4.0.0/content/speech-to-text/realtime/quickstart\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Best Practices\",\"item\":\"https://own-c8c61ef7.mintlify.app/v4.0.0/content/speech-to-text/realtime/best-practices\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://own-c8c61ef7.mintlify.app/v4.0.0/content/speech-to-text/realtime/best-practices#article\",\"headline\":\"Best Practices\",\"name\":\"Best Practices\",\"description\":\"Optimize your real-time WebSocket transcription for low latency and high accuracy\",\"url\":\"https://own-c8c61ef7.mintlify.app/v4.0.0/content/speech-to-text/realtime/best-practices\",\"mainEntityOfPage\":{\"@id\":\"https://own-c8c61ef7.mintlify.app/v4.0.0/content/speech-to-text/realtime/best-practices#webpage\"},\"dateModified\":\"2026-01-27T12:44:47.440Z\",\"publisher\":{\"@id\":\"https://own-c8c61ef7.mintlify.app/#organization\"},\"isPartOf\":{\"@id\":\"https://own-c8c61ef7.mintlify.app#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Waves\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"Waves\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/v4.0.0/content/speech-to-text/realtime/best-practices.md","siteName":"Waves","nav":{"global":null,"versions":[{"version":"v4.0.0","default":true,"tabs":[{"tab":"Documentation","groups":[{"group":"Getting Started","pages":[{"title":"Introduction","icon":"book-open","href":"/v4.0.0/content/getting-started/introduction"},{"title":"Models","icon":"cube","href":"/v4.0.0/content/getting-started/models"},{"title":"Authentication","icon":"lock","href":"/v4.0.0/content/getting-started/authentication"},{"title":"HTTP vs HTTP Streaming vs Websockets","icon":"handshake-angle","href":"/v4.0.0/content/getting-started/http-stream"}]},{"group":"Text to Speech","pages":[{"title":"Overview","icon":"waveform-lines","href":"/v4.0.0/content/text-to-speech/overview"},{"title":"Quickstart","icon":"rocket","href":"/v4.0.0/content/text-to-speech/quickstart"},{"title":"How to use Text to Speech (TTS)","icon":"wave-square","href":"/v4.0.0/content/text-to-speech/how-to-tts"},{"title":"How to use Streaming Text to Speech (TTS) with websockets","icon":"bars-staggered","href":"/v4.0.0/content/text-to-speech/stream-tts"},{"title":"Pronunciation Dictionaries","icon":"speaker","href":"/v4.0.0/content/text-to-speech/pronunciation-dictionaries"},{"title":"Get available Voices, Models and Languages","icon":"toolbox","href":"/v4.0.0/content/text-to-speech/get-voice-models-langs"}]},{"group":"Speech to Text","pages":[{"title":"Overview","icon":"microphone","href":"/v4.0.0/content/speech-to-text/overview"},{"title":"Quickstart","icon":"rocket","href":"/v4.0.0/content/speech-to-text/quickstart"},{"group":"Pre-Recorded","icon":"play","pages":[{"title":"Quickstart","href":"/v4.0.0/content/speech-to-text/pre-recorded/quickstart"},{"title":"Audio Specifications","href":"/v4.0.0/content/speech-to-text/pre-recorded/audio-formats"},{"title":"Webhooks","href":"/v4.0.0/content/speech-to-text/pre-recorded/webhooks"},{"title":"Features","href":"/v4.0.0/content/speech-to-text/pre-recorded/features"},{"title":"Troubleshooting","href":"/v4.0.0/content/speech-to-text/pre-recorded/troubleshooting"},{"title":"Best Practices","href":"/v4.0.0/content/speech-to-text/pre-recorded/best-practices"},{"title":"Code Examples","href":"/v4.0.0/content/speech-to-text/pre-recorded/code-examples"}]},{"group":"Realtime (WebSocket)","icon":"radio","pages":[{"title":"Quickstart","href":"/v4.0.0/content/speech-to-text/realtime/quickstart"},{"title":"Response Format","href":"/v4.0.0/content/speech-to-text/realtime/response-format"},{"title":"Audio Specifications","href":"/v4.0.0/content/speech-to-text/realtime/audio-formats"},{"title":"Features","href":"/v4.0.0/content/speech-to-text/realtime/features"},{"title":"Troubleshooting","description":"Common issues and solutions for real-time WebSocket transcription","href":"/v4.0.0/content/speech-to-text/realtime/troubleshooting"},{"title":"Best Practices","href":"/v4.0.0/content/speech-to-text/realtime/best-practices"}]},{"group":"Features","icon":"layer-group","pages":[{"title":"Word timestamps","description":"Return word-level timing metadata from Pulse STT","href":"/v4.0.0/content/speech-to-text/features/word-timestamps"},{"title":"Language detection","href":"/v4.0.0/content/speech-to-text/features/language-detection"},{"title":"Sentence-level timestamps","href":"/v4.0.0/content/speech-to-text/features/utterances"},{"title":"Speaker diarization","href":"/v4.0.0/content/speech-to-text/features/diarization"},{"title":"PII and PCI Redaction","href":"/v4.0.0/content/speech-to-text/features/redaction"},{"title":"Full Transcript","href":"/v4.0.0/content/speech-to-text/features/full-transcript"},{"title":"Numeric Formatting","href":"/v4.0.0/content/speech-to-text/features/numeric-formatting"},{"title":"Word Boosting","href":"/v4.0.0/content/speech-to-text/features/word-boosting"},{"title":"Age \u0026 gender detection","href":"/v4.0.0/content/speech-to-text/features/age-and-gender-detection"},{"title":"Emotion detection","href":"/v4.0.0/content/speech-to-text/features/emotion-detection"}]},{"group":"Benchmarks","icon":"chart-line","pages":[{"title":"Performance","href":"/v4.0.0/content/speech-to-text/benchmarks/performance"},{"title":"Metrics Overview","href":"/v4.0.0/content/speech-to-text/benchmarks/metrics-overview"},{"title":"Evaluation Walkthrough","href":"/v4.0.0/content/speech-to-text/benchmarks/evaluation-walkthrough"}]}]},{"group":"Cookbooks","pages":[{"title":"Speech to Text Examples","sidebarTitle":"Speech to Text","icon":"code","href":"/v4.0.0/content/cookbooks/speech-to-text"}]},{"group":"Voice Cloning","pages":[{"title":"Types of Cloning: Instant vs Professional","icon":"compact-disc","href":"/v4.0.0/content/voice-cloning/types-of-clone"},{"title":"How to Create an Instant Voice Clone","icon":"compact-disc","href":"/v4.0.0/content/voice-cloning/how-to-vc-ui"},{"title":"How to create an Instant Voice Clone using Python SDK","icon":"compact-disc","href":"/v4.0.0/content/voice-cloning/how-to-vc"},{"title":"How to delete your Voice Clone using Python SDK","icon":"compact-disc","href":"/v4.0.0/content/voice-cloning/how-to-delete-vc"},{"title":"How to Create a Professional Voice Clone","icon":"compact-disc","href":"/v4.0.0/content/voice-cloning/how-to-pvc"}]},{"group":"Integrations","pages":[{"title":"LiveKit","icon":"voicemail","href":"/v4.0.0/content/integrations/livekit"},{"title":"Telephony: Plivo","icon":"phone-volume","href":"/v4.0.0/content/integrations/plivo"},{"title":"Telephony: Vonage","icon":"tty","href":"/v4.0.0/content/integrations/vonage"}]},{"group":"Best Practices","pages":[{"title":"Voice Cloning - Best Practices","icon":"clone","href":"/v4.0.0/content/best-practices/vc-best-practices"},{"title":"Professional Voice Cloning - Best Practices","icon":"user-tie","href":"/v4.0.0/content/best-practices/pvc-best-practices"},{"title":"Text to Speech (TTS) - Best Practices","icon":"comment-dots","href":"/v4.0.0/content/best-practices/tts-best-practices"}]}]},{"tab":"API Reference","pages":[{"title":"API Reference","href":"/v4.0.0/content/api-references/authentication"}]},{"tab":"Self Host","pages":[{"title":"Self Host","href":"/v4.0.0/content/on-prem/getting-started/introduction"}]},{"tab":"Client Libraries","pages":[{"title":"Client Libraries","href":"/v4.0.0/content/client-libraries/overview"}]},{"tab":"Changelog","pages":[{"title":"Changelog","href":"/v4.0.0/content/changelog/announcements"}]}]},{"version":"v3.0.1","pages":[{"title":"v3.0.1","href":"/v3.0.1/content/introduction/introduction"}]},{"version":"v2.2.0","pages":[{"title":"v2.2.0","href":"/v2.2.0/content/introduction/introduction"}]}]},"basePath":"","title":"Best Practices - Waves","buildId":"dpl_596ePT575z4qnAFksq1biRW97aLY","deploymentId":"dpl_596ePT575z4qnAFksq1biRW97aLY","dynamics":[],"chunks":[]}