WS wss://api.echonova.ai /v1/text-to-speech/stream
Keep one socket open and send a synthesize message for each sentence or reply. The server answers with start, then binary PCM16 frames, then done. Audio is generated a few seconds of speech at a time, so the first audio arrives well before the whole text is spoken. Only one synthesis runs at a time: send cancel, or a new synthesize, to stop the current one (barge-in). Each synthesize is charged per character when it starts; a cancelled synthesis is still charged.
Try it is not available here: a browser cannot send an API key on a WebSocket, so connect from your server. Read the streaming guide · Try voices in the portal
Messages you send synthesizeSpeak this text. Cancels any synthesis still running on this socket.
type string Required
synthesize
requestId string Optional
Your id for this synthesis, echoed in start, done, cancelled and error. Generated when you leave it out.
Up to 64 characters
text string Required
The text to speak, 1 to 500 characters.
1 to 500 characters
voiceId string Required
The id of a voice from List available voices. The voice fixes the dialect.
speed number Optional
How fast the voice speaks.
0.5 to 2 default 1
cfg number Optional
How closely the voice follows the text. Leave it at the default unless you are tuning.
1 to 5 default 2
numSteps integer Optional
Diffusion steps. More steps are slower and cleaner.
16, 32, 48, 64 or 128 default 48
tashkeel boolean Optional
Adds the vowel marks to Arabic text before it is read. Applies to Fusha voices only.
default false
normalize boolean Optional
Reads numbers, dates, times, money, units, URLs and e-mails the way a speaker of the voice's dialect says them.
default true
{
"type" : "synthesize" ,
"requestId" : "reply-1" ,
"text" : "أهلاً بك، كيف يمكنني مساعدتك اليوم؟" ,
"voiceId" : "66e5ef3a9c1d2b4f8a7e6c01"
} cancelStop the running synthesis. The server answers with cancelled and sends no more audio for it.
type string Required
cancel
{
"type" : "cancel"
} pingOptional keep-alive. The server answers with pong.
{
"type" : "ping"
} Messages you receive startSent before the first audio frame of a synthesis. Use its sampleRate to play the audio.
type string Required
start
requestId string Required
sampleRate integer Required
Sample rate of the audio frames, in Hz.
encoding string Required
pcm_s16le
channels integer Required
1
{
"type" : "start" ,
"requestId" : "reply-1" ,
"sampleRate" : 24000 ,
"encoding" : "pcm_s16le" ,
"channels" : 1
} audio Binary frame Binary frame of mono PCM16 little-endian audio at the sampleRate from start. Play frames in the order they arrive.
doneAll audio for the synthesis has been sent.
requestId string Required
durationSeconds number Required
Length of the audio sent, in seconds.
characters integer Required
Characters charged.
creditsConsumed number Required
Credits charged for this synthesis.
{
"type" : "done" ,
"requestId" : "reply-1" ,
"durationSeconds" : 2.9 ,
"characters" : 36 ,
"creditsConsumed" : 36
} cancelledThe synthesis stopped. No more audio follows for this requestId.
type string Required
cancelled
requestId string Required
{
"type" : "cancelled" ,
"requestId" : "reply-1"
} errorSomething went wrong. Fatal errors are followed by a close frame; others leave the socket open.
type string Required
error
requestId string Optional
Text to Speech only: the synthesis that failed.
code string Required
Machine-readable reason.
invalid_message, frame_too_large, validation_failed, voice_not_found, insufficient_balance, spending_limit or upstream_error
message string Required
Human-readable explanation.
{
"type" : "error" ,
"code" : "validation_failed" ,
"message" : "text must be shorter than or equal to 500 characters"
} pongThe answer to ping.
{
"type" : "pong"
} Close codes
1000 Normal You sent stop, or you closed the socket.
1001 Going away The server is restarting; reconnect.
1008 Policy violation A frame was not valid JSON, was an unknown type, or was larger than 64 KiB.
1009 Message too big A frame was larger than 1 MiB; the socket closes without an error message.
1011 Server error Speech to Text: the speech service failed; reconnect and retry. On Text to Speech a failed synthesis sends error and the socket stays open.
4002 Insufficient balance The workspace ran out of credits mid-session.
4008 Timeout No frame for 120 seconds, or the session reached its maximum length.
4029 Spending limit The key reached its Credit Limit mid-session. Limits
Text length 500 characters per synthesize message.
Syntheses at a time 1 per socket; a new synthesize cancels the current one.
Session length 30 minutes.
Idle timeout 120 seconds without any frame.
Concurrent streams 10 open streams per workspace, STT and TTS together.
Connection rate 100 connection attempts per minute per key. Handshake errors Plain HTTP answers to the upgrade request, in the usual envelope. Nothing is charged. All errors
401 Unauthorized When. The Authorization header is missing or is not Bearer ek_..., no key matches the token, or the key is deleted, disabled or its account is closed.
Fix. Send Authorization: Bearer ek_... with an enabled key from this environment.
402 Insufficient subscription balance When. The workspace balance is empty.
Fix. Add credits to the workspace.
403 This API key does not have access to Text-to-Speech services When. The key is restricted and Text to Speech is not among its services.
Fix. Edit the key and grant Text to Speech, or use another key.
403 Subscription expired or inactive When. The subscription is in a state other than active or trial.
Fix. Renew the subscription.
403 Subscription not found When. The workspace that owns the key has no subscription.
Fix. Check the workspace's plan in the portal.
429 ThrottlerException: Too Many Requests When. The key opened more than 100 connections in 60 seconds.
Fix. Wait Retry-After seconds, then reconnect.
429 Too many concurrent streams When. The workspace already has 10 streams open.
Fix. Close a stream, or reuse one socket for many syntheses.
429 Monthly spending limit exhausted When. The key has reached its Credit Limit for this billing cycle.
Fix. Raise or clear the limit on the key, or wait for the next cycle.
503 Streaming is not enabled When. Streaming is turned off on this environment.
Fix. Contact support.