Voice name (e.g. Amjad) or the UUID of a custom cloned voice. Pick a speaker that matches the chosen dialect — see the dialect field below for voice examples.
Output sample rate of the PCM audio. One of 8k or 16k. Defaults to 16k. Only applies to PCM output — cannot be combined with mulaw (mu-law output is always 8 kHz).
Refer to Hamsa Platforms to get the list of the available pre-built speakers where you can take the name of the speaker, or use a UUID for your custom cloned voice.
When using a custom cloned voice (UUID) as the speaker, you must preload the voice before establishing the WebSocket connection. This ensures optimal latency during streaming.
Preload Required for Custom VoicesCall the Preload Voice endpoint once when your application starts to avoid latency when using custom cloned voices.
// 1. Preload the custom voice at app startupawait fetch('https://api.tryhamsa.com/v2/tts/voices/custom/preload', { method: 'POST', headers: { 'Authorization': 'Token YOUR_API_KEY', 'Content-Type': 'application/json' }, body: JSON.stringify({ voiceId: 'your-custom-voice-uuid' })});// 2. Now connect to WebSocket and use the custom voiceconst ws = new WebSocket('wss://api.tryhamsa.com/v1/realtime/ws?api_key=YOUR_API_KEY');ws.onopen = () => { ws.send(JSON.stringify({ type: 'tts', payload: { text: 'Hello from my custom voice', speaker: 'your-custom-voice-uuid', // Use the same UUID dialect: 'pls', languageId: 'ar', mulaw: false } }));};
Messages
{ "type": "tts", "payload": { "text": "مرحبا بك في خدمة همسة", "speaker": "Amjad", "dialect": "pls", "languageId": "ar", "mulaw": false, "sampleRate": "16k", "expressiveness": 1 } }
{ "type": "ack", "payload": { "message": "Real time text to speach connection establesh" } }
API key passed as query parameter or X-Api-Key header
TTS Request
type:object
Request to convert text to speech
TTS Acknowledgment
type:object
Server acknowledges the TTS request
TTS Audio Chunk
type:string
Binary audio data chunk
TTS Stream End
type:object
Signals the end of the audio stream
Error Response
type:object
Error message from the server
Was this page helpful?
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Hamsa API","colors":{"primary":"#1B5E3A","light":"#B4FD83","dark":"#2D7A4F"},"logo":{"light":"https://mintcdn.com/hamsa-452fa79a/B5KuRhzUCER4_1Wi/logo/hamsa_logo_light.svg?fit=max\u0026auto=format\u0026n=B5KuRhzUCER4_1Wi\u0026q=85\u0026s=2576c2f27fed68b31fa686aca13e6fbf","dark":"https://mintcdn.com/hamsa-452fa79a/B5KuRhzUCER4_1Wi/logo/hamsa_logo_dark.svg?fit=max\u0026auto=format\u0026n=B5KuRhzUCER4_1Wi\u0026q=85\u0026s=b89ad21e4d97ee72de3045482602bf53"},"favicon":"https://mintcdn.com/hamsa-452fa79a/B5KuRhzUCER4_1Wi/favicon.svg?fit=max\u0026auto=format\u0026n=B5KuRhzUCER4_1Wi\u0026q=85\u0026s=f369c0501b06a15339575e7c72e2494a","navbar":{"links":[{"href":"https://tryhamsa.com/contact/","label":"Support"}],"primary":{"type":"button","label":"Dashboard","href":"https://agents.tryhamsa.com/"}},"footer":{"socials":{"github":"https://github.com/hamsa-ai","linkedin":"https://www.linkedin.com/company/tryhamsa","website":"https://tryhamsa.com"}},"integrations":{"posthog":{"apiKey":"phc_3TCeimn6ufgVchZQ08TCRlIfu7Lwyaa8xGtBA67ym66","sessionRecording":false}},"contextual":{"options":["copy","view","chatgpt","claude","perplexity","mcp","cursor","vscode"],"display":"header"},"styling":{"latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"hamsa-452fa79a","hasAudioNarration":false,"actualSubdomain":"hamsa-452fa79a","customDomains":["docs.tryhamsa.com"],"gitSource":{"type":"github","owner":"hamsa-dev","repo":"docs","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":""},"chroma":{"liveDeploymentHistoryId":"6aba7d75e5024a36fdb35844","collectionId":"530fa5de-69cb-481c-80ed-ee186974aa4b","schemaVersion":"v3","latestBuiltDeploymentHistoryId":"6aba7d75e5024a36fdb35844"},"feedback":{"thumbs":true},"entitlements":{"AI_CHAT":{"status":"ENABLED"},"WEB_MCP":{"status":"ENABLED"},"NARRATION":{"status":"ENABLED"}},"buildId":"6aba7d75e5024a36fdb35844","clientVersion":"0.0.4074","searchFilterCounts":[{"language":"default","tag":"API Reference","count":103},{"language":"default","tag":"Agents Platform","count":77},{"language":"default","tag":"Agents","count":25},{"language":"default","tag":"Overview","count":20},{"language":"default","tag":"Flow Agent","count":18},{"language":"default","tag":"Media Platform","count":15},{"language":"default","tag":"Variables","count":13},{"language":"default","tag":"Developers","count":13},{"language":"default","tag":"Web Tools Routes","count":12},{"language":"default","tag":"Nodes","count":11}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":true,"hasWebMcpPermissions":true,"toggles":[],"googleFontsInlined":false},"customCss":[{"filePath":"style.css","content":"#navbar>div>div>div>div:nth-child(3)>div{display:none!important}[data-theme=\"light\"] nav a[aria-current=\"page\"],[data-theme=\"light\"] nav a.active,[data-theme=\"light\"] .sidebar a[aria-current=\"page\"],[data-theme=\"light\"] .sidebar a.active,[data-theme=\"light\"] [style*=\"background\"][style*=\"#B4FD83\"],[data-theme=\"light\"] [style*=\"background\"][style*=\"rgb(180, 253, 131)\"]{background-color:#2D7A4F!important;color:#ffffff!important}[data-theme=\"dark\"] nav a[aria-current=\"page\"],[data-theme=\"dark\"] nav a.active,[data-theme=\"dark\"] .sidebar a[aria-current=\"page\"],[data-theme=\"dark\"] .sidebar a.active,[data-theme=\"dark\"] [style*=\"background\"][style*=\"#B4FD83\"],[data-theme=\"dark\"] [style*=\"background\"][style*=\"rgb(180, 253, 131)\"]{background-color:#B4FD83!important;color:#1a1a1a!important}[data-theme=\"light\"] button[class*=\"primary\"],[data-theme=\"light\"] .btn-primary{background-color:#2D7A4F!important;color:#ffffff!important}[data-theme=\"dark\"] button[class*=\"primary\"],[data-theme=\"dark\"] .btn-primary{background-color:#B4FD83!important;color:#1a1a1a!important}"}],"page":{"pagePath":"websocket/websocket-tts","slug":"/websocket/websocket-tts","pageMetadata":{"title":"Text-to-Speech","description":"Convert text to streaming audio via WebSocket","asyncapi":"websocket/asyncapi-tts.json tts","href":"/websocket/websocket-tts"},"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: \"Convert text to streaming audio via WebSocket\"\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`,ol:`ol`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,..._provideComponents(),...props.components},{CodeBlock,Expandable,Heading,Note,ParamField,Table,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Expandable)_missingMdxReference(`Expandable`,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:[_jsx(Note,{children:_jsx(_components.p,{children:`Connect to the WebSocket and send TTS requests to convert text into streaming audio.`})}),`\n`,_jsx(Heading,{level:`2`,id:`quick-start`,children:`Quick Start`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsx(_components.li,{children:`Enter your API key in the authentication field`}),`\n`,_jsxs(_components.li,{children:[`Click `,_jsx(_components.strong,{children:`Connect`}),` to establish the WebSocket connection`]}),`\n`,_jsx(_components.li,{children:`Modify the request payload with your text`}),`\n`,_jsxs(_components.li,{children:[`Click `,_jsx(_components.strong,{children:`Send`}),` to receive streaming audio`]}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`request-message`,children:`Request Message`}),`\n`,_jsx(_components.p,{children:`After connecting, send a JSON message with the following structure:`}),`\n`,_jsx(ParamField,{body:`type`,type:`string`,required:true,id:`param-type`,children:_jsxs(_components.p,{children:[`Must be `,_jsx(_components.code,{children:`\"tts\"`})]})}),`\n`,_jsx(ParamField,{body:`payload`,type:`object`,required:true,id:`param-payload`,children:_jsxs(Expandable,{title:`payload properties`,children:[_jsx(ParamField,{body:`text`,type:`string`,required:true,id:`param-text`,children:_jsx(_components.p,{children:`The text to synthesize. Maximum 2000 characters.`})}),_jsx(ParamField,{body:`speaker`,type:`string`,required:true,id:`param-speaker`,children:_jsxs(_components.p,{children:[`Voice name (e.g. `,_jsx(_components.code,{children:`Amjad`}),`) or the UUID of a custom cloned voice. Pick a speaker that matches the chosen dialect — see the dialect field below for voice examples.`]})}),_jsx(ParamField,{body:`dialect`,type:`string`,required:true,id:`param-dialect`,children:_jsxs(_components.p,{children:[`Dialect to synthesize. One of: `,_jsx(_components.code,{children:`pls`}),`, `,_jsx(_components.code,{children:`egy`}),`, `,_jsx(_components.code,{children:`syr`}),`, `,_jsx(_components.code,{children:`irq`}),`, `,_jsx(_components.code,{children:`jor`}),`, `,_jsx(_components.code,{children:`leb`}),`, `,_jsx(_components.code,{children:`ksa`}),`, `,_jsx(_components.code,{children:`uae`}),`, `,_jsx(_components.code,{children:`bah`}),`, `,_jsx(_components.code,{children:`qat`}),`, `,_jsx(_components.code,{children:`kuw`}),`, `,_jsx(_components.code,{children:`oma`}),`, `,_jsx(_components.code,{children:`msa`}),`, `,_jsx(_components.code,{children:`ar-sa`}),`, `,_jsx(_components.code,{children:`en`}),`. See `,_jsx(_components.a,{href:`#dialects-and-voice-examples`,children:`Dialects and Voice Examples`}),` below.`]})}),_jsx(ParamField,{body:`languageId`,type:`string`,required:true,example:`ar`,id:`param-language-id`,children:_jsx(_components.p,{children:`Language code. (e.g., “ar”).`})}),_jsx(ParamField,{body:`mulaw`,type:`boolean`,required:true,example:`false`,id:`param-mulaw`,children:_jsx(_components.p,{children:`Whether to use mu-law audio encoding. (e.g., false)`})}),_jsx(ParamField,{body:`sampleRate`,type:`string`,default:`16k`,id:`param-sample-rate`,children:_jsxs(_components.p,{children:[`Output sample rate of the PCM audio. One of `,_jsx(_components.code,{children:`8k`}),` or `,_jsx(_components.code,{children:`16k`}),`. Defaults to `,_jsx(_components.code,{children:`16k`}),`. Only applies to PCM output — cannot be combined with `,_jsx(_components.code,{children:`mulaw`}),` (mu-law output is always 8 kHz).`]})}),_jsx(ParamField,{body:`expressiveness`,type:`number`,default:`1`,id:`param-expressiveness`,children:_jsxs(_components.p,{children:[`Controls how expressive the generated speech sounds, from `,_jsx(_components.code,{children:`0`}),` (flat and monotone) to `,_jsx(_components.code,{children:`2`}),` (highly expressive). Defaults to `,_jsx(_components.code,{children:`1`}),`.`]})})]})}),`\n`,_jsx(CodeBlock,{filename:`TTS Request`,numberOfLines:`12`,language:`json`,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:`json`,children:_jsxs(_components.code,{language:`json`,numberOfLines:`12`,children:[_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:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"tts\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"payload\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"text\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"مرحبا بك في خدمة همسة\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"speaker\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Amjad\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"dialect\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"pls\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"languageId\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"ar\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"mulaw\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`false`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"sampleRate\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"16k\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"expressiveness\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1`})]}),`\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(Heading,{level:`2`,id:`response-sequence`,children:`Response Sequence`}),`\n`,_jsx(_components.p,{children:`The server responds with:`}),`\n`,_jsx(CodeBlock,{filename:`1. Acknowledgment`,numberOfLines:`6`,language:`json`,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:`json`,children:_jsxs(_components.code,{language:`json`,numberOfLines:`6`,children:[_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:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"ack\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"payload\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"message\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Real time text to speach connection establesh\"`})]}),`\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(CodeBlock,{filename:`2. Binary Audio Chunks`,numberOfLines:`2`,language:`json`,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:`json`,children:_jsxs(_components.code,{language:`json`,numberOfLines:`2`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Raw binary audio data streamed in chunks`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Buffer these chunks to reconstruct the complete audio`})}),`\n`]})})}),`\n`,_jsx(CodeBlock,{filename:`3. Stream End`,numberOfLines:`6`,language:`json`,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:`json`,children:_jsxs(_components.code,{language:`json`,numberOfLines:`6`,children:[_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:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"end\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"payload\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"message\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"End of TTS stream\"`})]}),`\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(Heading,{level:`2`,id:`dialects-and-voice-examples`,children:`Dialects and Voice Examples`}),`\n`,_jsxs(_components.p,{children:[`Pick a `,_jsx(_components.code,{children:`speaker`}),` that matches your chosen `,_jsx(_components.code,{children:`dialect`}),`. Voice examples per dialect:`]}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Dialect`}),_jsx(_components.th,{children:`Code`}),_jsx(_components.th,{children:`Voice examples`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Palestinian`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`pls`})}),_jsx(_components.td,{children:`Amjad, Layan`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Egyptian`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`egy`})}),_jsx(_components.td,{children:`Mariam, Samir`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Syrian`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`syr`})}),_jsx(_components.td,{children:`Dalal, Mais`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Iraqi`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`irq`})}),_jsx(_components.td,{children:`Lyali, Fatma`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Jordanian`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`jor`})}),_jsx(_components.td,{children:`Lana, Jasem`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Lebanese`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`leb`})}),_jsx(_components.td,{children:`Carla, Majd`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Saudi`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`ksa`})}),_jsx(_components.td,{children:`Hiba, Fahd`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Emirati`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`uae`})}),_jsx(_components.td,{children:`Salma, Dima`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Bahraini`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`bah`})}),_jsx(_components.td,{children:`Mazen, Ruba`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Qatari`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`qat`})}),_jsx(_components.td,{children:`Deema, Faisal`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Kuwaiti`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`kuw`})}),_jsx(_components.td,{children:`Mai, Hatem`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Omani`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`oma`})}),_jsx(_components.td,{children:`Aisha, Jaber`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`MSA / Fusha`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`msa`})}),_jsx(_components.td,{children:`Salem, Tamim`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Arabic – Gulf`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`ar-sa`})}),_jsx(_components.td,{children:`Khalid, Rahma`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`English`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`en`})}),_jsx(_components.td,{children:`Emma, James`})]})]})]}),`\n`,_jsx(Heading,{level:`2`,id:`available-speakers`,children:`Available Speakers`}),`\n`,_jsx(_components.p,{children:`Refer to Hamsa Platforms to get the list of the available pre-built speakers where you can take the name of the speaker, or use a UUID for your custom cloned voice.`}),`\n`,_jsx(Heading,{level:`2`,id:`using-custom-cloned-voices`,children:`Using Custom Cloned Voices`}),`\n`,_jsx(_components.p,{children:`When using a custom cloned voice (UUID) as the speaker, you must preload the voice before establishing the WebSocket connection. This ensures optimal latency during streaming.`}),`\n`,_jsxs(Warning,{children:[_jsx(_components.p,{children:_jsx(_components.strong,{children:`Preload Required for Custom Voices`})}),_jsxs(_components.p,{children:[`Call the `,_jsx(_components.a,{href:`/developers/apis/use-cloned-voice-id-as-speaker`,children:`Preload Voice endpoint`}),` once when your application starts to avoid latency when using custom cloned voices.`]})]}),`\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:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// 1. Preload the custom voice at app startup`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` fetch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'https://api.tryhamsa.com/v2/tts/voices/custom/preload'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` method:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'POST'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` headers:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'Authorization'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'Token YOUR_API_KEY'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'Content-Type'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'application/json'`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` body:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` JSON`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`stringify`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`voiceId:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'your-custom-voice-uuid'`}),_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`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// 2. Now connect to WebSocket and use the custom voice`})}),`\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:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'wss://api.tryhamsa.com/v1/realtime/ws?api_key=YOUR_API_KEY'`}),_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\":`#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:` 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:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` type:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'tts'`}),_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:` payload:`}),_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:` text:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'Hello from my custom voice'`}),_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:` speaker:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'your-custom-voice-uuid'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Use the same UUID`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` dialect:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'pls'`}),_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:` languageId:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'ar'`}),_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:` mulaw:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` false`})]}),`\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`]})})})]})}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":"Text-to-Speech","description":"Convert text to streaming audio via WebSocket","asyncapi":"websocket/asyncapi-tts.json tts","href":"/websocket/websocket-tts"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Quick Start","slug":"quick-start","depth":2,"children":[]},{"title":"Request Message","slug":"request-message","depth":2,"children":[]},{"title":"Response Sequence","slug":"response-sequence","depth":2,"children":[]},{"title":"Dialects and Voice Examples","slug":"dialects-and-voice-examples","depth":2,"children":[]},{"title":"Available Speakers","slug":"available-speakers","depth":2,"children":[]},{"title":"Using Custom Cloned Voices","slug":"using-custom-cloned-voices","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"apiReferenceData":{"channel":{"id":"tts","title":"Text-to-Speech","description":"Convert text to speech with streaming audio output","servers":[{"id":"production","protocol":"wss","host":"api.tryhamsa.com/v1/realtime/ws","bindings":[],"variables":[]}],"address":"/","parameters":[],"bindings":[],"operations":[{"id":"sendTTSRequest","title":"Send TTS Request","description":"Send a text-to-speech request to convert text into streaming audio","type":"receive","messages":[{"id":"ttsRequest","contentType":"application/json","payload":[{"name":"TTS Request","description":"Request to convert text to speech","type":"object","properties":[{"name":"type","type":"string","description":"Message type identifier","required":true},{"name":"payload","type":"object","required":true,"properties":[{"name":"text","type":"string","description":"The text to synthesize into speech. Maximum 2000 characters.","required":true},{"name":"speaker","type":"string","description":"Voice name (e.g. 'Amjad') or the UUID of a custom cloned voice. Pick a speaker that matches the chosen dialect.","required":true},{"name":"dialect","type":"string","description":"Dialect to synthesize. Voice examples per dialect: pls (Palestinian) — Amjad, Layan; egy (Egyptian) — Mariam, Samir; syr (Syrian) — Dalal, Mais; irq (Iraqi) — Lyali, Fatma; jor (Jordanian) — Lana, Jasem; leb (Lebanese) — Carla, Majd; ksa (Saudi) — Hiba, Fahd; uae (Emirati) — Salma, Dima; bah (Bahraini) — Mazen, Ruba; qat (Qatari) — Deema, Faisal; kuw (Kuwaiti) — Mai, Hatem; oma (Omani) — Aisha, Jaber; msa (MSA / Fusha) — Salem, Tamim; ar-sa (Arabic – Gulf) — Khalid, Rahma; en (English) — Emma, James.","enumValues":["pls","egy","syr","irq","jor","leb","ksa","uae","bah","qat","kuw","oma","msa","ar-sa","en"],"required":false},{"name":"languageId","type":"string","description":"Language code. Defaults to 'ar' (Arabic).","required":false},{"name":"mulaw","type":"boolean","description":"Whether to use mu-law audio encoding.","required":false},{"name":"sampleRate","type":"string","description":"Output sample rate of the PCM audio. Defaults to '16k'. Only applies to PCM output — cannot be combined with mulaw (mu-law output is always 8 kHz).","enumValues":["8k","16k"],"required":false},{"name":"expressiveness","type":"number","description":"Controls how expressive the generated speech sounds. 0 is flat and monotone, 1 is the natural default, and 2 is highly expressive.","required":false}]}]}],"headers":[],"jsonPayloadSchema":{"type":"object","required":["type","payload","dialect","languageId","mulaw"],"properties":{"type":{"type":"string","const":"tts","description":"Message type identifier","x-parser-schema-id":"\u003canonymous-schema-1>"},"payload":{"type":"object","required":["text","speaker"],"properties":{"text":{"type":"string","minLength":1,"maxLength":2000,"description":"The text to synthesize into speech. Maximum 2000 characters.","x-parser-schema-id":"\u003canonymous-schema-3>"},"speaker":{"type":"string","minLength":1,"description":"Voice name (e.g. 'Amjad') or the UUID of a custom cloned voice. Pick a speaker that matches the chosen dialect.","x-parser-schema-id":"\u003canonymous-schema-4>"},"dialect":{"type":"string","enum":["pls","egy","syr","irq","jor","leb","ksa","uae","bah","qat","kuw","oma","msa","ar-sa","en"],"description":"Dialect to synthesize. Voice examples per dialect: pls (Palestinian) — Amjad, Layan; egy (Egyptian) — Mariam, Samir; syr (Syrian) — Dalal, Mais; irq (Iraqi) — Lyali, Fatma; jor (Jordanian) — Lana, Jasem; leb (Lebanese) — Carla, Majd; ksa (Saudi) — Hiba, Fahd; uae (Emirati) — Salma, Dima; bah (Bahraini) — Mazen, Ruba; qat (Qatari) — Deema, Faisal; kuw (Kuwaiti) — Mai, Hatem; oma (Omani) — Aisha, Jaber; msa (MSA / Fusha) — Salem, Tamim; ar-sa (Arabic – Gulf) — Khalid, Rahma; en (English) — Emma, James.","x-parser-schema-id":"\u003canonymous-schema-5>"},"languageId":{"type":"string","default":"ar","description":"Language code. Defaults to 'ar' (Arabic).","x-parser-schema-id":"\u003canonymous-schema-6>"},"mulaw":{"type":"boolean","default":false,"description":"Whether to use mu-law audio encoding.","x-parser-schema-id":"\u003canonymous-schema-7>"},"sampleRate":{"type":"string","enum":["8k","16k"],"default":"16k","description":"Output sample rate of the PCM audio. Defaults to '16k'. Only applies to PCM output — cannot be combined with mulaw (mu-law output is always 8 kHz).","x-parser-schema-id":"\u003canonymous-schema-8>"},"expressiveness":{"type":"number","minimum":0,"maximum":2,"default":1,"description":"Controls how expressive the generated speech sounds. 0 is flat and monotone, 1 is the natural default, and 2 is highly expressive.","x-parser-schema-id":"\u003canonymous-schema-9>"}},"x-parser-schema-id":"\u003canonymous-schema-2>"}},"x-parser-schema-id":"TTSRequestPayload"},"title":"TTS Request","description":"Request to convert text to speech","example":"{\n \"type\": \"tts\",\n \"payload\": {\n \"text\": \"مرحبا بك في خدمة همسة\",\n \"speaker\": \"Amjad\",\n \"dialect\": \"pls\",\n \"languageId\": \"ar\",\n \"mulaw\": false,\n \"sampleRate\": \"16k\",\n \"expressiveness\": 1\n }\n}","bindings":[],"extensions":[{"id":"x-parser-unique-object-id","value":"ttsRequest"}]}],"bindings":[],"extensions":[{"id":"x-parser-unique-object-id","value":"tts"}]},{"id":"receiveTTSResponse","title":"Receive TTS Response","description":"Receive acknowledgment, audio chunks, and end signal","type":"send","messages":[{"id":"ttsAck","contentType":"application/json","payload":[{"name":"TTS Acknowledgment","description":"Server acknowledges the TTS request","type":"object","properties":[{"name":"type","type":"string","description":"ack","required":false},{"name":"payload","type":"object","required":false,"properties":[{"name":"message","type":"string","required":false}]}]}],"headers":[],"jsonPayloadSchema":{"type":"object","properties":{"type":{"type":"string","const":"ack","x-parser-schema-id":"\u003canonymous-schema-10>"},"payload":{"type":"object","properties":{"message":{"type":"string","x-parser-schema-id":"\u003canonymous-schema-12>"}},"x-parser-schema-id":"\u003canonymous-schema-11>"}},"x-parser-schema-id":"AckPayload"},"title":"TTS Acknowledgment","description":"Server acknowledges the TTS request","example":"{\n \"type\": \"ack\",\n \"payload\": {\n \"message\": \"Real time text to speach connection establesh\"\n }\n}","bindings":[],"extensions":[{"id":"x-parser-unique-object-id","value":"ttsAck"}]},{"id":"ttsAudioChunk","contentType":"application/octet-stream","payload":[{"type":"string","format":"binary","description":"Binary audio data chunk","x-parser-schema-id":"\u003canonymous-schema-13>","name":"TTS Audio Chunk"}],"headers":[],"jsonPayloadSchema":{"type":"string","format":"binary","description":"Raw audio bytes. Buffer multiple chunks to reconstruct the complete audio file.","x-parser-schema-id":"\u003canonymous-schema-13>"},"title":"TTS Audio Chunk","description":"Binary audio data chunk","example":"{}","bindings":[],"extensions":[{"id":"x-parser-unique-object-id","value":"ttsAudioChunk"}]},{"id":"ttsEnd","contentType":"application/json","payload":[{"name":"TTS Stream End","description":"Signals the end of the audio stream","type":"object","properties":[{"name":"type","type":"string","description":"end","required":false},{"name":"payload","type":"object","required":false,"properties":[{"name":"message","type":"string","required":false}]}]}],"headers":[],"jsonPayloadSchema":{"type":"object","properties":{"type":{"type":"string","const":"end","x-parser-schema-id":"\u003canonymous-schema-14>"},"payload":{"type":"object","properties":{"message":{"type":"string","x-parser-schema-id":"\u003canonymous-schema-16>"}},"x-parser-schema-id":"\u003canonymous-schema-15>"}},"x-parser-schema-id":"EndPayload"},"title":"TTS Stream End","description":"Signals the end of the audio stream","example":"{\n \"type\": \"end\",\n \"payload\": {\n \"message\": \"End of TTS stream\"\n }\n}","bindings":[],"extensions":[{"id":"x-parser-unique-object-id","value":"ttsEnd"}]},{"id":"errorResponse","contentType":"application/json","payload":[{"name":"Error Response","description":"Error message from the server","type":"object","properties":[{"name":"type","type":"string","description":"error","required":false},{"name":"payload","type":"object","required":false,"properties":[{"name":"message","type":"string","description":"Error description","required":false}]}]}],"headers":[],"jsonPayloadSchema":{"type":"object","properties":{"type":{"type":"string","const":"error","x-parser-schema-id":"\u003canonymous-schema-17>"},"payload":{"type":"object","properties":{"message":{"type":"string","description":"Error description","x-parser-schema-id":"\u003canonymous-schema-19>"}},"x-parser-schema-id":"\u003canonymous-schema-18>"}},"x-parser-schema-id":"ErrorPayload"},"title":"Error Response","description":"Error message from the server","example":"{\n \"type\": \"error\",\n \"payload\": {\n \"message\": \"Invalid payload for message type: tts\"\n }\n}","bindings":[],"extensions":[{"id":"x-parser-unique-object-id","value":"errorResponse"}]}],"bindings":[],"extensions":[{"id":"x-parser-unique-object-id","value":"tts"}]}],"sendOperations":[{"id":"sendTTSRequest","title":"Send TTS Request","description":"Send a text-to-speech request to convert text into streaming audio","type":"receive","messages":[{"id":"ttsRequest","contentType":"application/json","payload":[{"name":"TTS Request","description":"Request to convert text to speech","type":"object","properties":[{"name":"type","type":"string","description":"Message type identifier","required":true},{"name":"payload","type":"object","required":true,"properties":[{"name":"text","type":"string","description":"The text to synthesize into speech. Maximum 2000 characters.","required":true},{"name":"speaker","type":"string","description":"Voice name (e.g. 'Amjad') or the UUID of a custom cloned voice. Pick a speaker that matches the chosen dialect.","required":true},{"name":"dialect","type":"string","description":"Dialect to synthesize. Voice examples per dialect: pls (Palestinian) — Amjad, Layan; egy (Egyptian) — Mariam, Samir; syr (Syrian) — Dalal, Mais; irq (Iraqi) — Lyali, Fatma; jor (Jordanian) — Lana, Jasem; leb (Lebanese) — Carla, Majd; ksa (Saudi) — Hiba, Fahd; uae (Emirati) — Salma, Dima; bah (Bahraini) — Mazen, Ruba; qat (Qatari) — Deema, Faisal; kuw (Kuwaiti) — Mai, Hatem; oma (Omani) — Aisha, Jaber; msa (MSA / Fusha) — Salem, Tamim; ar-sa (Arabic – Gulf) — Khalid, Rahma; en (English) — Emma, James.","enumValues":["pls","egy","syr","irq","jor","leb","ksa","uae","bah","qat","kuw","oma","msa","ar-sa","en"],"required":false},{"name":"languageId","type":"string","description":"Language code. Defaults to 'ar' (Arabic).","required":false},{"name":"mulaw","type":"boolean","description":"Whether to use mu-law audio encoding.","required":false},{"name":"sampleRate","type":"string","description":"Output sample rate of the PCM audio. Defaults to '16k'. Only applies to PCM output — cannot be combined with mulaw (mu-law output is always 8 kHz).","enumValues":["8k","16k"],"required":false},{"name":"expressiveness","type":"number","description":"Controls how expressive the generated speech sounds. 0 is flat and monotone, 1 is the natural default, and 2 is highly expressive.","required":false}]}]}],"headers":[],"jsonPayloadSchema":{"type":"object","required":["type","payload","dialect","languageId","mulaw"],"properties":{"type":{"type":"string","const":"tts","description":"Message type identifier","x-parser-schema-id":"\u003canonymous-schema-1>"},"payload":{"type":"object","required":["text","speaker"],"properties":{"text":{"type":"string","minLength":1,"maxLength":2000,"description":"The text to synthesize into speech. Maximum 2000 characters.","x-parser-schema-id":"\u003canonymous-schema-3>"},"speaker":{"type":"string","minLength":1,"description":"Voice name (e.g. 'Amjad') or the UUID of a custom cloned voice. Pick a speaker that matches the chosen dialect.","x-parser-schema-id":"\u003canonymous-schema-4>"},"dialect":{"type":"string","enum":["pls","egy","syr","irq","jor","leb","ksa","uae","bah","qat","kuw","oma","msa","ar-sa","en"],"description":"Dialect to synthesize. Voice examples per dialect: pls (Palestinian) — Amjad, Layan; egy (Egyptian) — Mariam, Samir; syr (Syrian) — Dalal, Mais; irq (Iraqi) — Lyali, Fatma; jor (Jordanian) — Lana, Jasem; leb (Lebanese) — Carla, Majd; ksa (Saudi) — Hiba, Fahd; uae (Emirati) — Salma, Dima; bah (Bahraini) — Mazen, Ruba; qat (Qatari) — Deema, Faisal; kuw (Kuwaiti) — Mai, Hatem; oma (Omani) — Aisha, Jaber; msa (MSA / Fusha) — Salem, Tamim; ar-sa (Arabic – Gulf) — Khalid, Rahma; en (English) — Emma, James.","x-parser-schema-id":"\u003canonymous-schema-5>"},"languageId":{"type":"string","default":"ar","description":"Language code. Defaults to 'ar' (Arabic).","x-parser-schema-id":"\u003canonymous-schema-6>"},"mulaw":{"type":"boolean","default":false,"description":"Whether to use mu-law audio encoding.","x-parser-schema-id":"\u003canonymous-schema-7>"},"sampleRate":{"type":"string","enum":["8k","16k"],"default":"16k","description":"Output sample rate of the PCM audio. Defaults to '16k'. Only applies to PCM output — cannot be combined with mulaw (mu-law output is always 8 kHz).","x-parser-schema-id":"\u003canonymous-schema-8>"},"expressiveness":{"type":"number","minimum":0,"maximum":2,"default":1,"description":"Controls how expressive the generated speech sounds. 0 is flat and monotone, 1 is the natural default, and 2 is highly expressive.","x-parser-schema-id":"\u003canonymous-schema-9>"}},"x-parser-schema-id":"\u003canonymous-schema-2>"}},"x-parser-schema-id":"TTSRequestPayload"},"title":"TTS Request","description":"Request to convert text to speech","example":"{\n \"type\": \"tts\",\n \"payload\": {\n \"text\": \"مرحبا بك في خدمة همسة\",\n \"speaker\": \"Amjad\",\n \"dialect\": \"pls\",\n \"languageId\": \"ar\",\n \"mulaw\": false,\n \"sampleRate\": \"16k\",\n \"expressiveness\": 1\n }\n}","bindings":[],"extensions":[{"id":"x-parser-unique-object-id","value":"ttsRequest"}]}],"bindings":[],"extensions":[{"id":"x-parser-unique-object-id","value":"tts"}]}],"receiveOperations":[{"id":"receiveTTSResponse","title":"Receive TTS Response","description":"Receive acknowledgment, audio chunks, and end signal","type":"send","messages":[{"id":"ttsAck","contentType":"application/json","payload":[{"name":"TTS Acknowledgment","description":"Server acknowledges the TTS request","type":"object","properties":[{"name":"type","type":"string","description":"ack","required":false},{"name":"payload","type":"object","required":false,"properties":[{"name":"message","type":"string","required":false}]}]}],"headers":[],"jsonPayloadSchema":{"type":"object","properties":{"type":{"type":"string","const":"ack","x-parser-schema-id":"\u003canonymous-schema-10>"},"payload":{"type":"object","properties":{"message":{"type":"string","x-parser-schema-id":"\u003canonymous-schema-12>"}},"x-parser-schema-id":"\u003canonymous-schema-11>"}},"x-parser-schema-id":"AckPayload"},"title":"TTS Acknowledgment","description":"Server acknowledges the TTS request","example":"{\n \"type\": \"ack\",\n \"payload\": {\n \"message\": \"Real time text to speach connection establesh\"\n }\n}","bindings":[],"extensions":[{"id":"x-parser-unique-object-id","value":"ttsAck"}]},{"id":"ttsAudioChunk","contentType":"application/octet-stream","payload":[{"type":"string","format":"binary","description":"Binary audio data chunk","x-parser-schema-id":"\u003canonymous-schema-13>","name":"TTS Audio Chunk"}],"headers":[],"jsonPayloadSchema":{"type":"string","format":"binary","description":"Raw audio bytes. Buffer multiple chunks to reconstruct the complete audio file.","x-parser-schema-id":"\u003canonymous-schema-13>"},"title":"TTS Audio Chunk","description":"Binary audio data chunk","example":"{}","bindings":[],"extensions":[{"id":"x-parser-unique-object-id","value":"ttsAudioChunk"}]},{"id":"ttsEnd","contentType":"application/json","payload":[{"name":"TTS Stream End","description":"Signals the end of the audio stream","type":"object","properties":[{"name":"type","type":"string","description":"end","required":false},{"name":"payload","type":"object","required":false,"properties":[{"name":"message","type":"string","required":false}]}]}],"headers":[],"jsonPayloadSchema":{"type":"object","properties":{"type":{"type":"string","const":"end","x-parser-schema-id":"\u003canonymous-schema-14>"},"payload":{"type":"object","properties":{"message":{"type":"string","x-parser-schema-id":"\u003canonymous-schema-16>"}},"x-parser-schema-id":"\u003canonymous-schema-15>"}},"x-parser-schema-id":"EndPayload"},"title":"TTS Stream End","description":"Signals the end of the audio stream","example":"{\n \"type\": \"end\",\n \"payload\": {\n \"message\": \"End of TTS stream\"\n }\n}","bindings":[],"extensions":[{"id":"x-parser-unique-object-id","value":"ttsEnd"}]},{"id":"errorResponse","contentType":"application/json","payload":[{"name":"Error Response","description":"Error message from the server","type":"object","properties":[{"name":"type","type":"string","description":"error","required":false},{"name":"payload","type":"object","required":false,"properties":[{"name":"message","type":"string","description":"Error description","required":false}]}]}],"headers":[],"jsonPayloadSchema":{"type":"object","properties":{"type":{"type":"string","const":"error","x-parser-schema-id":"\u003canonymous-schema-17>"},"payload":{"type":"object","properties":{"message":{"type":"string","description":"Error description","x-parser-schema-id":"\u003canonymous-schema-19>"}},"x-parser-schema-id":"\u003canonymous-schema-18>"}},"x-parser-schema-id":"ErrorPayload"},"title":"Error Response","description":"Error message from the server","example":"{\n \"type\": \"error\",\n \"payload\": {\n \"message\": \"Invalid payload for message type: tts\"\n }\n}","bindings":[],"extensions":[{"id":"x-parser-unique-object-id","value":"errorResponse"}]}],"bindings":[],"extensions":[{"id":"x-parser-unique-object-id","value":"tts"}]}],"sendMessages":[{"id":"ttsRequest","contentType":"application/json","payload":[{"name":"TTS Request","description":"Request to convert text to speech","type":"object","properties":[{"name":"type","type":"string","description":"Message type identifier","required":true},{"name":"payload","type":"object","required":true,"properties":[{"name":"text","type":"string","description":"The text to synthesize into speech. Maximum 2000 characters.","required":true},{"name":"speaker","type":"string","description":"Voice name (e.g. 'Amjad') or the UUID of a custom cloned voice. Pick a speaker that matches the chosen dialect.","required":true},{"name":"dialect","type":"string","description":"Dialect to synthesize. Voice examples per dialect: pls (Palestinian) — Amjad, Layan; egy (Egyptian) — Mariam, Samir; syr (Syrian) — Dalal, Mais; irq (Iraqi) — Lyali, Fatma; jor (Jordanian) — Lana, Jasem; leb (Lebanese) — Carla, Majd; ksa (Saudi) — Hiba, Fahd; uae (Emirati) — Salma, Dima; bah (Bahraini) — Mazen, Ruba; qat (Qatari) — Deema, Faisal; kuw (Kuwaiti) — Mai, Hatem; oma (Omani) — Aisha, Jaber; msa (MSA / Fusha) — Salem, Tamim; ar-sa (Arabic – Gulf) — Khalid, Rahma; en (English) — Emma, James.","enumValues":["pls","egy","syr","irq","jor","leb","ksa","uae","bah","qat","kuw","oma","msa","ar-sa","en"],"required":false},{"name":"languageId","type":"string","description":"Language code. Defaults to 'ar' (Arabic).","required":false},{"name":"mulaw","type":"boolean","description":"Whether to use mu-law audio encoding.","required":false},{"name":"sampleRate","type":"string","description":"Output sample rate of the PCM audio. Defaults to '16k'. Only applies to PCM output — cannot be combined with mulaw (mu-law output is always 8 kHz).","enumValues":["8k","16k"],"required":false},{"name":"expressiveness","type":"number","description":"Controls how expressive the generated speech sounds. 0 is flat and monotone, 1 is the natural default, and 2 is highly expressive.","required":false}]}]}],"headers":[],"jsonPayloadSchema":{"type":"object","required":["type","payload","dialect","languageId","mulaw"],"properties":{"type":{"type":"string","const":"tts","description":"Message type identifier","x-parser-schema-id":"\u003canonymous-schema-1>"},"payload":{"type":"object","required":["text","speaker"],"properties":{"text":{"type":"string","minLength":1,"maxLength":2000,"description":"The text to synthesize into speech. Maximum 2000 characters.","x-parser-schema-id":"\u003canonymous-schema-3>"},"speaker":{"type":"string","minLength":1,"description":"Voice name (e.g. 'Amjad') or the UUID of a custom cloned voice. Pick a speaker that matches the chosen dialect.","x-parser-schema-id":"\u003canonymous-schema-4>"},"dialect":{"type":"string","enum":["pls","egy","syr","irq","jor","leb","ksa","uae","bah","qat","kuw","oma","msa","ar-sa","en"],"description":"Dialect to synthesize. Voice examples per dialect: pls (Palestinian) — Amjad, Layan; egy (Egyptian) — Mariam, Samir; syr (Syrian) — Dalal, Mais; irq (Iraqi) — Lyali, Fatma; jor (Jordanian) — Lana, Jasem; leb (Lebanese) — Carla, Majd; ksa (Saudi) — Hiba, Fahd; uae (Emirati) — Salma, Dima; bah (Bahraini) — Mazen, Ruba; qat (Qatari) — Deema, Faisal; kuw (Kuwaiti) — Mai, Hatem; oma (Omani) — Aisha, Jaber; msa (MSA / Fusha) — Salem, Tamim; ar-sa (Arabic – Gulf) — Khalid, Rahma; en (English) — Emma, James.","x-parser-schema-id":"\u003canonymous-schema-5>"},"languageId":{"type":"string","default":"ar","description":"Language code. Defaults to 'ar' (Arabic).","x-parser-schema-id":"\u003canonymous-schema-6>"},"mulaw":{"type":"boolean","default":false,"description":"Whether to use mu-law audio encoding.","x-parser-schema-id":"\u003canonymous-schema-7>"},"sampleRate":{"type":"string","enum":["8k","16k"],"default":"16k","description":"Output sample rate of the PCM audio. Defaults to '16k'. Only applies to PCM output — cannot be combined with mulaw (mu-law output is always 8 kHz).","x-parser-schema-id":"\u003canonymous-schema-8>"},"expressiveness":{"type":"number","minimum":0,"maximum":2,"default":1,"description":"Controls how expressive the generated speech sounds. 0 is flat and monotone, 1 is the natural default, and 2 is highly expressive.","x-parser-schema-id":"\u003canonymous-schema-9>"}},"x-parser-schema-id":"\u003canonymous-schema-2>"}},"x-parser-schema-id":"TTSRequestPayload"},"title":"TTS Request","description":"Request to convert text to speech","example":"{\n \"type\": \"tts\",\n \"payload\": {\n \"text\": \"مرحبا بك في خدمة همسة\",\n \"speaker\": \"Amjad\",\n \"dialect\": \"pls\",\n \"languageId\": \"ar\",\n \"mulaw\": false,\n \"sampleRate\": \"16k\",\n \"expressiveness\": 1\n }\n}","bindings":[],"extensions":[{"id":"x-parser-unique-object-id","value":"ttsRequest"}]}],"receiveMessages":[{"id":"ttsAck","contentType":"application/json","payload":[{"name":"TTS Acknowledgment","description":"Server acknowledges the TTS request","type":"object","properties":[{"name":"type","type":"string","description":"ack","required":false},{"name":"payload","type":"object","required":false,"properties":[{"name":"message","type":"string","required":false}]}]}],"headers":[],"jsonPayloadSchema":{"type":"object","properties":{"type":{"type":"string","const":"ack","x-parser-schema-id":"\u003canonymous-schema-10>"},"payload":{"type":"object","properties":{"message":{"type":"string","x-parser-schema-id":"\u003canonymous-schema-12>"}},"x-parser-schema-id":"\u003canonymous-schema-11>"}},"x-parser-schema-id":"AckPayload"},"title":"TTS Acknowledgment","description":"Server acknowledges the TTS request","example":"{\n \"type\": \"ack\",\n \"payload\": {\n \"message\": \"Real time text to speach connection establesh\"\n }\n}","bindings":[],"extensions":[{"id":"x-parser-unique-object-id","value":"ttsAck"}]},{"id":"ttsAudioChunk","contentType":"application/octet-stream","payload":[{"type":"string","format":"binary","description":"Binary audio data chunk","x-parser-schema-id":"\u003canonymous-schema-13>","name":"TTS Audio Chunk"}],"headers":[],"jsonPayloadSchema":{"type":"string","format":"binary","description":"Raw audio bytes. Buffer multiple chunks to reconstruct the complete audio file.","x-parser-schema-id":"\u003canonymous-schema-13>"},"title":"TTS Audio Chunk","description":"Binary audio data chunk","example":"{}","bindings":[],"extensions":[{"id":"x-parser-unique-object-id","value":"ttsAudioChunk"}]},{"id":"ttsEnd","contentType":"application/json","payload":[{"name":"TTS Stream End","description":"Signals the end of the audio stream","type":"object","properties":[{"name":"type","type":"string","description":"end","required":false},{"name":"payload","type":"object","required":false,"properties":[{"name":"message","type":"string","required":false}]}]}],"headers":[],"jsonPayloadSchema":{"type":"object","properties":{"type":{"type":"string","const":"end","x-parser-schema-id":"\u003canonymous-schema-14>"},"payload":{"type":"object","properties":{"message":{"type":"string","x-parser-schema-id":"\u003canonymous-schema-16>"}},"x-parser-schema-id":"\u003canonymous-schema-15>"}},"x-parser-schema-id":"EndPayload"},"title":"TTS Stream End","description":"Signals the end of the audio stream","example":"{\n \"type\": \"end\",\n \"payload\": {\n \"message\": \"End of TTS stream\"\n }\n}","bindings":[],"extensions":[{"id":"x-parser-unique-object-id","value":"ttsEnd"}]},{"id":"errorResponse","contentType":"application/json","payload":[{"name":"Error Response","description":"Error message from the server","type":"object","properties":[{"name":"type","type":"string","description":"error","required":false},{"name":"payload","type":"object","required":false,"properties":[{"name":"message","type":"string","description":"Error description","required":false}]}]}],"headers":[],"jsonPayloadSchema":{"type":"object","properties":{"type":{"type":"string","const":"error","x-parser-schema-id":"\u003canonymous-schema-17>"},"payload":{"type":"object","properties":{"message":{"type":"string","description":"Error description","x-parser-schema-id":"\u003canonymous-schema-19>"}},"x-parser-schema-id":"\u003canonymous-schema-18>"}},"x-parser-schema-id":"ErrorPayload"},"title":"Error Response","description":"Error message from the server","example":"{\n \"type\": \"error\",\n \"payload\": {\n \"message\": \"Invalid payload for message type: tts\"\n }\n}","bindings":[],"extensions":[{"id":"x-parser-unique-object-id","value":"errorResponse"}]}],"extensions":[{"id":"x-parser-unique-object-id","value":"tts"}],"securitySchemes":[{"id":"apiKey","name":"api_key","type":"httpApiKey","description":"API key passed as query parameter or X-Api-Key header","in":"query","extensions":[]}]},"channelId":"tts","metadata":{"id":3052,"subdomain":"hamsa-452fa79a","eTag":"\"1faf5cc89ab0f9a6e6386266396d1f52\"","originalFileLocation":"websocket/asyncapi-tts.json","uuid":"bc95ae1e-7034-480c-b425-612b0a09178b","source":"LOCAL_FILE","createdAt":"2026-01-30T14:52:34.412Z","updatedAt":"2026-08-04T14:43:19.953Z","deletedAt":null,"retiredAt":null,"retiredByDeploymentHistoryId":null}},"subdomain":"hamsa-452fa79a","siteName":"Hamsa API","title":"Text-to-Speech - Hamsa API","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-08-04T14:43:40.181Z","originalFileLocation":"websocket/websocket-tts.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=\"Convert text to streaming audio via WebSocket\">\u003cmeta data-mint-head name=\"application-name\" content=\"Hamsa API\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/hamsa-452fa79a/11pr1mz1Eztynfhz/_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/hamsa-452fa79a/11pr1mz1Eztynfhz/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/hamsa-452fa79a/11pr1mz1Eztynfhz/_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/hamsa-452fa79a/11pr1mz1Eztynfhz/_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/hamsa-452fa79a/11pr1mz1Eztynfhz/_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/hamsa-452fa79a/11pr1mz1Eztynfhz/_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/hamsa-452fa79a/11pr1mz1Eztynfhz/_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/hamsa-452fa79a/11pr1mz1Eztynfhz/_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/hamsa-452fa79a/11pr1mz1Eztynfhz/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Text-to-Speech - Hamsa API\">\u003cmeta data-mint-head property=\"og:description\" content=\"Convert text to streaming audio via WebSocket\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Hamsa API\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.tryhamsa.com/websocket/websocket-tts\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://hamsa-452fa79a.mintlify.site/_mintlify/api/og/v2?division=WebSocket+Playgrounds\u0026amp;title=Text-to-Speech\u0026amp;description=Convert+text+to+streaming+audio+via+WebSocket\u0026amp;theme=36084cdf444b71ec535ab394\u0026amp;signature=a4e99a5c2013c00dd65caf885b3b70f538bad01bdcdf507f3721ab7bf28e6bbc\">\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=\"Text-to-Speech - Hamsa API\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Convert text to streaming audio via WebSocket\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://hamsa-452fa79a.mintlify.site/_mintlify/api/og/v2?division=WebSocket+Playgrounds\u0026amp;title=Text-to-Speech\u0026amp;description=Convert+text+to+streaming+audio+via+WebSocket\u0026amp;theme=36084cdf444b71ec535ab394\u0026amp;signature=a4e99a5c2013c00dd65caf885b3b70f538bad01bdcdf507f3721ab7bf28e6bbc\">\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/hamsa-452fa79a/11pr1mz1Eztynfhz/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Hamsa API\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#1B5E3A\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.tryhamsa.com/websocket/websocket-tts\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/websocket/websocket-tts.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.tryhamsa.com/#organization\",\"name\":\"Hamsa API\",\"url\":\"https://docs.tryhamsa.com\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/hamsa-452fa79a/B5KuRhzUCER4_1Wi/logo/hamsa_logo_light.svg?fit=max\u0026auto=format\u0026n=B5KuRhzUCER4_1Wi\u0026q=85\u0026s=2576c2f27fed68b31fa686aca13e6fbf\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.tryhamsa.com#website\",\"name\":\"Hamsa API\",\"url\":\"https://docs.tryhamsa.com\",\"publisher\":{\"@id\":\"https://docs.tryhamsa.com/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.tryhamsa.com/websocket/websocket-tts#webpage\",\"url\":\"https://docs.tryhamsa.com/websocket/websocket-tts\",\"name\":\"Text-to-Speech\",\"description\":\"Convert text to streaming audio via WebSocket\",\"dateModified\":\"2026-08-04T14:43:40.181Z\",\"isPartOf\":{\"@id\":\"https://docs.tryhamsa.com#website\"},\"breadcrumb\":{\"@id\":\"https://docs.tryhamsa.com/websocket/websocket-tts#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.tryhamsa.com/websocket/websocket-tts#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Hamsa API\",\"item\":\"https://docs.tryhamsa.com\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Text-to-Speech\",\"item\":\"https://docs.tryhamsa.com/websocket/websocket-tts\"}]},{\"@type\":[\"TechArticle\",\"APIReference\"],\"@id\":\"https://docs.tryhamsa.com/websocket/websocket-tts#apireference\",\"headline\":\"Text-to-Speech\",\"name\":\"Text-to-Speech\",\"description\":\"Convert text to streaming audio via WebSocket\",\"url\":\"https://docs.tryhamsa.com/websocket/websocket-tts\",\"mainEntityOfPage\":{\"@id\":\"https://docs.tryhamsa.com/websocket/websocket-tts#webpage\"},\"dateModified\":\"2026-08-04T14:43:40.181Z\",\"publisher\":{\"@id\":\"https://docs.tryhamsa.com/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.tryhamsa.com#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Hamsa API\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"Hamsa API","nav":{"global":null,"tabs":[{"tab":"Overview","icon":"list-timeline","pages":[{"title":"Overview","href":"/overview/introduction"}]},{"tab":"Text to Speech","icon":"message-waveform","pages":[{"title":"Text to Speech","href":"/text-to-speech/introduction"}]},{"tab":"Speech to Text","icon":"head-side-speak","pages":[{"title":"Speech to Text","href":"/speech-to-text/introduction"}]},{"tab":"Agents Platform","icon":"user-robot","pages":[{"title":"Agents Platform","href":"/agents/dashboard/introduction"}]},{"tab":"Media Platform","icon":"photo-film-music","pages":[{"title":"Media Platform","href":"/media/introduction"}]},{"tab":"Developers","icon":"square-terminal","pages":[{"title":"Developers","href":"/developers/apis/quick-start"}]},{"tab":"API Reference","icon":"code","pages":[{"title":"API Reference","href":"/api-reference/introduction"}]},{"tab":"WebSocket API","icon":"rocket-vertical","groups":[{"group":"overview","pages":[{"title":"Real-Time WebSocket API","description":"Connect to Hamsa's real-time WebSocket API for streaming Text-to-Speech and Speech-to-Text","href":"/websocket/websocket-api"}]},{"group":"WebSocket Playgrounds","pages":[{"title":"Text-to-Speech","asyncapi":"websocket/asyncapi-tts.json tts","href":"/websocket/websocket-tts"},{"title":"Speech-to-Text","description":"Transcribe audio to text via WebSocket","asyncapi":"websocket/asyncapi-stt.json stt","href":"/websocket/websocket-stt"}]}]},{"tab":"Changelog","icon":"rectangle-history-circle-user","pages":[{"title":"Changelog","href":"/changelog/main"}]}]},"basePath":"","title":"Text-to-Speech - Hamsa API","buildId":"dpl_BLQvU86QFwq3AhPofSTw6q8dGWKm","deploymentId":"dpl_BLQvU86QFwq3AhPofSTw6q8dGWKm","dynamics":["3b021dca80","a4b48b4bee","a9bb46feb3"],"chunks":["MessageExamples-Bo3-XOgK.js","CodeSnippet-D--dzvnl.js","Page-BeGvfmUE.js","utils-C2HkQgW0.js","cloneDeep-izs3Hzxb.js","_Uint8Array-BVIqJ90l.js","isObjectLike-C8vmzPEN.js","isArray-Dcu1dQ5t.js","getPastedJson-C-VECgcL.js","icon-BPq2-Mg3.js","MethodPill-D9J5cUHd.js","DuplicateIcon-BqHaxUnD.js","createIcon-CIbcZHp9.js","DynamicMarkdown-BKiHAm_d.js","getApiPlaygroundDisplay-CTo5Zn03.js","Markdown-CpxgzsKA.js","clsx-C5EfhVm0.js","lib-DuNMoZ05.js","lib-B8HbPgcC.js","html-void-elements-mCSPHezU.js","dist-CJ9Oly2E.js","katex-YMM-FMeD.js","marked.esm-CZWythHk.js","AssistantPageLink-Mk6P3qvh.js"]}