> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.bakbak.si/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.bakbak.si/_mcp/server.

# WebSocket

GET /v1/text-to-speech/ws

Many streaming synthesis requests on one connection. Each request runs exactly like `POST /v1/text-to-speech/stream`: the same validation, billing and limits.

The [WebSocket guide](/text-to-speech/websocket) covers ordering, cancellation, errors, limits and close codes.

- **You send:** One JSON text message per synthesis request, or a cancel for a context.
- **You receive:** Zero or more chunks per request, then exactly one done or error; one cancelled per cancel.

Reference: https://docs.bakbak.si/api-reference/text-to-speech/websocket

## AsyncAPI Specification

```yaml
asyncapi: 2.6.0
info:
  title: tts
  version: subpackage_tts.tts
  description: >-
    Many streaming synthesis requests on one connection. Each request runs
    exactly like `POST /v1/text-to-speech/stream`: the same validation, billing
    and limits.


    The [WebSocket guide](/text-to-speech/websocket) covers ordering,
    cancellation, errors, limits and close codes.


    - **You send:** One JSON text message per synthesis request, or a cancel for
    a context.

    - **You receive:** Zero or more chunks per request, then exactly one done or
    error; one cancelled per cancel.
channels:
  /v1/text-to-speech/ws:
    description: >-
      Many streaming synthesis requests on one connection. Each request runs
      exactly like `POST /v1/text-to-speech/stream`: the same validation,
      billing and limits.


      The [WebSocket guide](/text-to-speech/websocket) covers ordering,
      cancellation, errors, limits and close codes.


      - **You send:** One JSON text message per synthesis request, or a cancel
      for a context.

      - **You receive:** Zero or more chunks per request, then exactly one done
      or error; one cancelled per cancel.
    publish:
      operationId: subpackage_tts.tts-publish
      summary: Server messages
      message:
        oneOf:
          - $ref: '#/components/messages/subpackage_tts.tts-server-0-chunk'
          - $ref: '#/components/messages/subpackage_tts.tts-server-1-done'
          - $ref: '#/components/messages/subpackage_tts.tts-server-2-error'
          - $ref: '#/components/messages/subpackage_tts.tts-server-3-cancelled'
    subscribe:
      operationId: subpackage_tts.tts-subscribe
      summary: Client messages
      message:
        oneOf:
          - $ref: '#/components/messages/subpackage_tts.tts-client-0-synthesisRequest'
          - $ref: '#/components/messages/subpackage_tts.tts-client-1-cancelRequest'
servers:
  Production server:
    url: wss://hub.getraya.app/
    protocol: wss
components:
  messages:
    subpackage_tts.tts-server-0-chunk:
      name: chunk
      title: chunk
      description: Base64 audio of one request, in the request's `output_format`.
      payload:
        $ref: '#/components/schemas/tts_chunk'
    subpackage_tts.tts-server-1-done:
      name: done
      title: done
      description: The request's last message when it succeeds.
      payload:
        $ref: '#/components/schemas/tts_done'
    subpackage_tts.tts-server-2-error:
      name: error
      title: error
      description: >-
        Ends one request only; the connection and other contexts carry on.
        `status_code` is the HTTP status the same failure gets on the streaming
        endpoint, and the endpoint's error fields are included. An error with
        neither `context_id` nor `request_id` is about a message that was not a
        request.
      payload:
        $ref: '#/components/schemas/tts_error'
    subpackage_tts.tts-server-3-cancelled:
      name: cancelled
      title: cancelled
      description: The answer to a cancel.
      payload:
        $ref: '#/components/schemas/tts_cancelled'
    subpackage_tts.tts-client-0-synthesisRequest:
      name: synthesisRequest
      title: synthesisRequest
      description: Send one JSON text message per request.
      payload:
        $ref: '#/components/schemas/tts_synthesisRequest'
    subpackage_tts.tts-client-1-cancelRequest:
      name: cancelRequest
      title: cancelRequest
      description: >-
        Stops the context's running request and drops the ones queued behind it.
        Answered by exactly one `cancelled`; nothing sent before the cancel
        arrives after it.
      payload:
        $ref: '#/components/schemas/tts_cancelRequest'
  schemas:
    ContextId:
      type: string
      pattern: ^[A-Za-z0-9._-]{1,128}$
      description: >-
        Groups requests: requests with the same `context_id` run one after
        another in the order sent; different contexts run at the same time and
        their messages interleave. Echoed on every message about the request.
        Requests without one share one implicit context.
      title: ContextId
    RequestId:
      type: string
      description: The request's id. Quote it to support.
      title: RequestId
    tts_chunk:
      type: object
      properties:
        type:
          type: string
          enum:
            - chunk
        status_code:
          type: integer
        done:
          type: boolean
          enum:
            - false
        data:
          type: string
          description: Base64-encoded audio.
        step_time:
          type: number
          format: double
          description: Seconds the model took for this chunk.
        context_id:
          $ref: '#/components/schemas/ContextId'
        request_id:
          $ref: '#/components/schemas/RequestId'
      title: tts_chunk
    tts_done:
      type: object
      properties:
        type:
          type: string
          enum:
            - done
        status_code:
          type: integer
        done:
          type: boolean
          enum:
            - true
        context_id:
          $ref: '#/components/schemas/ContextId'
        request_id:
          $ref: '#/components/schemas/RequestId'
      title: tts_done
    tts_error:
      type: object
      properties:
        type:
          type: string
          enum:
            - error
        status_code:
          type: integer
        done:
          type: boolean
          enum:
            - true
        message:
          type: string
        error_code:
          type: string
          description: What went wrong, from the fixed list on the Errors page.
        retryable:
          type: boolean
        detail:
          description: Validation entries on a 422.
        context_id:
          $ref: '#/components/schemas/ContextId'
        request_id:
          $ref: '#/components/schemas/RequestId'
      title: tts_error
    tts_cancelled:
      type: object
      properties:
        type:
          type: string
          enum:
            - cancelled
        done:
          type: boolean
          enum:
            - true
        context_id:
          $ref: '#/components/schemas/ContextId'
      title: tts_cancelled
    ChannelsTtsMessagesSynthesisRequestModel:
      type: string
      enum:
        - standard
        - m1
      default: standard
      description: >
        The synthesis model to use. Each model has its own set of voices — use
        `/v1/voices` to find voice IDs for the model you choose.


        **Important:** `standard` and `m1` voices are not interchangeable.
        Passing a `standard` voice ID with `"model": "m1"` (or vice versa) will
        fail.
      title: ChannelsTtsMessagesSynthesisRequestModel
    ChannelsTtsMessagesSynthesisRequestLanguage:
      type: string
      enum:
        - hi
        - mr
        - te
        - kn
        - bn
        - as
        - gu
        - ne
        - ml
        - ta
        - en-in
        - en-us
      description: >
        Language code for the text. Currently supported: hi (Hindi), mr
        (Marathi), te (Telugu), kn (Kannada), bn (Bengali), as (Assamese), gu
        (Gujarati), ne (Nepali), ml (Malayalam), ta (Tamil), en-in (Indian
        English), en-us (US English).


        Hindi must be written in Devanagari script (Romanized Hindi is not
        supported). For English, Indic named entities are best written in
        Devanagari for accurate pronunciation.

        More languages are coming soon.
      title: ChannelsTtsMessagesSynthesisRequestLanguage
    OutputFormatContainer:
      type: string
      enum:
        - raw
      default: raw
      description: >-
        `raw` for headerless audio, `wav` for a WAV file, `mp3` for MP3. `wav`
        and `mp3` are only available on `/v1/text-to-speech`; the streaming
        endpoint accepts only `raw`.
      title: OutputFormatContainer
    OutputFormatEncoding:
      type: string
      enum:
        - pcm_f32le
        - pcm_s16le
        - pcm_mulaw
        - pcm_alaw
      description: >-
        Sample encoding. Required for `raw` and `wav`; omit it for `mp3`. Audio
        is always mono.

        - `pcm_f32le`: 32-bit float, little-endian

        - `pcm_s16le`: 16-bit signed integer, little-endian

        - `pcm_mulaw`: G.711 μ-law (PCMU), 1 byte per sample

        - `pcm_alaw`: G.711 A-law (PCMA), 1 byte per sample
      title: OutputFormatEncoding
    OutputFormatSampleRate:
      type: string
      enum:
        - '8000'
        - '16000'
        - '22050'
        - '24000'
      description: Sample rate in Hz.
      title: OutputFormatSampleRate
    OutputFormat:
      type: object
      properties:
        container:
          $ref: '#/components/schemas/OutputFormatContainer'
          default: raw
          description: >-
            `raw` for headerless audio, `wav` for a WAV file, `mp3` for MP3.
            `wav` and `mp3` are only available on `/v1/text-to-speech`; the
            streaming endpoint accepts only `raw`.
        encoding:
          $ref: '#/components/schemas/OutputFormatEncoding'
          description: >-
            Sample encoding. Required for `raw` and `wav`; omit it for `mp3`.
            Audio is always mono.

            - `pcm_f32le`: 32-bit float, little-endian

            - `pcm_s16le`: 16-bit signed integer, little-endian

            - `pcm_mulaw`: G.711 μ-law (PCMU), 1 byte per sample

            - `pcm_alaw`: G.711 A-law (PCMA), 1 byte per sample
        sample_rate:
          $ref: '#/components/schemas/OutputFormatSampleRate'
          default: 24000
          description: Sample rate in Hz.
      description: >-
        Encoding and sample rate of the audio chunks. Only the `raw` container
        is accepted on the WebSocket.
      title: OutputFormat
    tts_synthesisRequest:
      type: object
      properties:
        text:
          type: string
          description: >
            The text to convert to speech.


            **Script notes:**

            - Hindi (`language`: `hi`) must be in Devanagari script. Romanized
            Hindi is not supported.

            - For English (`en-in`, `en-us`), Indic named entities (names,
            places, etc.) are pronounced more accurately in Devanagari — e.g.
            `राहुल` instead of `Rahul`. If text is LLM-generated, prompt it to
            output Indic names in Devanagari even when the rest of the content
            is in English.
        voice_id:
          type: string
          description: >
            The ID of the voice to use for synthesis. Use `/v1/voices` to get
            available voice IDs.

            The `voice_id` must match the `model` you specify — `standard`
            voices only work with `"model": "standard"`, and `m1` voices only
            work with `"model": "m1"`.
        model:
          $ref: '#/components/schemas/ChannelsTtsMessagesSynthesisRequestModel'
          default: standard
          description: >
            The synthesis model to use. Each model has its own set of voices —
            use `/v1/voices` to find voice IDs for the model you choose.


            **Important:** `standard` and `m1` voices are not interchangeable.
            Passing a `standard` voice ID with `"model": "m1"` (or vice versa)
            will fail.
        language:
          $ref: '#/components/schemas/ChannelsTtsMessagesSynthesisRequestLanguage'
          description: >
            Language code for the text. Currently supported: hi (Hindi), mr
            (Marathi), te (Telugu), kn (Kannada), bn (Bengali), as (Assamese),
            gu (Gujarati), ne (Nepali), ml (Malayalam), ta (Tamil), en-in
            (Indian English), en-us (US English).


            Hindi must be written in Devanagari script (Romanized Hindi is not
            supported). For English, Indic named entities are best written in
            Devanagari for accurate pronunciation.

            More languages are coming soon.
        speed:
          type: string
          title: float
          description: >-
            Speech speed multiplier (0.5 to 1.5). Changes standard voices only;
            m1 voices ignore it.
          default: 1
        output_format:
          $ref: '#/components/schemas/OutputFormat'
        context_id:
          $ref: '#/components/schemas/ContextId'
      required:
        - text
        - voice_id
        - language
      description: >-
        One synthesis request. The body of `POST /v1/text-to-speech/stream`,
        with every field and rule unchanged, plus an optional `context_id`.
        `output_format.container` must be `raw`.
      title: tts_synthesisRequest
    tts_cancelRequest:
      type: object
      properties:
        context_id:
          $ref: '#/components/schemas/ContextId'
        cancel:
          type: boolean
          enum:
            - true
      required:
        - context_id
        - cancel
      title: tts_cancelRequest

```