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

# TTS WebSocket

> Bidirectional text-to-speech channel. Authenticate with the `chariotai-api-key` header, or with the `api_key` query parameter when your client cannot set handshake headers.
Binary frames carrying audio are interleaved between the `audio.start` and `audio.done` messages and are not modelled as JSON messages below.
The connection closes with code `1000` on success, `1008` on an auth or parameter problem, `1011` on an upstream failure, and `4402` when the workspace runs out of credits.




## AsyncAPI

````yaml api-reference/asyncapi.yaml ttsStream
id: ttsStream
title: Text to speech stream
description: >
  Bidirectional text-to-speech channel. Authenticate with the
  `chariotai-api-key` header, or with the `api_key` query parameter when your
  client cannot set handshake headers.

  Binary frames carrying audio are interleaved between the `audio.start` and
  `audio.done` messages and are not modelled as JSON messages below.

  The connection closes with code `1000` on success, `1008` on an auth or
  parameter problem, `1011` on an upstream failure, and `4402` when the
  workspace runs out of credits.
servers:
  - id: production
    protocol: wss
    host: api.chariot.in
    bindings: []
    variables: []
address: /v1/tts/ws
parameters: []
bindings:
  - protocol: ws
    version: 0.1.0
    value:
      method: GET
      query:
        type: object
        required:
          - voice_id
        properties:
          voice_id:
            type: string
            format: uuid
            description: >
              Required. UUID of the voice to synthesize with. Get one from `GET
              /v1/voices`.
            examples: &ref_0
              - bac7d666-094d-4698-91fa-741d60fce662
          response_format:
            type: string
            enum:
              - pcm
              - wav
            default: pcm
            examples: &ref_1
              - pcm
            description: >
              Encoding of the binary audio frames. `pcm` is raw signed 16-bit
              little-endian PCM; `wav` is a streaming WAV (RIFF header followed
              by PCM). Defaults to `pcm`.
          idle_timeout:
            type: number
            default: 60
            exclusiveMinimum: 0
            maximum: 300
            examples: &ref_2
              - 60
            description: >
              Seconds the server waits for a client message before closing the
              session as idle. Must be greater than 0 and at most 300. Defaults
              to 60.
          enable_logging:
            type: boolean
            default: false
            examples: &ref_3
              - false
            description: >
              When true, each generated segment is archived to your TTS history
              and the audio is stored for later retrieval. Defaults to false.
          api_key:
            type: string
            description: >
              Your API key. No default. Prefer the `chariotai-api-key` header
              where your client supports it, and use this query parameter only
              when the client cannot set handshake headers.
    schemaProperties:
      - name: method
        type: string
        description: GET
        required: false
      - name: query
        type: object
        required: false
        properties:
          - name: voice_id
            type: string
            description: >
              Required. UUID of the voice to synthesize with. Get one from `GET
              /v1/voices`.
            examples: *ref_0
            required: true
          - name: response_format
            type: string
            description: >
              Encoding of the binary audio frames. `pcm` is raw signed 16-bit
              little-endian PCM; `wav` is a streaming WAV (RIFF header followed
              by PCM). Defaults to `pcm`.
            enumValues:
              - pcm
              - wav
            examples: *ref_1
            required: false
          - name: idle_timeout
            type: number
            description: >
              Seconds the server waits for a client message before closing the
              session as idle. Must be greater than 0 and at most 300. Defaults
              to 60.
            examples: *ref_2
            required: false
          - name: enable_logging
            type: boolean
            description: >
              When true, each generated segment is archived to your TTS history
              and the audio is stored for later retrieval. Defaults to false.
            examples: *ref_3
            required: false
          - name: api_key
            type: string
            description: >
              Your API key. No default. Prefer the `chariotai-api-key` header
              where your client supports it, and use this query parameter only
              when the client cannot set handshake headers.
            required: false
