1. Full-duplex communication
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. Full-duplex communication

V2 bidirectional streaming synthesis (WebSocket)

Convert incoming text to speech as it arrives. The server buffers text, detects sentence boundaries and streams hex-encoded audio chunks in JSON messages.
Use for voice agents, live support, chatbots and playback during synthesis.
SDK downloads
Java: Download v1.0.2 ZIP · Source
Python: Download v1.0.2 ZIP · Source
Go: Download v1.0.2 ZIP · Source
These links point to official MyVocal GitHub releases. See each SDK’s README.md for installation and runtime requirements.

1. Connection#

Connection URL:
wss://openapi.myvocal.ai/v2/ai/speech/websocket
Use the full URL at the top of the page on a single line when connecting.
API-Key
Type: string
Required: yes
Location: WebSocket handshake header
MyVocal API key.
Keep the key out of logs and client-side source code.
This endpoint currently supports:
Model: Skyblight-Turbo
Concurrency: dedicated_concurrency

2. Message sequence#

1.
Connect and receive connected_success.
2.
Send task_start.
3.
Receive task_started.
4.
Send one or more task_continue messages.
5.
Receive sentence events and audio chunks.
6.
Optionally send task_flush to process buffered text immediately.
7.
Send task_finish.
8.
Receive task_finished.
9.
The server closes normally with code 1000.
Completion signals have different scopes:
is_final=true: last chunk of the current audio request.
sentence_end: all audio for the current sentence has arrived.
task_finished: the entire session has ended.

3. Start the task#

Send task_start after connecting:
{
  "event": "task_start",
  "model": "Skyblight-Turbo",
  "voice": "YOUR_VOICE_ID",
  "language": "en",
  "format": "mp3",
  "sample_rate": 32000,
  "bitrate": 128000,
  "channel": 1,
  "priority": "dedicated_concurrency",
  "voice_setting": {
    "speed": 1.0,
    "vol": 1.0,
    "pitch": 0,
    "emotion": "calm"
  },
  "subtitle_enable": true,
  "subtitle_type": "word_streaming",
  "session_id": "client-session-001"
}

3.1 Basic parameters#

event
Type: string
Required: yes
Fixed value: task_start
Starts a speech synthesis session.
Wait for task_started before sending text.
model
Type: string
Required: yes
Allowed value: Skyblight-Turbo only
Selects the speech synthesis model.
voice
Type: string
Required: yes
Selects a MyVocal voice ID.
A valid voice is required even when using timbre_weights.
language
Type: string
Required: no
Examples: zh, en, ja
Default: infer the language when omitted.
Helps the model select pronunciation rules.
format
Type: string
Required: no
Default: mp3
Allowed values: mp3, pcm, wav, flac, pcmu_raw, pcmu_wav
Selects the audio encoding or container.
pcmu_raw and pcmu_wav use 8 kHz G.711 μ-law.
sample_rate
Type: integer
Required: no
Default: 32000
Allowed values: 8000, 16000, 22050, 24000, 32000, 44100
Unit: Hz
bitrate
Type: integer
Required: no
Default: 128000
Allowed values: 32000, 64000, 128000, 256000
Unit: bit/s
Applies only with format=mp3.
channel
Type: integer
Required: no
Default: 1
Allowed values: 1 or 2
1 is mono and 2 is stereo.
priority
Type: string
Required: yes
Allowed value: dedicated_concurrency only
Uses dedicated concurrency.
session_id
Type: string
Required: no
Client-provided identifier for correlating this session.
The server echoes the value in its messages.

3.2 voice_setting#

voice_setting.speed
Type: number
Required: no
Default: 1.0
Suggested range: 0.5 to 2.0
Controls speaking rate. Higher values produce faster speech.
voice_setting.vol
Type: number
Required: no
Default: 1.0
Suggested range: greater than 0 and at most 10
Controls output volume.
voice_setting.pitch
Type: integer
Required: no
Default: 0
Suggested range: -12 to 12
Adjusts base pitch. Negative values lower it and positive values raise it.
voice_setting.emotion
Type: string
Required: no
Allowed values: happy, sad, angry, fearful
Other allowed values: disgusted, surprised, calm
Sets the delivery’s emotional tone.
Default: let the model choose based on the text.
voice_setting.english_normalization
Type: boolean
Required: no
Default: false
Improves English readings of content such as numbers.
May slightly increase latency.
voice_setting.latex_read
Type: boolean
Required: no
Default: false
Enables spoken LaTeX formulas.
Language: Chinese only.
Wrap formulas in $$...$$ and escape backslashes correctly.
Validate the documented ranges on the client. Service handling of out-of-range values may vary.

3.3 Pronunciation dictionary#

pronunciation_dict.tone
Type: string[]
Required: no
Specifies custom pronunciations for terms, abbreviations or symbols.
Format: original/pronunciation
Example: MyVocal/My Vocal

3.4 Voice mixing#

{
  "voice": "PRIMARY_VOICE_ID",
  "timbre_weights": [
    {
      "voice_id": "VOICE_ID_A",
      "weight": 50
    },
    {
      "voice_id": "VOICE_ID_B",
      "weight": 50
    }
  ]
}
timbre_weights
Type: object[]
Required: no
Blends several voices.
Limit: four voices.
The top-level voice must still be a valid voice ID.
timbre_weights[].voice_id
Type: string
Required: yes
ID of a voice to include in the blend.
timbre_weights[].weight
Type: integer
Required: yes
Range: 1 to 100
A higher weight increases that voice’s contribution.

