> ## Documentation Index
> Fetch the complete documentation index at: https://developers.telnyx.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 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`.




## AsyncAPI

````yaml openapi/asyncapi/audio-watermark-detection-websockets/audio-watermark-detection-websockets.yml audio-watermark-detection-websockets
id: audio-watermark-detection-websockets
title: Detect the Telnyx TTS watermark over WebSocket
description: >
  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`.
servers:
  - id: audio-watermark-detection-websockets
    protocol: wss
    host: api.telnyx.com
    bindings:
      - protocol: ws
        version: 0.1.0
        value: {}
        schemaProperties: []
    variables: []
address: /v2/audio_watermark_detections/stream
parameters: []
bindings:
  - protocol: ws
    version: 0.1.0
    value:
      query:
        type: object
        description: Query parameters passed when opening the WebSocket connection.
        required:
          - sample_rate
        properties:
          format:
            type: string
            description: >
              Audio encoding of the binary frames.

              `l16` is 16-bit signed integer PCM, little-endian (2 bytes per
              sample).

              `mulaw` and `alaw` are G.711 µ-law and A-law (1 byte per sample),
              as telephony media carries them.
            enum:
              - l16
              - mulaw
              - alaw
            default: l16
          sample_rate:
            type: integer
            description: >
              Sample rate of the audio in Hz. Required. Any integer from 8000 to
              48000.

              A missing value or a value outside that range closes the
              connection with `invalid_params` and close code `1008`.
            minimum: 8000
            maximum: 48000
          channels:
            type: integer
            description: >
              Number of interleaved channels. Each channel is read on its own:
              stream the two legs of a call as

              two channels rather than a mono mix.
            minimum: 1
            maximum: 2
            default: 1
    schemaProperties:
      - name: query
        type: object
        description: Query parameters passed when opening the WebSocket connection.
        required: false
        properties:
          - name: format
            type: string
            description: >
              Audio encoding of the binary frames.

              `l16` is 16-bit signed integer PCM, little-endian (2 bytes per
              sample).

              `mulaw` and `alaw` are G.711 µ-law and A-law (1 byte per sample),
              as telephony media carries them.
            enumValues:
              - l16
              - mulaw
              - alaw
            required: false
          - name: sample_rate
            type: integer
            description: >
              Sample rate of the audio in Hz. Required. Any integer from 8000 to
              48000.

              A missing value or a value outside that range closes the
              connection with `invalid_params` and close code `1008`.
            required: true
          - name: channels
            type: integer
            description: >
              Number of interleaved channels. Each channel is read on its own:
              stream the two legs of a call as

              two channels rather than a mono mix.
            required: false
operations:
  - &ref_1
    id: sendAudio
    title: Send Audio to Check
    description: >-
      Client sends binary audio frames, then an end_of_stream message when it
      has no more audio.
    type: receive
    messages:
      - &ref_3
        id: clientAudio
        contentType: application/octet-stream
        payload:
          - type: string
            format: binary
            description: >
              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.
            x-parser-schema-id: <anonymous-schema-1>
            name: Audio Frame
        headers: []
        jsonPayloadSchema:
          type: string
          format: binary
          description: Raw audio samples, interleaved by channel.
          x-parser-schema-id: <anonymous-schema-1>
        title: Audio Frame
        description: >
          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.
        example: '{}'
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: clientAudio
      - &ref_4
        id: clientEndOfStream
        contentType: application/json
        payload:
          - name: End of Stream
            description: >
              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.
            type: object
            properties:
              - name: type
                type: string
                description: Message type identifier.
                required: true
        headers: []
        jsonPayloadSchema:
          type: object
          required:
            - type
          properties:
            type:
              type: string
              const: end_of_stream
              description: Message type identifier.
              x-parser-schema-id: <anonymous-schema-3>
          x-parser-schema-id: <anonymous-schema-2>
        title: End of Stream
        description: >
          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.
        example: |-
          {
            "type": "end_of_stream"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: clientEndOfStream
    bindings: []
    extensions: &ref_0
      - id: x-parser-unique-object-id
        value: audio-watermark-detection-websockets
  - &ref_2
    id: receiveResults
    title: Receive Detection Results
    description: >-
      Server sends detection messages, a final summary message, and error frames
      to the client.
    type: send
    messages:
      - &ref_5
        id: serverDetection
        contentType: application/json
        payload:
          - name: Detection
            description: >
              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.
            type: object
            properties:
              - name: type
                type: string
                description: Message type identifier.
                required: true
              - name: channel
                type: integer
                description: Zero-based channel index.
                required: true
              - name: watermark_detected
                type: boolean
                description: >-
                  Always `true`. Channels without a watermark send no detection
                  message.
                required: true
              - name: detected_at_millis
                type: integer
                description: >-
                  Position in the channel's audio, in milliseconds, at which the
                  watermark read.
                required: true
        headers: []
        jsonPayloadSchema:
          type: object
          required:
            - type
            - channel
            - watermark_detected
            - detected_at_millis
          properties:
            type:
              type: string
              const: detection
              description: Message type identifier.
              x-parser-schema-id: <anonymous-schema-5>
            channel:
              type: integer
              minimum: 0
              description: Zero-based channel index.
              x-parser-schema-id: <anonymous-schema-6>
            watermark_detected:
              type: boolean
              const: true
              description: >-
                Always `true`. Channels without a watermark send no detection
                message.
              x-parser-schema-id: <anonymous-schema-7>
            detected_at_millis:
              type: integer
              description: >-
                Position in the channel's audio, in milliseconds, at which the
                watermark read.
              x-parser-schema-id: <anonymous-schema-8>
          x-parser-schema-id: <anonymous-schema-4>
        title: Detection
        description: >
          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.
        example: |-
          {
            "type": "detection",
            "channel": 0,
            "watermark_detected": true,
            "detected_at_millis": 4000
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: serverDetection
      - &ref_6
        id: serverSummary
        contentType: application/json
        payload:
          - name: Summary
            description: >
              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`.
            type: object
            properties:
              - name: type
                type: string
                description: Message type identifier.
                required: true
              - name: data
                type: object
                required: true
                properties:
                  - name: record_type
                    type: string
                    description: Identifies the type of the resource.
                    required: true
                  - name: id
                    type: string
                    description: >-
                      Unique identifier of this detection. Quote it when you
                      contact support.
                    required: true
                  - name: watermark_detected
                    type: boolean
                    description: >
                      `true` when the watermark read on at least one channel.
                      `false` means no watermark was read;

                      it does not prove the audio is not synthetic.
                    required: true
                  - name: confidence
                    type: string
                    description: >
                      How much to rely on `watermark_detected`. `high`: the
                      watermark read directly, or no sign of one

                      in at least 20 seconds of audio or in digital silence.
                      `medium`: read only after a wider search,

                      or no sign of one in less than 20 seconds. `low`: signs of
                      a watermark that could not be read,

                      or less than 2 seconds of audio.
                    enumValues:
                      - high
                      - medium
                      - low
                    required: true
                  - name: channels
                    type: array
                    description: The result for each channel, in channel order.
                    required: true
                    properties:
                      - name: channel
                        type: integer
                        description: Zero-based channel index.
                        required: true
                      - name: watermark_detected
                        type: boolean
                        description: '`true` when the watermark read on this channel.'
                        required: true
                  - name: audio
                    type: object
                    required: true
                    properties:
                      - name: duration_millis
                        type: integer
                        description: Duration of the audio received, in milliseconds.
                        required: true
                      - name: sample_rate
                        type: integer
                        description: The `sample_rate` query parameter.
                        required: true
                      - name: format
                        type: string
                        description: The `format` query parameter.
                        required: true
                      - name: channels
                        type: integer
                        description: The `channels` query parameter.
                        required: true
                  - name: created_at
                    type: string
                    description: >-
                      ISO 8601 timestamp of the result, in UTC with millisecond
                      precision.
                    required: true
        headers: []
        jsonPayloadSchema:
          type: object
          required:
            - type
            - data
          properties:
            type:
              type: string
              const: summary
              description: Message type identifier.
              x-parser-schema-id: <anonymous-schema-10>
            data:
              type: object
              required:
                - record_type
                - id
                - watermark_detected
                - confidence
                - channels
                - audio
                - created_at
              properties:
                record_type:
                  type: string
                  const: audio_watermark_detection
                  description: Identifies the type of the resource.
                  x-parser-schema-id: <anonymous-schema-12>
                id:
                  type: string
                  format: uuid
                  description: >-
                    Unique identifier of this detection. Quote it when you
                    contact support.
                  x-parser-schema-id: <anonymous-schema-13>
                watermark_detected:
                  type: boolean
                  description: >
                    `true` when the watermark read on at least one channel.
                    `false` means no watermark was read;

                    it does not prove the audio is not synthetic.
                  x-parser-schema-id: <anonymous-schema-14>
                confidence:
                  type: string
                  enum:
                    - high
                    - medium
                    - low
                  description: >
                    How much to rely on `watermark_detected`. `high`: the
                    watermark read directly, or no sign of one

                    in at least 20 seconds of audio or in digital silence.
                    `medium`: read only after a wider search,

                    or no sign of one in less than 20 seconds. `low`: signs of a
                    watermark that could not be read,

                    or less than 2 seconds of audio.
                  x-parser-schema-id: <anonymous-schema-15>
                channels:
                  type: array
                  description: The result for each channel, in channel order.
                  items:
                    type: object
                    required:
                      - channel
                      - watermark_detected
                    properties:
                      channel:
                        type: integer
                        minimum: 0
                        description: Zero-based channel index.
                        x-parser-schema-id: <anonymous-schema-18>
                      watermark_detected:
                        type: boolean
                        description: '`true` when the watermark read on this channel.'
                        x-parser-schema-id: <anonymous-schema-19>
                    x-parser-schema-id: <anonymous-schema-17>
                  x-parser-schema-id: <anonymous-schema-16>
                audio:
                  type: object
                  required:
                    - duration_millis
                    - sample_rate
                    - format
                    - channels
                  properties:
                    duration_millis:
                      type: integer
                      description: Duration of the audio received, in milliseconds.
                      x-parser-schema-id: <anonymous-schema-21>
                    sample_rate:
                      type: integer
                      description: The `sample_rate` query parameter.
                      x-parser-schema-id: <anonymous-schema-22>
                    format:
                      type: string
                      description: The `format` query parameter.
                      x-parser-schema-id: <anonymous-schema-23>
                    channels:
                      type: integer
                      description: The `channels` query parameter.
                      x-parser-schema-id: <anonymous-schema-24>
                  x-parser-schema-id: <anonymous-schema-20>
                created_at:
                  type: string
                  format: date-time
                  description: >-
                    ISO 8601 timestamp of the result, in UTC with millisecond
                    precision.
                  x-parser-schema-id: <anonymous-schema-25>
              x-parser-schema-id: <anonymous-schema-11>
          x-parser-schema-id: <anonymous-schema-9>
        title: Summary
        description: >
          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`.
        example: |-
          {
            "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"
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: serverSummary
      - &ref_7
        id: serverError
        contentType: application/json
        payload:
          - name: Error Frame
            description: >
              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` (close `1008`): a query parameter is missing or
              has an unsupported value.

              - `max_session_duration` (close `1008`): the session reached 590
              seconds or 60 minutes of audio. The `summary` message is sent
              first.

              - `internal_error` (close `1011`): detection failed. Reconnect and
              try again.

              - `overloaded` (close `1013`): 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"}`.
            type: object
            properties:
              - name: type
                type: string
                description: Frame type identifier.
                required: true
              - name: code
                type: string
                description: Stable error code.
                enumValues:
                  - invalid_params
                  - max_session_duration
                  - internal_error
                  - overloaded
                  - chunk_too_large
                  - decode_error
                  - unsupported_message
                required: true
              - name: message
                type: string
                description: Human-readable description. Do not parse it.
                required: true
        headers: []
        jsonPayloadSchema:
          type: object
          required:
            - type
            - code
            - message
          properties:
            type:
              type: string
              const: error
              description: Frame type identifier.
              x-parser-schema-id: <anonymous-schema-27>
            code:
              type: string
              description: Stable error code.
              enum:
                - invalid_params
                - max_session_duration
                - internal_error
                - overloaded
                - chunk_too_large
                - decode_error
                - unsupported_message
              x-parser-schema-id: <anonymous-schema-28>
            message:
              type: string
              description: Human-readable description. Do not parse it.
              x-parser-schema-id: <anonymous-schema-29>
          x-parser-schema-id: <anonymous-schema-26>
        title: Error Frame
        description: >
          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` (close `1008`): a query parameter is missing or has
          an unsupported value.

          - `max_session_duration` (close `1008`): the session reached 590
          seconds or 60 minutes of audio. The `summary` message is sent first.

          - `internal_error` (close `1011`): detection failed. Reconnect and try
          again.

          - `overloaded` (close `1013`): 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"}`.
        example: |-
          {
            "type": "error",
            "code": "invalid_params",
            "message": "sample_rate is required: the audio's rate in Hz, 8000-48000"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: serverError
    bindings: []
    extensions: *ref_0
sendOperations:
  - *ref_1
receiveOperations:
  - *ref_2
sendMessages:
  - *ref_3
  - *ref_4
receiveMessages:
  - *ref_5
  - *ref_6
  - *ref_7
extensions:
  - id: x-parser-unique-object-id
    value: audio-watermark-detection-websockets
securitySchemes:
  - id: bearerAuth
    name: bearerAuth
    type: http
    description: Telnyx API v2 Bearer token authentication.
    scheme: bearer
    extensions: []

````