operations:
  - &ref_7
    id: sendToChariot
    title: Client to server
    description: Messages you send to Chariot.
    type: receive
    messages:
      - &ref_9
        id: inputText
        payload:
          - name: Append text
            description: >-
              Add text to the server's buffer. Does not generate audio on its
              own.
            type: object
            properties:
              - name: type
                type: string
                description: input.text
                required: true
              - name: text
                type: string
                description: The text to append to the buffer.
                examples: &ref_4
                  - 'Hello and welcome. '
                required: true
        headers: []
        jsonPayloadSchema:
          type: object
          required:
            - type
            - text
          properties:
            type:
              type: string
              const: input.text
              x-parser-schema-id: <anonymous-schema-2>
            text:
              type: string
              description: The text to append to the buffer.
              examples: *ref_4
              x-parser-schema-id: <anonymous-schema-3>
          x-parser-schema-id: <anonymous-schema-1>
        title: Append text
        description: Add text to the server's buffer. Does not generate audio on its own.
        example: |-
          {
            "type": "<string>",
            "text": "<string>"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: inputText
      - &ref_10
        id: inputFlush
        payload:
          - name: Flush and generate
            description: >
              Synthesize everything currently buffered and stream the audio
              back. The session stays open. Flushing is what triggers
              generation.
            type: object
            properties:
              - name: type
                type: string
                description: input.flush
                required: true
        headers: []
        jsonPayloadSchema:
          type: object
          required:
            - type
          properties:
            type:
              type: string
              const: input.flush
              x-parser-schema-id: <anonymous-schema-5>
          x-parser-schema-id: <anonymous-schema-4>
        title: Flush and generate
        description: >
          Synthesize everything currently buffered and stream the audio back.
          The session stays open. Flushing is what triggers generation.
        example: |-
          {
            "type": "<string>"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: inputFlush
      - &ref_11
        id: inputDone
        payload:
          - name: End input
            description: >
              Signal that no more text is coming. The server flushes the
              remainder and finishes the session.
            type: object
            properties:
              - name: type
                type: string
                description: input.done
                required: true
        headers: []
        jsonPayloadSchema:
          type: object
          required:
            - type
          properties:
            type:
              type: string
              const: input.done
              x-parser-schema-id: <anonymous-schema-7>
          x-parser-schema-id: <anonymous-schema-6>
        title: End input
        description: >
          Signal that no more text is coming. The server flushes the remainder
          and finishes the session.
        example: |-
          {
            "type": "<string>"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: inputDone
    bindings: []
    extensions: &ref_6
      - id: x-parser-unique-object-id
        value: ttsStream
  - &ref_8
    id: receiveFromChariot
    title: Server to client
    description: Messages Chariot sends back to you.
    type: send
    messages:
      - &ref_12
        id: audioStart
        payload:
          - name: Segment started
            description: A new audio segment is about to stream as binary frames.
            type: object
            properties:
              - name: type
                type: string
                description: audio.start
                required: false
              - name: sentence_index
                type: integer
                description: Zero-based index of this segment within the session.
                required: false
              - name: sentence_text
                type: string
                description: The text being spoken in this segment.
                required: false
              - name: format
                type: string
                enumValues:
                  - pcm
                  - wav
                required: false
              - name: sample_rate
                type: integer
                required: false
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            type:
              type: string
              const: audio.start
              x-parser-schema-id: <anonymous-schema-9>
            sentence_index:
              type: integer
              description: Zero-based index of this segment within the session.
              x-parser-schema-id: <anonymous-schema-10>
            sentence_text:
              type: string
              description: The text being spoken in this segment.
              x-parser-schema-id: <anonymous-schema-11>
            format:
              type: string
              enum:
                - pcm
                - wav
              x-parser-schema-id: <anonymous-schema-12>
            sample_rate:
              type: integer
              default: 44100
              x-parser-schema-id: <anonymous-schema-13>
          x-parser-schema-id: <anonymous-schema-8>
        title: Segment started
        description: A new audio segment is about to stream as binary frames.
        example: |-
          {
            "type": "<string>",
            "sentence_index": 123,
            "sentence_text": "<string>",
            "format": "<string>",
            "sample_rate": 123
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: audioStart
      - &ref_13
        id: audioDone
        payload:
          - name: Segment finished
            description: >
              The current segment has finished streaming. Carries the credits
              charged for this segment.
            type: object
            properties:
              - name: type
                type: string
                description: audio.done
                required: false
              - name: sentence_index
                type: integer
                required: false
              - name: total_bytes
                type: integer
                description: Total bytes of audio streamed for this segment.
                required: false
              - name: credits_utilized
                type: integer
                description: Credits charged for this segment (1 per character).
                required: false
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            type:
              type: string
              const: audio.done
              x-parser-schema-id: <anonymous-schema-15>
            sentence_index:
              type: integer
              x-parser-schema-id: <anonymous-schema-16>
            total_bytes:
              type: integer
              description: Total bytes of audio streamed for this segment.
              x-parser-schema-id: <anonymous-schema-17>
            credits_utilized:
              type: integer
              description: Credits charged for this segment (1 per character).
              x-parser-schema-id: <anonymous-schema-18>
          x-parser-schema-id: <anonymous-schema-14>
        title: Segment finished
        description: >
          The current segment has finished streaming. Carries the credits
          charged for this segment.
        example: |-
          {
            "type": "<string>",
            "sentence_index": 123,
            "total_bytes": 123,
            "credits_utilized": 123
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: audioDone
      - &ref_14
        id: sessionDone
        payload:
          - name: Session complete
            description: >
              All segments are complete. The server then closes the connection
              with code 1000.
            type: object
            properties:
              - name: type
                type: string
                description: session.done
                required: false
              - name: total_sentences
                type: integer
                required: false
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            type:
              type: string
              const: session.done
              x-parser-schema-id: <anonymous-schema-20>
            total_sentences:
              type: integer
              x-parser-schema-id: <anonymous-schema-21>
          x-parser-schema-id: <anonymous-schema-19>
        title: Session complete
        description: >
          All segments are complete. The server then closes the connection with
          code 1000.
        example: |-
          {
            "type": "<string>",
            "total_sentences": 123
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: sessionDone
      - &ref_15
        id: errorMessage
        payload:
          - name: Error
            description: >
              An error occurred. Terminal errors carry a `code` matching the
              WebSocket close code that follows.
            type: object
            properties:
              - name: type
                type: string
                description: error
                required: false
              - name: code
                type: integer
                description: >
                  Matches the close code, for example 4402 for insufficient
                  credits.
                required: false
              - name: message
                type: string
                examples: &ref_5
                  - insufficient credits
                required: false
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            type:
              type: string
              const: error
              x-parser-schema-id: <anonymous-schema-23>
            code:
              type: integer
              description: >
                Matches the close code, for example 4402 for insufficient
                credits.
              x-parser-schema-id: <anonymous-schema-24>
            message:
              type: string
              examples: *ref_5
              x-parser-schema-id: <anonymous-schema-25>
          x-parser-schema-id: <anonymous-schema-22>
        title: Error
        description: >
          An error occurred. Terminal errors carry a `code` matching the
          WebSocket close code that follows.
        example: |-
          {
            "type": "<string>",
            "code": 123,
            "message": "<string>"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: errorMessage
    bindings: []
    extensions: *ref_6
sendOperations:
  - *ref_7
receiveOperations:
  - *ref_8
sendMessages:
  - *ref_9
  - *ref_10
  - *ref_11
receiveMessages:
  - *ref_12
  - *ref_13
  - *ref_14
  - *ref_15
extensions:
  - id: x-parser-unique-object-id
    value: ttsStream
securitySchemes: []

````