Realtime transcription
wss://global.rt.speechmatics.com/v2/Transcribe audio as you stream it, over one WebSocket connection. Open the connection and send StartRecognition with your audio format and transcription settings; then stream audio as binary messages, and transcripts arrive as they are ready. Every other message is a JSON object that names itself in its message field.
New to the Realtime API? Start with the quickstart.
Handshake
- GET
wss://global.rt.speechmatics.com/v2/
Routes each connection to the nearest region, for the lowest latency. To keep data in one region instead, connect to that region's endpoint, such as wss://eu.rt.speechmatics.com/v2. See Supported endpoints.
Authentication
Any one of:
- apiKey
Authorization: Bearer <token>Your API key, for server-side connections.
- temporaryKey
?jwt=<key>A temporary key, for connections from a browser, which cannot set the
Authorizationheader — and should not hold your long-lived API key. For example,wss://global.rt.speechmatics.com/v2?jwt=<temporary-key>.
Responses
Switching Protocols. Connected: send StartRecognition to begin.
A successful handshake request:
GET /v2/ HTTP/1.1
Host: global.rt.speechmatics.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: ujRTbIaQsXO/0uCbjjkSZQ==
Sec-WebSocket-Version: 13
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Authorization: Bearer wmz9fkLJM6U5NdyaG3HLHybGZj65PXp
User-Agent: Python/3.8 websockets/8.1
And its response:
HTTP/1.1 101 Switching Protocols
Server: nginx/1.17.8
Date: Wed, 06 Jan 2021 11:01:05 GMT
Connection: upgrade
Upgrade: WebSocket
Sec-WebSocket-Accept: 87kiC/LI5WgXG52nSylnfXdz260=
Bad Request. The handshake request is malformed.
Unauthorized. The API key or temporary key is not valid.
Method Not Allowed. The request method is not GET.
Send
StartRecognition
Initiates a new recognition session.
message"StartRecognition"audio_formatAudioFormatone oftranscription_configTranscriptionConfigContains configuration for this recognition session.
translation_configoptionalTranslationConfigSpecifies various configuration values for translation. All fields except
target_languagesare optional, using default values when omitted.audio_events_configoptionalAudioEventsConfigContains configuration for Audio Events
AddAudio
A binary chunk of audio. The server confirms receipt by sending an AudioAdded message.
application/octet-streamstring<binary>Raw audio bytes, in the encoding and sample rate given by
audio_formatin StartRecognition.
AddChannelAudio
Audio belonging to a specific channel.
message"AddChannelAudio"channelstringThe channel identifier to which the audio belongs.
datastringThe audio data in base64 format.
EndOfStream
Declares that the client has no more audio to send.
message"EndOfStream"last_seq_nointeger
EndOfChannel
Declares that the channel has no more audio to send.
message"EndOfChannel"channelstringThe channel identifier to which the audio belongs.
last_seq_nointeger
ForceEndOfUtterance
Requests a finalized transcript followed by an EndOfUtterance message.
Supported by Enhanced, Standard, and Melia 1. The client decides when to send this message using its own turn detection.
message"ForceEndOfUtterance"channeloptionalstringThe channel to request finalized transcript from. This field is only seen in multichannel.
timestampoptionalnumber<float>≥ 0Timestamp of the audio data that corresponds to the force end of utterance request. It's the number of seconds since the beginning of the audio.
SetRecognitionConfig
Allows the client to re-configure the recognition session.
The language field can be included in SetRecognitionConfig, but its value must match the language specified in the initial StartRecognition message. Attempting to change the language or any other transcription configuration parameter not listed below will result in an error.
message"SetRecognitionConfig"transcription_configMidSessionTranscriptionConfigContains configuration for this recognition session.
GetSpeakers
Requests any detected speaker identifiers to be returned.
message"GetSpeakers"finaloptionalbooleanOptional. This flag controls when speaker identifiers are returned. Defaults to false if omitted. When false, multiple GetSpeakers requests can be sent during transcription, each returning the speaker identifiers generated so far. To reduce the chance of empty results, send requests after at least one TranscriptAdded message is received to make sure that the server has processed some audio. When true, speaker identifiers are returned only once at the end of the transcription, regardless of how many final: true requests are sent. Even with final: true requests, you can still send final: false requests to receive intermediate speaker identifier updates.
Receive
RecognitionStarted
Server response to StartRecognition, acknowledging that a recognition session has started.
message"RecognitionStarted"orchestrator_versionoptionalstringidoptionalstringlanguage_pack_infooptionalLanguagePackInfoProperties of the language pack.
channel_idsoptionalstring[]
AudioAdded
Server response to AddAudio, indicating that audio has been added successfully.
When clients send audio faster than real-time, the server may read data slower than it's sent. If binary AddAudio messages exceed the server's internal buffer, the server will process other WebSocket messages until buffer space is available. Clients receive AudioAdded responses only after binary data is read. This can fill TCP buffers, potentially causing WebSocket write failures and connection closure with prejudice. Clients can monitor the WebSocket's bufferedAmount attribute to prevent this.
message"AudioAdded"seq_nointeger
ChannelAudioAdded
Server response to AddChannelAudio, indicating that audio has been added successfully.
message"ChannelAudioAdded"seq_nointegerchannelstring
AddPartialTranscript
A partial transcript is a transcript that can be changed in a future AddPartialTranscript as more words are spoken until the AddTranscript Final message is sent for that audio.
Partials will only be sent if transcription_config.enable_partials is set to true in the StartRecognition message.
The message structure is the same as AddTranscript, with a few limitations.
For AddPartialTranscript messages the confidence field for alternatives has no meaning and should not be relied on.
message"AddPartialTranscript"formatoptionalstringSpeechmatics JSON output format version number.
metadataRecognitionMetadataresultsRecognitionResult[]channeloptionalstringThe channel identifier to which the audio belongs. This field is only seen in multichannel.
forcedoptionalbooleanWhether this message was triggered by a
ForceEndOfUtterancemessage. This field is only seen on forced messages, where its value istrue.
AddTranscript
Contains the final transcript of a part of the audio that the client has sent.
message"AddTranscript"formatoptionalstringSpeechmatics JSON output format version number.
metadataRecognitionMetadataresultsRecognitionResult[]channeloptionalstringThe channel identifier to which the audio belongs. This field is only seen in multichannel.
forcedoptionalbooleanWhether this message was triggered by a
ForceEndOfUtterancemessage. This field is only seen on forced messages, where its value istrue.
AddPartialTranslation
Contains a work-in-progress translation of a part of the audio that the client has sent.
message"AddPartialTranslation"formatoptionalstringSpeechmatics JSON output format version number.
languagestringLanguage translation relates to given as an ISO language code.
resultsTranslatedSentence[]
AddTranslation
Contains the final translation of a part of the audio that the client has sent.
message"AddTranslation"formatoptionalstringSpeechmatics JSON output format version number.
languagestringLanguage translation relates to given as an ISO language code.
resultsTranslatedSentence[]
EndOfTranscript
Server response to EndOfStream, after the server has finished sending all AddTranscript messages.
message"EndOfTranscript"
AudioEventStarted
Start of an audio event detected.
message"AudioEventStarted"eventAudioEventStartDatachanneloptionalstringThe channel identifier to which the audio belongs. This field is only seen in multichannel.
AudioEventEnded
End of an audio event detected.
message"AudioEventEnded"eventAudioEventEndDatachanneloptionalstringThe channel identifier to which the audio belongs. This field is only seen in multichannel.
EndOfUtterance
Indicates the end of an utterance, triggered by a configurable period of non-speech or a client-sent ForceEndOfUtterance message.
Enhanced and Standard support automatic silence-based detection, configured by the end_of_utterance_silence_trigger parameter in conversation_config (see End of utterance).
Melia 1 does not support automatic silence-based detection and rejects this setting. With Melia 1, send ForceEndOfUtterance to receive an EndOfUtterance message.
Like punctuation, an EndOfUtterance has zero duration.
message"EndOfUtterance"metadataEndOfUtteranceMetadatachanneloptionalstringThe channel identifier to which the EndOfUtterance message belongs. This field is only seen in multichannel.
forcedoptionalbooleanWhether this message was triggered by a
ForceEndOfUtterancemessage. This field is only seen on forced messages, where its value istrue.
LanguageInfo
Reports the word delimiter and writing direction for a language detected in the audio.
Sent only by the melia-1 model, which labels each word with the language it was spoken in. The message is emitted once per language code, immediately before that language first appears in an AddPartialTranscript or AddTranscript message. Use it to set word spacing and text direction when rendering the transcript (see LanguageInfo message).
message"LanguageInfo"languagestringThe detected language code.
word_delimiterstringThe delimiter to place between words of this language when reconstructing the transcript.
writing_directionWritingDirectionEnum"left-to-right""right-to-left"The direction that words in the language should be written and read in.
partialoptionalbooleanWhether the message was triggered by a Partial transcript. This field is only seen when its value is
true.
Info
Additional information sent from the server to the client.
message"Info"typeInfoTypeEnumone ofThe kind of information an
Infomessage carries.reasonstringcodeoptionalintegerseq_nooptionalintegerqualityoptionalstringOnly set when
typeisrecognition_quality. Quality-based model name. It is one of "telephony", "broadcast". The model is selected automatically, for high-quality audio (12kHz+) the broadcast model is used, for lower quality audio the telephony model is used.usageoptionalnumberOnly set when
typeisconcurrent_session_usage. Indicates the current usage (number of active concurrent sessions).quotaoptionalnumberOnly set when
typeisconcurrent_session_usage. Indicates the current quota (maximum number of concurrent sessions allowed).last_updatedoptionalstringOnly set when
typeisconcurrent_session_usage. Indicates the timestamp of the most recent usage update, in the formatYYYY-MM-DDTHH:MM:SSZ(UTC). This value is updated even when usage exceeds the quota, as it represents the most recent known data. In some cases, it may be empty or outdated due to internal errors preventing successful update.regionoptionalstringOnly set when
typeisconcurrent_session_usage. The region that reported this usage, for exampleeu.
Warning
Warning messages sent from the server to the client.
message"Warning"typeWarningTypeEnumone ofThe kind of problem a
Warningmessage reports.reasonstringcodeoptionalintegerseq_nooptionalintegerduration_limitoptionalnumberOnly set when
typeisduration_limit_exceeded. Indicates the limit that was exceeded (in seconds).
Error
Error messages sent from the server to the client. After any error, the transcription is terminated and the connection is closed.
message"Error"typeErrorTypeEnumone ofThe kind of error an
Errormessage reports.invalid_message,protocol_errorandunknown_errorcan be triggered as a response to any type of messages.reasonstringcodeoptionalintegerseq_nooptionalinteger
SpeakersResult
Server response to GetSpeakers request returning any detected speaker identifiers.
message"SpeakersResult"speakersSpeakersResultItem[]
Connection close
An Error message can be followed by a WebSocket close frame. Its code, and the reason it carries:
For 4005, 4013 and 1011 only, retry after at least 5–10 seconds.
Sessions also close when they idle or run too long; see Realtime limits.