Detect the Telnyx TTS watermark over WebSocket
Stream raw audio and receive a detection message as soon as the Telnyx TTS watermark reads on a channel.
Set all options as query parameters on the upgrade request. They cannot change during the session.
A request without valid credentials fails with HTTP 401, and an account level that does not permit
watermark detection with HTTP 403. An organization whose data locality this endpoint does not serve fails
with HTTP 422 and error code 37005. Errors at the upgrade carry a JSON errors body. An unsupported
parameter value opens the connection, sends an invalid_params error frame, and closes it with 1008.
Each channel is first read after 4 seconds of its audio, then about every 2 seconds, and less often
after 30 seconds, until its watermark reads. You can send audio faster than real time.
Sessions are limited to 590 seconds, and to 60 minutes of audio. At either limit, the server sends the
summary message, then a max_session_duration error frame, and closes with 1008.
{}{
"type": "end_of_stream"
}{
"type": "detection",
"channel": 0,
"watermark_detected": true,
"detected_at_millis": 4000
}{
"type": "summary",
"data": {
"record_type": "audio_watermark_detection",
"id": "d2c9f588-1e3b-4a47-9c2d-7b8e6f5a4c31",
"watermark_detected": true,
"confidence": "high",
"channels": [
{
"channel": 0,
"watermark_detected": true
}
],
"audio": {
"duration_millis": 24060,
"sample_rate": 8000,
"format": "mulaw",
"channels": 1
},
"created_at": "2026-12-04T14:26:52.318Z"
}
}{
"type": "error",
"code": "invalid_params",
"message": "sample_rate is required: the audio's rate in Hz, 8000-48000"
}Telnyx API v2 Bearer token authentication.
Query parameters passed when opening the WebSocket connection.
Client-to-server binary frame with raw audio in the format and sample_rate set on the connection,
channels interleaved. No container and no WAV header.
The frame must contain a whole number of samples for all channels (for example, a multiple of 4 bytes
for two-channel l16) and must not exceed 65,536 bytes. 20 ms chunks are a good default.
Client-to-server text frame. Send it when you have no more audio. The server reads the rest of the
audio, sends the summary message, then closes with code 1000. If you close the connection without
it, you get no summary. Any other text frame gets an unsupported_message error frame and the session
continues.
Server-to-client text frame, sent once for each channel whose watermark reads, as soon as it reads. After it, that channel is no longer read; the rest of its audio is only counted. You can end the stream as soon as you have the answer you need.
Server-to-client text frame, sent once after end_of_stream or at a session limit. data is the
same object that POST /v2/audio_watermark_detections returns, with audio.format set to the
stream's format.
Server-to-client text frame. If the error ends the session, the server closes the connection right after this frame, with the close code listed below and the error code as the close reason.
invalid_params(close1008): a query parameter is missing or has an unsupported value.max_session_duration(close1008): the session reached 590 seconds or 60 minutes of audio. Thesummarymessage is sent first.internal_error(close1011): detection failed. Reconnect and try again.overloaded(close1013): the service has too many open sessions. Try again later.chunk_too_large(session continues): the binary frame is larger than 65,536 bytes. The frame is dropped.decode_error(session continues): the frame length is not a whole number of samples. The frame is dropped.unsupported_message(session continues): the text frame is not{"type": "end_of_stream"}.
Was this page helpful?
{}{
"type": "end_of_stream"
}{
"type": "detection",
"channel": 0,
"watermark_detected": true,
"detected_at_millis": 4000
}{
"type": "summary",
"data": {
"record_type": "audio_watermark_detection",
"id": "d2c9f588-1e3b-4a47-9c2d-7b8e6f5a4c31",
"watermark_detected": true,
"confidence": "high",
"channels": [
{
"channel": 0,
"watermark_detected": true
}
],
"audio": {
"duration_millis": 24060,
"sample_rate": 8000,
"format": "mulaw",
"channels": 1
},
"created_at": "2026-12-04T14:26:52.318Z"
}
}{
"type": "error",
"code": "invalid_params",
"message": "sample_rate is required: the audio's rate in Hz, 8000-48000"
}