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 · Single connection

Send text incrementally on one connection for a single speech task.
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 → send text → send empty text → wait for final → disconnect

Endpoint#

Automatic selection
wss://api.voicelibrary.co/enterprise/v1/tts/{voice_id}/websocket
United States
wss://api.us.voicelibrary.co/enterprise/v1/tts/{voice_id}/websocket
Ireland
wss://api.eu.voicelibrary.co/enterprise/v1/tts/{voice_id}/websocket
Japan
wss://api.jp.voicelibrary.co/enterprise/v1/tts/{voice_id}/websocket
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#

Required string. Select an output audio format from the endpoint’s enumerated values.

idleTimeout#

Optional integer. Idle timeout in seconds, from 1..180.

language_code#

Optional string. A nonempty language 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. The client must 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.
Example:
wss://api.voicelibrary.co/enterprise/v1/tts/{voice_id}/websocket?model_id=flash_v2_5&priority=dedicated_concurrency&format=pcm_16000&idleTimeout=120&language_code=zh

Languages for language_code#

See Standard TTS WebSocket languages by model.

Client messages#

1. Initialize#

Initialize once per connection. Omitting text is equivalent to sending a single space.
{
  "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. generation_config.synthesisSchedule is an array of positive integers controlling when accumulated text triggers generation. Test the schedule for latency and quality. The example is not a fixed server default.

2. Send text#

{
  "text": "Hello world.",
  "earlyGeneration": false
}
Send one or more nonempty text fragments for the task.

3. Finish the current task#

{
  "text": ""
}
After sending the message, wait for isFinal=true or is_final=true.

4. Flush buffered text#

{
  "text": "",
  "flush": true
}
flush=true requests output for buffered text and may return audio without final. To finish the task, send {"text":""} as in the previous step and wait for final.

Server responses#

Example JSON audio chunk:
{
  "audio": "BASE64_AUDIO_DATA",
  "isFinal": false
}
Example final frame:
{
  "audio": "",
  "isFinal": true
}
audio contains Base64-encoded audio. Direct streaming may also return binary frames.
Even with directStreaming=true, the service may return JSON with Base64 audio. Handle the actual frame type.
Accept both isFinal and is_final.
On a final frame, audio may be empty, absent or null. The task has still completed successfully.
isFinal=null does not signal completion.
Timing or alignment data may appear in timestamps, alignment, normalizedAlignment or normalized_alignment.
Errors can include error and message. Handle unfamiliar codes and retain error details for troubleshooting.

Call sequence#

connect -> initialize -> send text fragment(s) -> {"text":""} -> wait final -> disconnect
Wait for final before disconnecting. The client does not need to send Ping. The server may close after final. For another task, open a new connection.

Official SDKs#

Download Python, Java and Go SDKs. Choose the standard single-connection TTS SDK.

Completion and shutdown#

isFinal=true or is_final=true signals successful synthesis for the task.
After final, the client may observe Close 1006 or no formal Close frame. The completed audio remains valid.
In Go, if Finish succeeded, a later Close cleanup error indicating a closed connection does not invalidate the synthesis. Do not replay the text.
None of the three SDKs reconnects or replays submitted text automatically.

Path#

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

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.
QueryformatstringYesOutput audio format. Select one of the supported values. 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.
QueryidleTimeoutintegerNoIdle timeout in seconds. 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.
上一页
WebSocket synthesis
下一页
Standard TTS · Multiple contexts
Built with