1. API reference
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
        POST
      • Get ASR usage
        GET
  • 企业客户声音定制服务
    • Your custom brand voice
  1. API reference

Realtime transcription over WebSocket

Realtime quickstart and SDK examples
Connect to wss://openapi.myvocal.ai/asr/realtime. Set the required api-key and model_id in the query string. Keep the full connection URL out of logs. This example uses the realtime V2 model:
wss://openapi.myvocal.ai/asr/realtime?api-key=YOUR_API_KEY&model_id=echo_v2_realtime&audio_format=pcm_16000&commit_mode=manual
SettingWhere to send itUsage
audio_formatConnection URLUse pcm_16000 for the sample. Set sample_rate to 16000 in each audio message.
commit_modeConnection URLmanual is the default. Use vad for silence-based segmentation or turn_prediction for turn detection (V2 only).
language, word_timestampsConnection URLUse language=en for English audio. Set word_timestamps=true to receive word timings.
multilingual_mode, speaker_diarizationConnection URLV2 only. Enable mixed-language transcription or speaker labels with true.
keytermsConnection URLRepeat the query field for each term, up to 50 terms.
previous_text, hotwords_libraryFirst audio message onlySupply optional preceding text or, on V2, an array of up to 10,000 terms (1–50 characters per term).
After session_started, send JSON text messages. Encode the raw PCM bytes as Base64, without a WAV header. Replace the placeholder below with audio bytes encoded as Base64.
{"message_type":"input_audio_chunk","audio_base_64":"BASE64_PCM_BYTES","sample_rate":16000,"commit":false}
For manual submission, set commit to true on the last audio message of the segment. With automatic segmentation, keep streaming chunks with commit=false.
Received eventHow to use it
session_startedStart sending audio.
partial_transcriptDisplay the current text; it can change.
committed_transcriptSave the final text for the segment.
committed_transcript_with_timestampsRead words[].start and words[].end in seconds.
diarized_transcriptWith V2 speaker labeling enabled, use segment_index and words[].speaker_id.
Example final message (fields shown selectively):
{"message_type":"committed_transcript","text":"The order contains 42 boxes."}
If the server returns an error event, read its message_type and error before handling the WebSocket close.
Both models use wss://openapi.myvocal.ai/asr/realtime. Use model_id to choose realtime V1 (echo_v1_realtime) or V2 (echo_v2_realtime) when connecting.
What you want to doWhere to send itHow to configure itApplies to
Submit when the user releases the record buttonConnection URLcommit_mode=manual (default)V1、V2
Submit the current segment manuallyAudio messageSend commit=true on the segment’s final chunk.V1、V2
Use silence to detect segment boundariesConnection URLcommit_mode=vadV1、V2
Detect when the speaker has finished a turnConnection URLcommit_mode=turn_predictionV2 only
Keep each language in bilingual captionsConnection URLmultilingual_mode=true. Default: false.V2 only
Identify speakers in a callConnection URLspeaker_diarization=true. Default: false.V2 only
Get word timingsConnection URLword_timestamps=trueV1、V2
Read the detected languageConnection URLSet include_language_detection=true and read language information from the final event with timestamps.V1、V2
Provide a short list of termsConnection URLRepeat keyterms once per term.V1、V2
Supply a store directory or product catalogFirst audio messageString array in hotwords_libraryV2 only
Continue from preceding textFirst audio messageprevious_textV1、V2
Java SDK (ZIP) · Python SDK (wheel) · Go SDK installation and examples · GitHub release

Connect#

wss://openapi.myvocal.ai/asr/realtime?api-key=YOUR_API_KEY&model_id=echo_v2_realtime&audio_format=pcm_16000&commit_mode=manual
api-key and model_id are required. Set commit_mode to choose when a segment is submitted. See the connection parameter reference for all fields.
Using the medical model echo_v2_medical here returns HTTP 400 during the handshake. For medical recordings use File transcription.

Send audio#

Wait for session_started and send audio in JSON text messages. Encode mono signed 16-bit little-endian PCM as Base64 in audio_base_64. If reading a WAV file, remove its header.
Supported audio_format values are pcm_8000, pcm_16000, pcm_22050, pcm_24000 and pcm_44100. Match sample_rate in each message, for example 16000 Hz for pcm_16000.
FieldTypeDescription
message_typestringFixed value: input_audio_chunk
audio_base_64stringBase64-encoded PCM audio without a WAV header
sample_rateintegerMatch the connection’s audio format, for example 16000.
commitbooleanSet to true to submit the segment in manual mode.
previous_textOptional stringPreceding text, allowed only in the first audio message of the session
hotwords_libraryOptional string arrayRealtime V2 only. Supply store names, product models or other terms in the first audio message. Up to 10,000 entries, each 1–50 characters.
Example message. Replace BASE64_PCM_BYTES with Base64-encoded audio:
{
  "message_type": "input_audio_chunk",
  "audio_base_64": "BASE64_PCM_BYTES",
  "sample_rate": 16000,
  "commit": false
}
For context, add previous_text only to the first audio message. Omit it from subsequent frames and the URL query.

Choose a commit mode#

