1. WebSocket synthesis
MyVocal AI语音大模型API文档
English
  • 中文
  • English
  • 文字转语音大模型
    • API reference
      • Voice management
        • List voices
        • Create a voice
        • Delete a voice
      • HTTP synthesis
        • Streaming HTTP synthesis
        • Non-streaming HTTP synthesis
      • WebSocket synthesis
        • Standard TTS · Single connection
        • Standard TTS · Multiple contexts
        • Dialogue · Multiple contexts
      • Usage and request history
        • Get master key usage
        • Look up a request by ID
        • Get usage by voice
      • Sub-key management
        • Create a sub-key
        • List sub-keys
        • Get sub-key details
        • Update a sub-key
        • Get sub-key usage
    • Overview and quickstart
      • Models
      • Choose a model and endpoint
      • Supported languages
      • Audio formats and playback
      • FAQ
      • SDKs and examples
  • 金融行业定制TTS模型
    • Skyblight text to speech
      • Streaming text to speech
      • Non-streaming text to speech
      • List voices
      • Delete a voice
      • Create a voice
      • Get usage
    • Full-duplex communication
      • WebSocket integration guide
      • V2 bidirectional streaming synthesis (WebSocket)
  • 语音转文字ASR
    • Overview and quickstarts
      • Realtime transcription quickstart
      • File transcription quickstart
      • Models and capabilities
      • Changelog
    • API reference
      • Realtime transcription over WebSocket
      • Create a file transcription
      • Get ASR usage
  • 企业客户声音定制服务
    • Your custom brand voice
  1. WebSocket synthesis

Standard TTS · Multiple contexts

Manage independent speech tasks on one connection. Identify each task by context_id.
Supported models: multilingual_v2 and flash_v2_5.
SDKs: Downloads and examples for Python, Java and Go.

Model compatibility#

For V3, V4 or V3 Turbo, use the dialogue endpoint. Standard TTS does not support those models.

Minimum message sequence#

Connect → initialize a context → send text → flush → close_context → wait for context final

Endpoint#

Automatic selection
wss://api.voicelibrary.co/enterprise/v1/tts/{voice_id}/websocket/multi
United States
wss://api.us.voicelibrary.co/enterprise/v1/tts/{voice_id}/websocket/multi
Ireland
wss://api.eu.voicelibrary.co/enterprise/v1/tts/{voice_id}/websocket/multi
Japan
wss://api.jp.voicelibrary.co/enterprise/v1/tts/{voice_id}/websocket/multi
Replace {voice_id} in the path and include the following WebSocket handshake header:
api-key: <YOUR_API_KEY>
Send the API key only in the header. Keep it out of URLs, logs and client-side source code.

Handshake parameters#

model_id#

Required string. Use flash_v2_5 or multilingual_v2. This endpoint does not support myvocal_v3.

priority#

Required string. Set to dedicated_concurrency.

format#

Optional string. Output format, default pcm_16000. See the parameter table for supported values.

idleTimeout#

Optional integer. Context idle timeout in seconds, default 20, range 1..180.

language_code#

Optional string. A two- or three-letter lowercase code supported by the model, such as en or zh.

Timestamps#

Optional boolean. Request timestamps or alignment information.

directStreaming#

Optional boolean. Request direct audio streaming. Accept both JSON with Base64 audio and binary frames.

seed#

Optional integer, 0..4294967295. A seed improves consistency with identical settings. Byte-identical audio is not guaranteed.

auto_mode#

Optional boolean. Enables automatic realtime generation.
The URL parameter is format. If your SDK exposes output_format, use that option and avoid supplying conflicting values.
Example:
wss://api.voicelibrary.co/enterprise/v1/tts/{voice_id}/websocket/multi?model_id=flash_v2_5&priority=dedicated_concurrency&format=pcm_16000&idleTimeout=20&language_code=zh

Languages for language_code#

See Standard TTS WebSocket languages by model.

Context rules#

A nonempty context_id is required.
The first message initializes the context.
Send voice_settings, previous_text, next_text and generation_config in the initialization message.
Set voice_settings only in the first message for that context.
One connection can have up to five active contexts.
Normal completion: send text, flush, send close_context, then wait for that context’s final event.
close_context does not implicitly flush. Closing without flushing interrupts or cancels the task and may discard buffered audio.

