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

Dialogue · Multiple contexts

Manage independent contexts on one connection. A context can use one or more voices. Use it for dialogue with several speakers or for incremental single-voice input with V4 or V3 Turbo.
Supported models: myvocal_v3 (default), myvocal_v4 and myvocal_v3_turbo.
Before you start: obtain an enterprise api-key, an available voice and priority=dedicated_concurrency.
SDKs: Downloads and examples for Python, Java and Go.

Minimum message sequence#

Connect → register voices and send inputs → receive audio → close_context → wait for is_final → close_socket
Example connection (handshake header: api-key: YOUR_API_KEY):
wss://api.voicelibrary.co/enterprise/v1/text-to-dialogue/websocket/multi?model_id=myvocal_v4&priority=dedicated_concurrency&format=mp3_128
Create a context and send a line of text:
{"context_id":"demo","voices":["YOUR_VOICE_ID"],"inputs":[{"text":"你好,欢迎使用语音合成。","voice_id":"YOUR_VOICE_ID","new_turn":true}]}
Finish the context:
{"context_id":"demo","close_context":true}
Decode Base64 audio for each context_id and wait for is_final=true. When all tasks are complete, send {"close_socket":true} and wait for a normal close. You can also use close_socket to finish all contexts together.
How dialogue differs from standard multi-context TTS
Dialogue uses inputs. Its close_context processes remaining text without a separate flush. Standard multi-context TTS uses different messages and a different completion sequence.

Choose a model#

See Models for capabilities and Supported languages for language codes.

1. Connection#

Connection URL:
wss://api.voicelibrary.co/enterprise/v1/text-to-dialogue/websocket/multi
Handshake header:
api-key
Type: string
Required: yes
Location: WebSocket handshake header
Purpose: MyVocal enterprise API key
Keep it out of client-side source code, logs and public repositories.
This endpoint supports:
Models: myvocal_v3 (default), myvocal_v4, myvocal_v3_turbo
Concurrency: dedicated_concurrency

2. Query parameters#

Suggested connection:
?priority=dedicated_concurrency
&model_id=myvocal_v3
&format=mp3_128
&language_code=en
&timestamps=true
&text_normalization=auto
&seed=618021
&enable_logging=true
Send the connection URL and query parameters on one line.

priority#

Type: string
Required: yes
Allowed value: dedicated_concurrency only
Uses dedicated concurrency.

model_id#

Type: string
Required: no
Default: myvocal_v3
Allowed values: myvocal_v3, myvocal_v4, myvocal_v3_turbo
Selects the dialogue synthesis model for this connection. Open another connection to change models.

format#

Type: string
Required: no
Default: mp3_128
Selects the audio encoding, sample rate and MP3 bitrate.
Allowed values:
MP3:mp3_64、mp3_96、mp3_128、mp3_192
PCM:pcm_8000、pcm_16000、pcm_22050、pcm_24000、
pcm_44100
G.711 μ-law:ulaw_8000
For precise turn boundaries, use PCM. MP3 chunk boundaries may not coincide with turn boundaries.

language_code#

Type: string
Optional. If omitted, the model selects a language from the input text.
Format: a supported two- or three-letter code, such as Mandarin zh, English en, Cantonese yue or Filipino fil.
Location: connection URL query. Applies to that connection.
Sets language and pronunciation. Supply the text in that language. The field does not translate it.
myvocal_v4 and myvocal_v3_turbo support the same 94 output languages, including Mandarin zh, Cantonese yue, English en, Japanese ja and Korean ko. See Output languages for the complete list.

timestamps#

Type: boolean
Required: no
Default: false
Set to true to receive character timings with audio messages.

text_normalization#

Type: string
Required: no
Default: on
Allowed values: auto, on, off
Controls spoken normalization of numbers, dates and abbreviations.
Values:
auto: let the system choose whether to normalize.
on: always normalize.
off: disable normalization.

seed#

Type: integer
Required: no
Range: 1 to 4294967295
Improves consistency for the same text and settings.
Reusing a seed can produce similar speech without guaranteeing identical bytes. If you omit it,
the service chooses a new seed.

enable_logging#

Type: boolean
Required: no
Default: true
Controls whether the request retains generation history.
With false, the request does not retain history and related history features are unavailable.
Availability depends on your enterprise account configuration.

3. Message sequence#

1.
Open the WebSocket connection.
2.
For a new context_id, send its first message to register voices and optional settings.
3.
Send additional inputs.
4.
Receive audio chunks labeled with the corresponding context_id.
5.
Use flush to process currently buffered text immediately.
6.
Use close_context to finish one context.
7.
Use close_socket to finish every context and close the connection.
8.
On normal completion, the server closes the WebSocket with code 1000.

4. Create a context#

The first message for a context_id must contain voices:
{
  "context_id": "scene-001",
  "voices": [
    "YOUR_VOICE_ID_A",
    "YOUR_VOICE_ID_B"
  ],
  "voice_settings": {
    "stability": 0.5
  },
  "inputs": [
    {
      "text": "Hello, how may I help you today?",
      "voice_id": "YOUR_VOICE_ID_A",
      "new_turn": true
    }
  ]
}

context_id#

Type: string
Required: yes
A client-supplied identifier distinguishing contexts on the same connection.
Must be a nonempty string.
Include context_id in every message except a message containing only close_socket.

voices#

Type: string[]
Required in the first message of the context only.
Enter 1 to 10 voice IDs.
Registers the MyVocal voice IDs available to this context.
Each subsequent inputs[].voice_id must refer to a registered voice.

