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

# Remove background noise over WebSocket

> Stream raw mono PCM audio and receive denoised audio in the same format and sample rate.
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`. A `sample_rate` or `channels`
value that is not a valid non-negative integer fails with HTTP `400`. While the server restarts, new connections fail with HTTP
`503`; reconnect with backoff. Any other unsupported parameter value closes the connection with
an `invalid_params` error frame and close code `1008`.

Sessions are limited to 590 seconds. At the limit, the server returns the remaining audio,
sends a `max_session_duration` error frame, and closes with `1008`.




## AsyncAPI

````yaml openapi/asyncapi/noise-suppression-websockets/noise-suppression-websockets.yml noise-suppression-websockets
id: noise-suppression-websockets
title: Remove background noise over WebSocket
description: >
  Stream raw mono PCM audio and receive denoised audio in the same format and
  sample rate.

  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`. A `sample_rate` or
  `channels`

  value that is not a valid non-negative integer fails with HTTP `400`. While
  the server restarts, new connections fail with HTTP

  `503`; reconnect with backoff. Any other unsupported parameter value closes
  the connection with

  an `invalid_params` error frame and close code `1008`.


  Sessions are limited to 590 seconds. At the limit, the server returns the
  remaining audio,

  sends a `max_session_duration` error frame, and closes with `1008`.
servers:
  - id: noise-suppression-websockets
    protocol: wss
    host: api.telnyx.com
    bindings:
      - protocol: ws
        version: 0.1.0
        value: {}
        schemaProperties: []
    variables: []
address: /v2/noise_suppression
parameters: []
bindings:
  - protocol: ws
    version: 0.1.0
    value:
      query:
        type: object
        description: Query parameters passed when opening the WebSocket connection.
        properties:
          format:
            type: string
            description: >
              Audio encoding, used for both input and output.

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

              `f32le` is 32-bit float PCM in the range -1.0 to 1.0,
              little-endian (4 bytes per sample).
            enum:
              - l16
              - f32le
            default: l16
          sample_rate:
            type: integer
            description: >
              Sample rate in Hz, used for both input and output. Any integer
              from 8000 to 48000.

              A value outside that range closes the connection with
              `invalid_params` and close code `1008`.

              Send telephony and PSTN audio at `8000`. Do not upsample 8 kHz
              audio to a higher rate: the

              full-band model treats the missing upper band as noise and lowers
              the speech level by about 14 dB.
            minimum: 8000
            maximum: 48000
            default: 16000
          channels:
            type: integer
            description: Number of channels. Only mono audio is supported.
            enum:
              - 1
            default: 1
          model:
            type: string
            description: >
              Noise suppression model. The service selects the model variant
              from `sample_rate`.

              `rook` is for audio that people listen to: the 8 kHz model at
              8000, the 16 kHz model from

              8001 to 16000, and the 48 kHz model above 16000. `quail` is for
              audio that goes to

              speech-to-text: the 8 kHz model at 8000 and the 16 kHz model above
              8000, so its output

              bandwidth is limited to 8 kHz.
            enum:
              - rook
              - quail
            default: rook
          quality:
            description: >
              Enhancement strength: how much noise the model removes.

              A number from `0.0` (lightest processing) to `1.0` (strongest), or
              a preset:

              `low_latency` (0.5, lighter processing; the name is kept for
              compatibility),

              `balanced` (0.8), or `high_quality` (1.0).
            default: balanced
            oneOf:
              - type: number
                minimum: 0
                maximum: 1
              - type: string
                enum:
                  - low_latency
                  - balanced
                  - high_quality
    schemaProperties:
      - name: query
        type: object
        description: Query parameters passed when opening the WebSocket connection.
        required: false
        properties:
          - name: format
            type: string
            description: >
              Audio encoding, used for both input and output.

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

              `f32le` is 32-bit float PCM in the range -1.0 to 1.0,
              little-endian (4 bytes per sample).
            enumValues:
              - l16
              - f32le
            required: false
          - name: sample_rate
            type: integer
            description: >
              Sample rate in Hz, used for both input and output. Any integer
              from 8000 to 48000.

              A value outside that range closes the connection with
              `invalid_params` and close code `1008`.

              Send telephony and PSTN audio at `8000`. Do not upsample 8 kHz
              audio to a higher rate: the

              full-band model treats the missing upper band as noise and lowers
              the speech level by about 14 dB.
            required: false
          - name: channels
            type: integer
            description: Number of channels. Only mono audio is supported.
            enumValues:
              - 1
            required: false
          - name: model
            type: string
            description: >
              Noise suppression model. The service selects the model variant
              from `sample_rate`.

              `rook` is for audio that people listen to: the 8 kHz model at
              8000, the 16 kHz model from

              8001 to 16000, and the 48 kHz model above 16000. `quail` is for
              audio that goes to

              speech-to-text: the 8 kHz model at 8000 and the 16 kHz model above
              8000, so its output

              bandwidth is limited to 8 kHz.
            enumValues:
              - rook
              - quail
            required: false
          - name: quality
            type: oneOf
            description: >
              Enhancement strength: how much noise the model removes.

              A number from `0.0` (lightest processing) to `1.0` (strongest), or
              a preset:

              `low_latency` (0.5, lighter processing; the name is kept for
              compatibility),

              `balanced` (0.8), or `high_quality` (1.0).
            required: false