Client messages#

1. Initialize the context#

{
  "context_id": "ctx_001",
  "text": " ",
  "previous_text": "Optional previous sentence",
  "next_text": "Optional next sentence",
  "voice_settings": {
    "stability": 0.5,
    "similarity_boost": 0.75,
    "style": 0.3,
    "use_speaker_boost": true
  },
  "generation_config": {
    "synthesisSchedule": [120, 160, 250, 290]
  }
}
stability, similarity_boost and style range from 0..1.

2. Send text#

{
  "context_id": "ctx_001",
  "text": "Hello world.",
  "flush": false
}

3. Flush Context#

{
  "context_id": "ctx_001",
  "text": "",
  "flush": true
}

4. Close the context normally#

Flush first, then send:
{
  "context_id": "ctx_001",
  "close_context": true
}
Wait for is_final=true or isFinal=true for that context.

5. Interrupt or cancel#

To interrupt immediately, send close_context=true. This ends the context. Any text that has not been flushed may be only partially rendered.

6. Keep a context alive#

{
  "context_id": "ctx_001",
  "text": ""
}

7. Close the WebSocket#

{
  "close_socket": true
}

Server responses#

JSON audio chunk:
{
  "context_id": "ctx_001",
  "audio": "BASE64_AUDIO_DATA",
  "is_final": false
}
Context completion:
{
  "context_id": "ctx_001",
  "is_final": true
}
Accept both context_id and contextId, and both is_final and isFinal.
A final frame may have empty, missing or null audio. It still signals successful completion for that context.
JSON audio is Base64. Binary frames may also arrive. Only route binary audio to a context when the protocol identifies the context it belongs to.
Timing and alignment information may appear in timestamps or alignment.
A terminal error for one context should leave others running. A connection-level error ends the connection and all active contexts.
Errors can include error and message. Handle unfamiliar codes and retain error details for troubleshooting.
After reconnection, do not automatically replay submitted text. Doing so can produce duplicate playback.

Call sequence#

connect -> initialize context -> send text -> flush -> close_context -> wait context final
Before closing the socket, wait for final for each context that should complete. Contexts you want to cancel may be closed immediately.

Path#

wss://api.voicelibrary.co/enterprise/v1/tts/{voice_id}/websocket/multi

Handshake parameter reference#

LocationParameterTypeRequiredDescription
Querymodel_idstringYesTTS model ID. Choose a model supported by this protocol. Allowed values: flash_v2_5, multilingual_v2.
QueryprioritystringYesDedicated concurrency is required. Allowed values: dedicated_concurrency.
QueryformatstringNoThe wire parameter is format and defaults to pcm_16000. Some SDKs call this option output_format. Allowed values: mp3_44100_64, mp3_44100_96, mp3_44100_128, mp3_44100_192, pcm_8000, pcm_16000, pcm_22050, pcm_24000, pcm_44100, ulaw_8000.
QueryidleTimeoutintegerNoContext idle timeout in seconds. Default: 20. Range: 1–180.
Querylanguage_codestringNoOptional language code. Standard TTS supports 29 languages with multilingual_v2 and 32 with flash_v2_5. Check availability for your model. Allowed values: en, ja, zh, de, hi, fr, ko, pt, it, es, id, nl, tr, fil, pl, sv, bg, ro, ar, cs, el, fi, hr, ms, sk, da, ta, uk, ru, hu, no, vi.
QueryTimestampsbooleanNoRequest timestamps or alignment information.
QuerydirectStreamingbooleanNoRequest direct audio streaming. Accept both JSON with Base64 audio and binary WebSocket frames.
QueryseedintegerNoAn integer seed helps reproduce similar results. Identical audio is not guaranteed. Range: 0–4294967295. Example value: 12345.
Queryauto_modebooleanNoEnable automatic realtime generation.
Pathvoice_idstringYesMyVocal voice ID.
Headerapi-keystringYesMyVocal enterprise API key, sent in the WebSocket handshake header.
上一页
Standard TTS · Single connection
下一页
Dialogue · Multiple contexts
Built with