3.5 Voice effects#

Use voice_modify with format=mp3.
voice_modify.pitch
Type: integer
Required: no
Range: -100 to 100
Negative values sound deeper. Positive values sound brighter.
voice_modify.intensity
Type: integer
Required: no
Range: -100 to 100
Negative values sound stronger. Positive values sound softer.
voice_modify.timbre
Type: integer
Required: no
Range: -100 to 100
Negative values sound fuller. Positive values sound clearer.
voice_modify.sound_effects
Type: string
Required: no
Allowed values: spacious_echo, auditorium_echo
Other allowed values: lofi_telephone, robotic
Applies a voice effect.
Select one effect at a time.

3.6 Subtitle parameters#

subtitle_enable
Type: boolean
Required: no
Default: false
Includes subtitle timings in audio responses.
subtitle_type
Type: string
Required: no
Default: sentence
Allowed values: sentence, word, word_streaming
Selects sentence, word or streaming word timestamps.

4. Send text incrementally#

After task_started, send the following message as often as needed:
{
  "event": "task_continue",
  "text": "Hello, welcome to MyVocal."
}
event
Type: string
Required: yes
Fixed value: task_continue
text
Type: string
Required: yes
Text to append to the server buffer.
Limit: 10,000 characters per message.
Keep sentence punctuation and line breaks. Clear sentence endings can trigger natural sentence-level synthesis sooner.
For short text without final punctuation, send task_flush.

5. Interrupt, flush or finish#

Interrupt the current synthesis#

{
  "event": "task_cancel"
}
The server returns task_canceled. The connection stays open.

Flush the buffer#

{
  "event": "task_flush"
}
The server processes buffered text and returns task_flushed. The session stays open. Flushing an empty buffer is allowed.

Finish the session#

{
  "event": "task_finish"
}
The server processes remaining text, returns task_finished and closes normally with code 1000.

6. Server events#

connected_success
The WebSocket is connected. Send task_start next.
task_started
The task has started. The client can send task_continue.
sentence_start
Synthesis has begun for a buffered sentence. Use this event to display sentence-level status.
task_continued
An audio chunk with optional subtitles and statistics. Assemble data.audio in arrival order.
sentence_end
All audio for the current sentence has been returned. The session can continue.
task_canceled
Synthesis was interrupted. The client can send another task_continue.
task_flushed
Buffered text has been processed. The session remains available.
task_finished
The session is complete. Wait for server close code 1000.
task_failed
The task failed. Read error_code, error and base_resp, stop the task and handle the indicated error.

7. Audio and subtitle responses#

event
Current event type.
data.audio
Type: string
Contents: hex-encoded audio chunk.
Decode to bytes and assemble chunks in arrival order.
data.subtitle.text
Text of the current subtitle.
data.subtitle.text_begin
Start offset of the subtitle in the text.
data.subtitle.text_end
End offset of the subtitle in the text.
data.subtitle.time_begin
Start time of the subtitle in the audio.
data.subtitle.time_end
End time of the subtitle in the audio.
data.subtitle.timestamped_words[]
Word-level subtitles. Each entry may contain:
word: word or character.
word_begin: start offset in the text.
word_end: end offset in the text.
time_begin: start time in the audio.
time_end: end time in the audio.
is_final
Whether this is the last chunk of the current audio request.

8. Session details, statistics and errors#

session_id
Session ID. A custom value is echoed unchanged.
connect_id
WebSocket connection ID.
trace_id
Per-request trace ID for troubleshooting.
extra_info.audio_length
Audio duration in milliseconds.
extra_info.audio_sample_rate
Actual sample rate.
extra_info.audio_size
Audio size in bytes.
extra_info.bitrate
Actual audio bitrate.
extra_info.audio_format
Actual audio format.
extra_info.audio_channel
Actual channel count.
extra_info.invisible_character_ratio
Proportion of invisible or invalid input characters. A high proportion may cause the service to reject synthesis.
extra_info.usage_characters
Billable character count for this synthesis.
extra_info.word_count
Number of valid characters or words read aloud, excluding punctuation.
base_resp.status_code
Application status code. 0 indicates success.
base_resp.status_msg
Application status description.
error_code
MyVocal error code, returned on failure.
error
MyVocal error description, returned on failure.

9. Example audio response#

{
  "event": "task_continued",
  "data": {
    "audio": "fff3..."
  },
  "is_final": false,
  "session_id": "client-session-001",
  "extra_info": {
    "audio_sample_rate": 32000,
    "audio_format": "mp3",
    "usage_characters": 28
  },
  "base_resp": {
    "status_code": 0,
    "status_msg": "success"
  }
}

10. Example error response#

{
  "event": "task_failed",
  "error_code": "400100",
  "error": "请求参数无效",
  "base_resp": {
    "status_code": 2013,
    "status_msg": "invalid params"
  }
}

11. Compatibility notes#

Omit continuous_sound.
Do not use format=opus.
Use voice_modify with format=mp3.
Text over 10,000 characters in a single message returns 2204.
After task_started, do not send task_start again.
Implement standard Ping/Pong, read/write timeouts and controlled reconnection.
Determine connection state from protocol and transport signals. A fixed elapsed time alone does not establish whether a connection is alive.

Path#

wss://openapi.myvocal.ai/v2/ai/speech/websocket

Handshake parameter reference#

LocationParameterTypeRequiredDescription
HeaderAPI-KeystringYesMyVocal API key, sent in the WebSocket handshake header.
上一页
WebSocket integration guide
下一页
Overview and quickstarts
Built with