operations:
  - &ref_1
    id: sendAudio
    title: Send Audio to Denoise
    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 mono PCM audio, in the
              `format` and `sample_rate`

              set on the connection. No container and no WAV header.

              The frame must contain a whole number of samples (a multiple of 2
              bytes for `l16`,

              4 bytes for `f32le`) 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 PCM audio samples, little-endian.
          x-parser-schema-id: <anonymous-schema-1>
        title: Audio Frame
        description: >
          Client-to-server binary frame with raw mono PCM audio, in the `format`
          and `sample_rate`

          set on the connection. No container and no WAV header.

          The frame must contain a whole number of samples (a multiple of 2
          bytes for `l16`,

          4 bytes for `f32le`) 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 returns all

              remaining audio, including the audio held back by the model's
              processing delay, as one final

              binary frame, then closes with code `1000`. If you close the
              connection without it, the end of

              your stream is lost. 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 returns all

          remaining audio, including the audio held back by the model's
          processing delay, as one final

          binary frame, then closes with code `1000`. If you close the
          connection without it, the end of

          your stream is lost. 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: noise-suppression-websockets
  - &ref_2
    id: receiveAudio
    title: Receive Denoised Audio
    description: Server sends denoised audio frames and error frames to the client.
    type: send
    messages:
      - &ref_5
        id: serverAudio
        contentType: application/octet-stream
        payload:
          - type: string
            format: binary
            description: >
              Server-to-client binary frame with denoised audio, in the same
              `format` and `sample_rate` as

              the input. The model processes fixed-size internal frames and has
              a short processing delay, so

              a frame can be smaller or larger than the matching input frame, or
              empty. Ignore empty frames. Over the session, total output equals
              the input length plus the processing delay.
            x-parser-schema-id: <anonymous-schema-4>
            name: Denoised Audio Frame
        headers: []
        jsonPayloadSchema:
          type: string
          format: binary
          description: Denoised raw PCM audio samples, little-endian.
          x-parser-schema-id: <anonymous-schema-4>
        title: Denoised Audio Frame
        description: >
          Server-to-client binary frame with denoised audio, in the same
          `format` and `sample_rate` as

          the input. The model processes fixed-size internal frames and has a
          short processing delay, so

          a frame can be smaller or larger than the matching input frame, or
          empty. Ignore empty frames. Over the session, total output equals the
          input length plus the processing delay.
        example: '{}'
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: serverAudio
      - &ref_6
        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 has an
              unsupported value.

              - `max_session_duration` (close `1008`): the session reached the
              590-second limit. The remaining audio is returned first.

              - `server_shutdown` (close `1001`): the server is restarting. The
              remaining audio is returned first. Reconnect with backoff.

              - `session_error` (close `1011`): the server could not start the
              noise suppression session.

              - `processing_error` (close `1011`): the noise suppression engine
              failed.

              - `encode_error` (close `1011`): the server could not encode the
              denoised audio.

              - `max_connections` (close `1013`): the server has too many open
              sessions. Try again later.

              - `overloaded` (close `1013`): the server is overloaded and does
              not accept new sessions. Try again later.

              - `chunk_too_large` (session continues): the binary frame is
              larger than 65,536 bytes. The chunk is dropped.

              - `decode_error` (session continues): the frame length is not a
              whole number of samples. The chunk is dropped.

              - `unsupported_message` (session continues): the text frame is not
              a supported message.
            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
                  - server_shutdown
                  - session_error
                  - processing_error
                  - encode_error
                  - max_connections
                  - 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-6>
            code:
              type: string
              description: Stable error code.
              enum:
                - invalid_params
                - max_session_duration
                - server_shutdown
                - session_error
                - processing_error
                - encode_error
                - max_connections
                - overloaded
                - chunk_too_large
                - decode_error
                - unsupported_message
              x-parser-schema-id: <anonymous-schema-7>
            message:
              type: string
              description: Human-readable description. Do not parse it.
              x-parser-schema-id: <anonymous-schema-8>
          x-parser-schema-id: <anonymous-schema-5>
        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 has an
          unsupported value.

          - `max_session_duration` (close `1008`): the session reached the
          590-second limit. The remaining audio is returned first.

          - `server_shutdown` (close `1001`): the server is restarting. The
          remaining audio is returned first. Reconnect with backoff.

          - `session_error` (close `1011`): the server could not start the noise
          suppression session.

          - `processing_error` (close `1011`): the noise suppression engine
          failed.

          - `encode_error` (close `1011`): the server could not encode the
          denoised audio.

          - `max_connections` (close `1013`): the server has too many open
          sessions. Try again later.

          - `overloaded` (close `1013`): the server is overloaded and does not
          accept new sessions. Try again later.

          - `chunk_too_large` (session continues): the binary frame is larger
          than 65,536 bytes. The chunk is dropped.

          - `decode_error` (session continues): the frame length is not a whole
          number of samples. The chunk is dropped.

          - `unsupported_message` (session continues): the text frame is not a
          supported message.
        example: |-
          {
            "type": "error",
            "code": "invalid_params",
            "message": "unsupported sample_rate 96000 (supported: 8000-48000 Hz)"
          }
        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
extensions:
  - id: x-parser-unique-object-id
    value: noise-suppression-websockets
securitySchemes:
  - id: bearerAuth
    name: bearerAuth
    type: http
    description: Telnyx API v2 Bearer token authentication.
    scheme: bearer
    extensions: []

````