voice_settings#

Type: object
Required: no
Location: the first context message only.
Use the stability setting described below. The HTTP fields similarity_boost, style and speed do not belong in this context configuration.

voice_settings.stability#

Type: number
Required: no
Range: 0 to 1
Controls generation stability.
Lower values generally yield greater variation in delivery. Higher values give more consistent results.

5. Send more text#

After creating a context, send inputs as often as needed:
{
  "context_id": "scene-001",
  "inputs": [
    {
      "text": "Sure, I can check that for you.",
      "voice_id": "YOUR_VOICE_ID_A"
    }
  ]
}

inputs#

Type: object[]
Required: no
Appends one or more text inputs to the current context.

inputs[].text#

Type: string
Required: yes
Text to synthesize.
Send natural phrases or complete sentences as they become available, retaining punctuation for natural delivery
and responsive streaming.

inputs[].voice_id#

Type: string
Required: yes
Selects the voice for this input.
Must be registered in the current context’s voices.

inputs[].new_turn#

Type: boolean
Required: no
Default: false
Set to true to end the current delivery segment and start a new speaking turn.
Changing voice_id also starts a new turn.

6. Control messages#

Process buffered text immediately#

{
  "context_id": "scene-001",
  "flush": true
}
flush forces the service to process the current context’s buffered text and keeps the context open.
You can continue sending inputs afterward.

Keep a context alive#

{
  "context_id": "scene-001",
  "keep_alive": true
}
keep_alive resets the context’s 20-second idle timer without generating audio.

Close one context#

{
  "context_id": "scene-001",
  "close_context": true
}
close_context processes the remaining text, sends is_final for that context,
and closes it. Other contexts continue.
A separate flush before close_context is unnecessary.

Close the connection#

{
  "close_socket": true
}
close_socket processes and closes all contexts. When every active context has finished, the server
closes the WebSocket normally with code 1000.

7. Server messages#

Audio chunks#

{
  "audio": "<BASE64_AUDIO>",
  "context_id": "scene-001"
}
audio: Base64-encoded audio chunk.
context_id: context that owns the audio.
Decode and assemble chunks in arrival order within each context_id.

End of turn audio#

{
  "context_id": "scene-001",
  "is_final_audio_for_turn": true
}
All audio for the current turn has been sent. The context may remain open.

End of context#

{
  "context_id": "scene-001",
  "is_final": true
}
All remaining audio for this context has been sent and the context is closed.

Character timings#

When timestamps=true, an audio message may also include:
{
  "audio": "<BASE64_AUDIO>",
  "context_id": "scene-001",
  "alignment": {
    "chars": ["H", "e", "l", "l", "o"],
    "char_start_times_ms": [0, 80, 150, 220, 300],
    "char_durations_ms": [80, 70, 70, 80, 90]
  },
  "normalized_alignment": {
    "chars": ["H", "e", "l", "l", "o"],
    "char_start_times_ms": [0, 80, 150, 220, 300],
    "char_durations_ms": [80, 70, 70, 80, 90]
  }
}
alignment: character timings for the original text.
normalized_alignment: character timings for normalized text.
chars: sequence of characters.
char_start_times_ms: start time for each character, in milliseconds.
char_durations_ms: duration of each character, in milliseconds.

8. Limits and lifecycle#

Up to five contexts may be active on one WebSocket connection.
Closing a context frees its slot.
Register up to ten voices per context.
After 20 seconds of inactivity, a context processes the remaining text, sends is_final and closes.
An idle context closing does not affect other contexts.
Set voice_settings only in the first message for a context.
A protocol or parameter error returns a JSON error and closes the connection with code 1008.
A normal close uses code 1000.

9. Error responses#

Parameter error example:
{
  "code": "INVALID_PARAMETER",
  "field": "voice_settings.stability",
  "message": "voice_settings.stability must be between 0 and 1"
}
Concurrency error example:
{
  "error": "INVALID_PRIORITY",
  "message": "This WebSocket requires priority=dedicated_concurrency"
}
Common errors:
INVALID_PARAMETER: invalid parameter, message structure or field value.
INVALID_PRIORITY: the request did not use dedicated_concurrency.
DEDICATED_CONCURRENCY_REQUIRED: the account has no available dedicated concurrency.
MAX_CONTEXT_LIMIT_EXCEEDED: more than five active contexts on one connection.
INSUFFICIENT_QUOTA: insufficient account quota.
STREAMING_SERVICE_ERROR: speech generation is temporarily unavailable.
On error, record the error type and field, stop sending further messages on the connection,
and wait for or handle the server’s Close frame.

10. Usage#

See Get master key usage for character counts and fields.

Path#

wss://api.voicelibrary.co/enterprise/v1/text-to-dialogue/websocket/multi

Handshake parameter reference#

LocationParameterTypeRequiredDescription
Headerapi-keystringYesMyVocal enterprise API key, sent in the WebSocket handshake header.
Querymodel_idstringNoDialogue model for the connection. V4 and V3 Turbo use this dialogue WebSocket protocol. Allowed values: myvocal_v3, myvocal_v4, myvocal_v3_turbo. If you omit this parameter, the default model is myvocal_v3.
Querylanguage_codestringNoOptional two- or three-letter language code, for example zh (Mandarin), yue (Cantonese) or fil (Filipino). If omitted, infer the language from the text. V4 and V3 Turbo support the same 94 languages.
上一页
Standard TTS · Multiple contexts
下一页
Usage and request history
Built with