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

WebSocket integration guide

View the official SDKs
Java | Python | Go · Chinese instructions

1
Step 1. Establish the WebSocket connection
Enter the connection URL:
wss://openapi.myvocal.ai/ai/speech/websocket
Confirm that the persistent connection has been established.
2
Step 2. Send the configuration with your API key
The first message after connecting must be a configuration message containing API-Key. Otherwise the service returns an error:
{
  "API-Key": "YOUR_API_KEY",
  "voice": "your_voice_id",
  "priority": "dedicated_concurrency",
  "extra_info": true
}
Required: API-Key, voice and priority=dedicated_concurrency
💡
Optional parameters: output format, sample rate sample_rate, output language and additional information with extra_info: true.
3
Step 3. Send text to synthesize
After initialization, continue sending text as JSON objects:
{"text": "Hello, welcome to MyVocal TTS!"}
You can split text across several messages. The server joins the fragments. For example, the following forms are equivalent:
Option 1
{"text": "This is a demonstration of real-time speech synthesis"}
Option 2: split the text across messages to receive first audio sooner.
{"text": "This is a demonstration of "}
{"text": "real-time speech synthesis"}
The server streams audio until synthesis completes.
4
Step 4. Flush buffered text
The service normally buffers incoming text until there is enough context for natural speech. To trigger synthesis immediately, send the following:
{
  "flush": true
}
After processing the buffered text, the server returns additional information containing buffer_empty.
Flush at the end of a sentence when possible. Forcing a flush mid-sentence can make the delivery sound unnatural.
After completion, you can close the WebSocket.
When audio is returned
Without flush, the model waits for sufficient text before returning binary audio. Typically it buffers about two sentences to preserve continuity.
For immediate output, send flush=true at a sentence boundary and check buffer_empty to see when buffered text has been processed.

Path#

wss://openapi.myvocal.ai/ai/speech/websocket
上一页
Full-duplex communication
下一页
V2 bidirectional streaming synthesis (WebSocket)
Built with