# Telnyx Voice: Watermark Detection — Full Documentation > Complete page content for Watermark Detection (Voice section) of the Telnyx developer docs (https://developers.telnyx.com). > This file: https://developers.telnyx.com/docs/development/llms/voice-watermark-detection-llms-full-txt · Root index: https://developers.telnyx.com/llms.txt ## ### Overview > Source: https://developers.telnyx.com/docs/voice/watermark-detection.md Supported Telnyx text-to-speech models embed an inaudible watermark in the speech they synthesize. The audio watermark detection API reads audio and answers one question: does it contain that watermark, that is, was it generated by Telnyx text-to-speech? The API answers only whether the watermark is present, and how confident the answer is. It never returns the watermark payload or the organization the audio was synthesized for. | Interface | Endpoint | Use it for | |-----------|----------|------------| | HTTP | `POST https://api.telnyx.com/v2/audio_watermark_detections` | A recorded file, up to 100 MB and 60 minutes per channel. The response carries the result. | | WebSocket | `wss://api.telnyx.com/v2/audio_watermark_detections/stream` | Audio that is still coming in, such as a live call. A `detection` message arrives as soon as the watermark reads. See [Streaming detection](/docs/voice/watermark-detection/websocket). | The API detects only the Telnyx watermark. Speech from other text-to-speech services, from third-party voices offered through Telnyx, and from Telnyx models that do not embed the watermark carries no Telnyx watermark: the result is `watermark_detected: false`. A `false` result does not prove that the speech is human. ## Quickstart Send the audio as a `multipart/form-data` part named `file`: ```bash curl https://api.telnyx.com/v2/audio_watermark_detections \ -H "Authorization: Bearer $TELNYX_API_KEY" \ -F file=@call-recording.wav ``` Response for a two-channel call recording, with Telnyx text-to-speech on the second channel: ```json { "data": { "record_type": "audio_watermark_detection", "id": "257ef836-7f93-49e2-b282-b49289463a68", "watermark_detected": true, "confidence": "high", "channels": [ { "channel": 0, "watermark_detected": false }, { "channel": 1, "watermark_detected": true } ], "audio": { "duration_millis": 20280, "sample_rate": 16000, "format": "wav", "channels": 2 }, "created_at": "2026-12-04T14:50:25.200Z" } } ``` The request is synchronous. A 30-second call reads in about a second; a 30-minute recording can take 15 to 30 seconds. Set the HTTP client timeout to at least 120 seconds for long files. See the [API reference](/api-reference/audio-watermark-detection/detect-the-telnyx-tts-watermark-in-an-audio-file) for every field and error. ## Reading the result | Field | Description | |-------|-------------| | `watermark_detected` | `true` when the watermark read on at least one channel. | | `confidence` | `high`, `medium`, or `low`: how much to rely on `watermark_detected`. See [Confidence](#confidence). | | `channels` | One entry for each channel, in channel order, with its own `watermark_detected`. | | `audio` | What was read: `duration_millis`, `sample_rate`, `format`, and number of `channels`. | | `id` | Identifier of this detection. Detections are not stored, so it cannot be retrieved later. Quote it, or the `X-Request-Id` response header, when you contact support. | A `true` result is very unlikely to be wrong: the watermark carries a checksum, and the API reports a detection only when the checksum matches. A `false` result means that no watermark read; the audio can still be synthetic, or watermarked audio can be too damaged to read (see [What affects detection](#what-affects-detection)). ### Confidence When a watermark is detected, `confidence` is that of the best channel. Otherwise it is that of the least certain channel. | Value | With `watermark_detected: true` | With `watermark_detected: false` | |-------|---------------------------------|----------------------------------| | `high` | The watermark read directly. | No sign of a watermark in at least 20 seconds of audio, or the channel is digital silence. | | `medium` | The watermark read only after a wider search, for example after skipping unmarked stretches. | No sign of a watermark, but in less than 20 seconds of audio. | | `low` | Not used. | The audio shows signs of a watermark that could not be read, for example after heavy compression; or there is less than 2 seconds of audio. | Treat `false` with `low` confidence as inconclusive. If you have a longer or less compressed copy of the audio, check that copy. ### Channels Every channel is read on its own. In a call recorded with one channel per leg, the Telnyx text-to-speech audio is on one channel and the other party on the other; `channels` shows which leg carries it. Send the separate channels when you have them: in a mono mix of both parties, the other voice masks the watermark, and detection is less reliable. ## What affects detection Detection needs a few seconds of the synthesized speech. The figures below are approximate, measured on Telnyx text-to-speech output across many voices: | Audio | 8 seconds | 12 seconds | 20 seconds | |-------|-----------|------------|------------| | Text-to-speech output as synthesized | about 85% | about 88% | about 93% | | The same speech after a phone call and an 8 kHz MP3 call recorder | about 72% | about 87% | about 92% | - **Low-bitrate codecs remove the watermark.** AMR-NB at 7.95 kbit/s or lower, Opus at 8 kbit/s or lower, and MP3 at 16 kbit/s are not read reliably. - **Edited audio reads less well.** A recording assembled from pieces, such as a clip looped or spliced, can fail to read even when each piece is watermarked. - **Repeated prompts in a call read less well.** In a call with several utterances, a prompt that is replayed rather than synthesized fresh, for example from a cache, can fail to read. Freshly synthesized utterances read as one stream. - **Less than 2 seconds of audio** cannot be read. ## Supported audio | | HTTP | WebSocket | |-|------|-----------| | Formats | WAV (PCM, µ-law, A-law, float), MP3, FLAC, OGG (Vorbis or Opus), AIFF | Raw `l16` (16-bit little-endian PCM), `mulaw`, or `alaw` | | Sample rate | 8 kHz to 48 kHz read as is; other rates are resampled to 24 kHz | 8000 to 48000 Hz | | Channels | Up to 8 | Up to 2, interleaved | | Size | Up to 100 MB | Frames of up to 65,536 bytes | | Duration | Up to 60 minutes per channel | 590 seconds per session, and up to 60 minutes of audio | AAC/M4A and video containers are not supported. Convert them first, for example: ```bash ffmpeg -i input.m4a output.wav ``` ## Limits and access - The audio is held in memory for the read only. Telnyx does not store it. - Pretrial and everroam accounts cannot use the API. Requests from those accounts fail with `403`. - When detection is busy, requests fail with `503` and a `Retry-After` header. Retry after that many seconds. See [Errors](/docs/voice/watermark-detection/errors) for every error code. ## Next steps - [Streaming detection](/docs/voice/watermark-detection/websocket): detect the watermark in a live stream, with Python and Node.js examples. - [Errors](/docs/voice/watermark-detection/errors): HTTP error codes, WebSocket error frames, and close codes. --- ### Streaming detection > Source: https://developers.telnyx.com/docs/voice/watermark-detection/websocket.md Stream raw audio over a WebSocket and receive a `detection` message as soon as the Telnyx text-to-speech watermark reads on a channel. Use it for audio that is still coming in, such as a live call. For a recorded file, use the [HTTP endpoint](/docs/voice/watermark-detection#quickstart) instead. ## Endpoint ``` wss://api.telnyx.com/v2/audio_watermark_detections/stream ``` ## Authentication Send your API key in the `Authorization` header of the WebSocket upgrade request: ``` Authorization: Bearer YOUR_API_KEY ``` Browsers cannot set headers on a WebSocket. Send the key as two subprotocols instead: the `telnyx-auth-ws` marker, then `base64url.bearer.telnyx.` followed by the key in base64url without padding. Send either the header or the subprotocols, not both. ```javascript const encoded = btoa(apiKey).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""); const ws = new WebSocket( "wss://api.telnyx.com/v2/audio_watermark_detections/stream?format=mulaw&sample_rate=8000", ["telnyx-auth-ws", `base64url.bearer.telnyx.${encoded}`], ); ws.binaryType = "arraybuffer"; ``` Do not ship your API key to browsers you do not control. For public web apps, proxy the stream through your server. The upgrade request fails before the WebSocket opens with HTTP `401` for missing or invalid credentials, `403` for an account level that does not permit watermark detection, and `422` (`37005`) for an organization whose data locality this endpoint does not serve. ## Query parameters Set all options as query parameters on the upgrade request. You cannot change them during the session. | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | `sample_rate` | integer | None, required | Sample rate of the audio in Hz. Any integer from `8000` to `48000`. | | `format` | string | `l16` | Audio encoding. `l16` is 16-bit signed PCM, little-endian. `mulaw` and `alaw` are G.711, one byte per sample. | | `channels` | integer | `1` | Number of interleaved channels: `1` or `2`. | A missing or unsupported value opens the connection, sends an `invalid_params` error frame, and closes it with code `1008`. Stream the two legs of a call as two channels rather than a mono mix: each channel is read on its own, and the other party's voice masks the watermark in a mix. ## Session flow 1. Open the WebSocket with the query parameters. 2. Send audio as **binary** frames: raw samples, `channels` interleaved, with no header. Each frame must contain a whole number of samples for all channels and must not exceed 65,536 bytes. 20 ms frames are a good default; at 8 kHz `mulaw`, 20 ms of one channel is 160 bytes. 3. Read messages while you send. When the watermark reads on a channel, the server sends a `detection` message for it. 4. When you have no more audio, send the text frame `{"type": "end_of_stream"}`. 5. The server sends a `summary` message, then closes with code `1000`. ``` Client → Server binary: 320 bytes (20 ms, l16, 8 kHz, mono) Client → Server binary: 320 bytes ... Client ← Server text: {"type":"detection","channel":0,"watermark_detected":true,"detected_at_millis":4000} ... Client → Server text: {"type":"end_of_stream"} Client ← Server text: {"type":"summary","data":{...}} Client ← Server close: 1000 end_of_stream ``` You can send audio faster than real time, for example to check a file over the WebSocket. ## Messages ### Detection Sent once for each channel whose watermark reads, as soon as it reads. Channels without a watermark send none. ```json { "type": "detection", "channel": 0, "watermark_detected": true, "detected_at_millis": 4000 } ``` `detected_at_millis` is the position in the channel's audio at which the watermark read. Each channel is first read after 4 seconds of its audio, then about every 2 seconds, and less often after 30 seconds. Clean text-to-speech audio can read at the first read; through phone networks, expect 8 to 20 seconds of synthesized speech. After a detection, that channel is no longer read. You can end the stream as soon as you have the answer you need. ### Summary Sent once after `end_of_stream`, or at a [session limit](#session-limits). `data` is the same object that the [HTTP endpoint](/docs/voice/watermark-detection#reading-the-result) returns, with `audio.format` set to the stream's `format`. ```json { "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" } } ``` If you close the connection without `end_of_stream`, you get no summary. ### Error ```json { "type": "error", "code": "invalid_params", "message": "sample_rate is required: the audio's rate in Hz, 8000-48000" } ``` `code` is a stable identifier; `message` is for humans, do not parse it. Some errors end the session and some only drop a frame. See [WebSocket errors](/docs/voice/watermark-detection/errors#websocket-errors). ## Session limits A session is limited to 590 seconds, and to 60 minutes of audio. At either limit, the server sends the `summary` for the audio received so far, then a `max_session_duration` error frame, and closes with `1008`. To keep checking a longer stream, open a new session. ## Examples Both examples read a 16-bit PCM WAV file, stream it in 20 ms frames in real time as a live source would, and print each detection and the summary. Because they stream in real time, a file longer than about 9.5 minutes reaches the [session limit](#session-limits); remove the 20 ms pause to send faster than real time. Save the Node.js example as `detect-stream.mjs`. To convert a file with `ffmpeg`: ```bash ffmpeg -i input.mp3 -c:a pcm_s16le call-recording.wav ``` ```python Python # pip install websockets import asyncio import json import os import wave import websockets API_KEY = os.environ["TELNYX_API_KEY"] INPUT_FILE = "call-recording.wav" # 16-bit PCM WAV, 1 or 2 channels, 8-48 kHz URL = "wss://api.telnyx.com/v2/audio_watermark_detections/stream" async def send_audio(ws, wav): """Send 20 ms frames in real time, as a live stream would, then end the stream.""" frames_per_chunk = wav.getframerate() // 50 while chunk := wav.readframes(frames_per_chunk): await ws.send(chunk) await asyncio.sleep(0.02) await ws.send(json.dumps({"type": "end_of_stream"})) async def main(): with wave.open(INPUT_FILE, "rb") as wav: if wav.getsampwidth() != 2: raise SystemExit("Convert the file to 16-bit PCM first") query = f"?format=l16&sample_rate={wav.getframerate()}&channels={wav.getnchannels()}" async with websockets.connect( URL + query, additional_headers={"Authorization": f"Bearer {API_KEY}"} ) as ws: sender = asyncio.create_task(send_audio(ws, wav)) try: async for message in ws: event = json.loads(message) if event["type"] == "detection": print(f"Watermark on channel {event['channel']} " f"after {event['detected_at_millis'] / 1000:.1f} s of audio") elif event["type"] == "summary": data = event["data"] print("Summary:", data["watermark_detected"], data["confidence"]) elif event["type"] == "error": print("Error:", event["code"], event["message"]) except websockets.ConnectionClosedError: pass # closed with an error code; see ws.close_code below finally: sender.cancel() print("Closed:", ws.close_code, ws.close_reason) asyncio.run(main()) ``` ```javascript Node.js // npm install ws import fs from "node:fs"; import WebSocket from "ws"; const API_KEY = process.env.TELNYX_API_KEY; const INPUT_FILE = "call-recording.wav"; // 16-bit PCM WAV, 1 or 2 channels, 8-48 kHz const URL = "wss://api.telnyx.com/v2/audio_watermark_detections/stream"; // Find the format and data chunks of a WAV file. function readWav(path) { const buf = fs.readFileSync(path); let offset = 12; let fmt; while (offset + 8 <= buf.length) { const id = buf.toString("ascii", offset, offset + 4); const size = buf.readUInt32LE(offset + 4); const body = offset + 8; if (id === "fmt ") { fmt = { channels: buf.readUInt16LE(body + 2), sampleRate: buf.readUInt32LE(body + 4), bitsPerSample: buf.readUInt16LE(body + 14), }; } else if (id === "data") { return { ...fmt, pcm: buf.subarray(body, body + size) }; } offset = body + size + (size % 2); } throw new Error("No data chunk in the WAV file"); } const wav = readWav(INPUT_FILE); if (wav.bitsPerSample !== 16) throw new Error("Convert the file to 16-bit PCM first"); const query = `?format=l16&sample_rate=${wav.sampleRate}&channels=${wav.channels}`; const ws = new WebSocket(URL + query, { headers: { Authorization: `Bearer ${API_KEY}` }, }); ws.on("open", async () => { // Send 20 ms frames in real time, as a live stream would, then end the stream. const chunkBytes = Math.floor(wav.sampleRate / 50) * wav.channels * 2; for (let i = 0; i < wav.pcm.length && ws.readyState === WebSocket.OPEN; i += chunkBytes) { ws.send(wav.pcm.subarray(i, i + chunkBytes)); await new Promise((resolve) => setTimeout(resolve, 20)); } if (ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify({ type: "end_of_stream" })); }); ws.on("message", (message, isBinary) => { if (isBinary) return; const event = JSON.parse(message.toString()); if (event.type === "detection") { console.log(`Watermark on channel ${event.channel} after ${event.detected_at_millis / 1000} s of audio`); } else if (event.type === "summary") { console.log("Summary:", event.data.watermark_detected, event.data.confidence); } else if (event.type === "error") { console.log("Error:", event.code, event.message); } }); ws.on("unexpected-response", (req, res) => { console.error("Handshake failed with HTTP", res.statusCode); }); ws.on("error", (err) => console.error("WebSocket error:", err.message)); ws.on("close", (code, reason) => console.log("Closed:", code, reason.toString())); ``` Output for a two-channel call recording with Telnyx text-to-speech on the second channel: ``` Watermark on channel 1 after 10.8 s of audio Summary: True high Closed: 1000 end_of_stream ``` On close `1011` or `1013`, or a close without a summary, the failure is temporary: reconnect with exponential backoff and send the audio again. See [Close codes](/docs/voice/watermark-detection/errors#close-codes). The [WebSocket API reference](/api-reference/websockets/detect-the-telnyx-tts-watermark-over-websocket) lists every message schema. --- ## API Reference ### Errors > Source: https://developers.telnyx.com/docs/voice/watermark-detection/errors.md The audio watermark detection API returns errors in the standard Telnyx format. The HTTP endpoint and the WebSocket handshake answer with an `errors` array. An open WebSocket session sends JSON error frames and closes with a WebSocket close code. ## HTTP errors `POST /v2/audio_watermark_detections` and the upgrade request of the WebSocket endpoint return errors in this shape: ```json { "errors": [ { "code": "37003", "title": "Unsupported audio format", "detail": "The file is not audio this API reads: WAV, MP3, FLAC, OGG (Vorbis or Opus) or AIFF, up to 8 channels", "source": { "pointer": "/file" } } ] } ``` `code` and `title` are stable. `detail` is a human-readable explanation; do not parse it. `source.pointer` names the request field when the error is about one. ### Error codes | Status | Code | Title | Cause | What to do | |--------|------|-------|-------|------------| | 400 | `10015` | Bad Request | The body is not `multipart/form-data`, or the multipart body cannot be read. | Send the audio as a `multipart/form-data` part named `file`. | | 401 | `10009` | Authentication failed | The API key is missing or invalid. | Send `Authorization: Bearer YOUR_API_KEY`. | | 403 | `10038` | Feature not permitted | The account level does not permit watermark detection. Pretrial and everroam accounts cannot use it. | Upgrade the account. | | 413 | `37001` | Audio file too large | The file is larger than 100 MB. | Send a shorter or more compressed file. | | 413 | `37002` | Audio too long | A channel is longer than 60 minutes. | Cut the recording into parts of 60 minutes or less. | | 415 | `37003` | Unsupported audio format | The file is not WAV, MP3, FLAC, OGG (Vorbis or Opus), or AIFF, or it has more than 8 channels. | Convert the file, for example with `ffmpeg -i input.m4a output.wav`. | | 422 | `10004` | Missing required parameter | The request has no `file` part. | Send the audio in the `file` part. | | 422 | `37004` | Invalid audio | The file is empty or contains no audio. | Check the file. | | 422 | `37005` | Data locality mismatch | The organization is pinned to a data locality that this endpoint does not serve. | Contact support. | | 429 | `10011` | Too many requests | The request rate limit was exceeded. | Retry with exponential backoff. | | 500 | `10007` | Unexpected error | Detection failed unexpectedly. | Retry. If the error persists, contact support with the `X-Request-Id` response header. | | 503 | `37006` | Detection temporarily unavailable | Detection is busy or restarting. | Retry after the number of seconds in the `Retry-After` header. | The WebSocket upgrade request can fail with `401`, `403`, or `422` (`37005`) before the connection opens. ## WebSocket errors During a session, the server sends errors as JSON text frames: ```json { "type": "error", "code": "invalid_params", "message": "sample_rate is required: the audio's rate in Hz, 8000-48000" } ``` `code` is a stable identifier. `message` is a human-readable description; do not parse it. ### WebSocket error codes | Error code | Close code | Cause | |------------|------------|-------| | `invalid_params` | 1008 | A query parameter is missing or has an unsupported value: `format`, `sample_rate`, or `channels`. | | `max_session_duration` | 1008 | The session reached 590 seconds or 60 minutes of audio. The server sends the `summary` message before it closes. | | `internal_error` | 1011 | Detection failed. Reconnect and send the audio again. | | `overloaded` | 1013 | The service has too many open sessions. Reconnect after a short wait. | | `chunk_too_large` | None, the session continues | The binary frame is larger than 65,536 bytes. The server drops the frame. | | `decode_error` | None, the session continues | The frame length is not a whole number of samples for all channels. The server drops the frame. | | `unsupported_message` | None, the session continues | The text frame is not `{"type": "end_of_stream"}`. | ### Close codes The close reason is the error code. Before every close that the server makes with a code other than `1000`, it sends the matching error frame. | Close code | Reason | What to do | |------------|--------|------------| | 1000 | `end_of_stream` | Nothing. Normal end, after the `summary` message. | | 1008 | `invalid_params` | Fix the query parameter before you reconnect. | | 1008 | `max_session_duration` | The `summary` message covers the audio received so far. Open a new session for the rest. | | 1011 | `internal_error` | Reconnect and send the audio again. | | 1013 | `overloaded` | Reconnect after a short wait, with exponential backoff. | A connection that closes with any other code, for example `1001` or `1012` while the server restarts, or a network failure, ends without a `summary` message. Reconnect with exponential backoff and send the audio again: the service keeps no state between connections. --- ## API Reference (Watermark Detection) ### Audio Watermark Detection - [Detect the Telnyx TTS watermark in an audio file](https://developers.telnyx.com/api-reference/audio-watermark-detection/detect-the-telnyx-tts-watermark-in-an-audio-file.md): Upload an audio file and check whether it contains the watermark that Telnyx text-to-speech embeds in synthesized speech. The request is synchronous: the respo…