Manual submission · commit_mode=manual
Omitting commit_mode selects manual submission. Send commit=true on the last chunk and keep receiving until the final transcript.
Silence-based segmentation · commit_mode=vad
Stream audio continuously. The server uses speech and silence to decide when to commit. Tune vad_threshold, vad_silence_threshold_secs (seconds), min_speech_duration_ms (milliseconds) or min_silence_duration_ms (milliseconds) in the connection URL.
Turn prediction · commit_mode=turn_prediction (realtime V2 only)
For a voice assistant, let the model detect when the speaker finishes a thought. Send commit=false continuously. The server decides when each segment is complete.

Automatic segmentation, bilingual speech and vocabulary#

Realtime V2 only
For live call captions, connect with model_id=echo_v2_realtime, audio_format=pcm_16000 and commit_mode=turn_prediction. Use multilingual_mode=true to retain Chinese and English speech in their original languages, speaker_diarization=true to distinguish speakers and word_timestamps=true for word timings.
Repeat keyterms in the connection URL for up to 50 terms. For larger catalogs, send hotwords_library as an array in the first input_audio_chunk after session_started. Use up to 10,000 entries of 1–50 characters each. The first frame may also contain previous_text. Later frames carry audio, sample rate and the commit flag. In automatic modes, continue sending commit=false.

Receive server events#

Dispatch on message_type. Word timings and speaker results for a segment can arrive in either order.
EventFields to readWhen to handle it
session_startedconfigStart sending audio when the session is ready.
partial_transcripttextUpdate live captions. Partial text can change.
committed_transcripttext and segment_index when presentSave each segment’s final transcript once.
committed_transcript_with_timestampswords[].text/start/endRead when word timings are enabled. Timings are in seconds. This event may omit the segment index.
diarized_transcriptsegment_index、words[].speaker_idWith realtime V2 speaker diarization, match by segment index. Zero is a valid index.
The following examples show separate messages with selected fields.
{"message_type":"session_started","config":{"include_timestamps":true}}
{"message_type":"partial_transcript","text":"Hello"}
{"message_type":"committed_transcript","text":"Hello world.","segment_index":0}
{"message_type":"committed_transcript_with_timestamps","text":"Hello world.","words":[{"text":"Hello","start":0.14,"end":0.4}]}
{"message_type":"diarized_transcript","segment_index":0,"words":[{"text":"Hello","speaker_id":"speaker_0"}]}
With include_language_detection=true, read the language from the final event with timestamps. Use enhanced events to enrich the final text saved for the same segment.

Errors and shutdown#

If the handshake fails, check the HTTP status. For HTTP 400, verify the model and connection parameters. Once connected, handle error events.
EventFields to readWhen to handle it
input_errormessage_type、errorCorrect the audio message according to the error. For example, the vocabulary must be in the first frame.
invalid_requestmessage_type、errorCorrect the request according to the error. Realtime V2 accepts up to 50 connection-level terms.
auth_errormessage_typeCheck the enterprise ASR API key.
quota_exceeded_errormessage_typeCheck the account quota.
errormessage_type and the reason returned by the serverHandle the indicated connection or server error.
The following error was returned when hotwords_library was sent after the first audio frame.
{"message_type":"input_error","error":"hotwords_library is only allowed in the first input_audio_chunk"}
If the connection closed after an error, correct the cause before reconnecting. For normal shutdown, finish the segment and wait for the final result before closing.

Usage and integration notes#

Realtime transcription is billed by the duration of streamed audio, in seconds, at the rate in your enterprise agreement. Get usage.
Send short chunks continuously and receive events concurrently. Keep the full connection URL out of logs because it contains your key.

Path#

wss://openapi.myvocal.ai/asr/realtime

Handshake parameter reference#

LocationParameterTypeRequiredDescription
Queryapi-keystringYesEnterprise ASR API key.
Querymodel_idstringYesRequired. Use echo_v2_realtime or echo_v1_realtime. Allowed values: echo_v2_realtime, echo_v1_realtime.
Queryaudio_formatstringNoMono signed 16-bit little-endian PCM. Match sample_rate to the format, such as 16000 for pcm_16000. Allowed values: pcm_8000, pcm_16000, pcm_22050, pcm_24000, pcm_44100.
Querycommit_modestringNoBoth realtime models support manual (default) and vad. Only echo_v2_realtime supports turn_prediction. Allowed values: manual, vad, turn_prediction.
Queryword_timestampsbooleanNoSet to true to receive start and end times for each word.
QuerylanguagestringNoLanguage code. Omit for automatic language detection.
Queryvad_thresholdstringNoVoice activity detection threshold. Higher values require stronger evidence of speech. Example value: 0.4.
Queryvad_silence_threshold_secsstringNoSeconds of silence used to end a segment in vad mode. Example value: 1.5 seconds.
Querymin_speech_duration_msintegerNoMinimum speech duration in milliseconds. Example value: 250 milliseconds.
Querymin_silence_duration_msintegerNoMinimum silence duration in milliseconds. Example value: 2500 milliseconds.
Queryinclude_language_detectionbooleanNoRead language information from committed_transcript_with_timestamps when enabled.
QuerykeytermsstringNoRepeat this query parameter for each term. Up to 50 terms on echo_v2_realtime. Terms guide recognition and do not guarantee a spelling.
Querymultilingual_modebooleanNoRealtime V2 only. Set to true to transcribe mixed-language speech in the original languages. Default: false.
Queryspeaker_diarizationbooleanNoRealtime V2 only. Set to true to receive speaker labels. Default: false.
上一页
Changelog
下一页
Create a file transcription
Built with