> ## Documentation Index
> Fetch the complete documentation index at: https://smallestai-ff1e543d.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Lightning v3.1 WebSocket

> The Lightning v3.1 WebSocket API provides real-time text-to-speech streaming capabilities with natural, expressive voice synthesis. This API uses WebSocket to deliver audio chunks as they're generated, enabling low-latency audio playback without waiting for the entire audio file to process.

## Overview

The Lightning v3.1 WebSocket API delivers state-of-the-art text-to-speech synthesis through a persistent WebSocket connection, providing ultra-low latency audio streaming for applications that demand real-time voice generation. Unlike traditional HTTP-based TTS APIs, this WebSocket implementation streams audio chunks as they're processed, significantly reducing perceived latency and enabling seamless user experiences.

Lightning v3.1 is a 44 kHz model that produces natural, expressive, and realistic speech, with support for voice cloning.

## Key Benefits

* **Ultra-Low Latency**: Audio chunks delivered as soon as they're generated
* **Real-Time Streaming**: Continuous audio delivery without waiting for complete text processing
* **Natural Speech**: Expressive synthesis that sounds realistic
* **Voice Cloning Support**: Compatible with cloned voices
* **Persistent Connection**: Maintains connection for multiple requests, reducing connection overhead
* **Interactive Applications**: Perfect for chatbots, voice assistants, and live communication systems

## Use Cases

* **Voice Assistants**: Real-time response generation for conversational AI
* **Interactive Chatbots**: Immediate audio feedback for user interactions
* **Live Streaming**: Real-time narration and commentary
* **Accessibility Tools**: Screen readers and text-to-speech applications
* **Gaming**: Dynamic voice generation for characters and narration
* **Customer Service**: Automated voice responses with natural speech patterns

## Concurrency and Rate Limits

This WebSocket API is subject to concurrency limits to ensure optimal performance for all users. Here's how it works:

* **1 Concurrency Unit** = 1 active TTS request that can be processed at any given time
* **5 WebSocket Connections** can be established per concurrency unit
* **Total Connections** = Your concurrency limit × 5

**Examples:**

* **1 concurrency** = Up to 5 WebSocket connections, but only 1 active request
* **3 concurrency** = Up to 15 WebSocket connections, but only 3 active requests simultaneously
* **5 concurrency** = Up to 25 WebSocket connections, but only 5 active requests simultaneously

While you can maintain multiple WebSocket connections, only your concurrency limit number of requests can be actively processed at once. Additional requests sent through any connection while at the concurrency limit will be rejected with an error.

For detailed information about concurrency limits, rate limiting, and best practices for handling these constraints, see our [Concurrency and Limits](concurrency-and-limits) documentation.

<Note>
  When multiple requests are sent simultaneously beyond your concurrency limit,
  additional requests will be rejected with an error. Implement proper error
  handling and request queuing to manage concurrency effectively.
</Note>


## AsyncAPI

````yaml asyncapi-spec/lightning-v3.1-ws.json /waves/v1/lightning-v3.1/get_speech/stream
id: /waves/v1/lightning-v3.1/get_speech/stream
title: /waves/v1/lightning-v3.1/get_speech/stream
description: ''
servers:
  - id: production
    protocol: wss
    host: api.smallest.ai
    bindings: []
    variables: []
address: /waves/v1/lightning-v3.1/get_speech/stream
parameters: []
bindings: []
operations:
  - &ref_1
    id: ttsRequest
    title: Tts request
    description: Send text-to-speech request
    type: receive
    messages:
      - &ref_3
        id: ttsRequest.message
        contentType: application/json
        payload:
          - name: TTSRequest
            type: object
            properties:
              - name: voice_id
                type: string
                description: The ID of the voice to use
                required: true
              - name: text
                type: string
                description: The text to convert to speech
                required: true
              - name: max_buffer_flush_ms
                type: integer
                description: >-
                  The maximum time (in ms) to wait for more input before
                  generating output. It flushes when either this time is reached
                  or enough input is received for optimal output—whichever comes
                  first. This is useful for input streams. Defaults to 0
                required: false
              - name: continue
                type: boolean
                description: >-
                  This setting controls whether the system should buffer and
                  wait for more input after receiving the current one. If not
                  set, it assumes no more input is coming.
                required: false
              - name: flush
                type: boolean
                description: >-
                  This setting controls whether the system should flush the
                  current buffer.
                required: false
              - name: complete_backoff_ms
                type: number
                description: >-
                  The time in ms to wait after the last chunk is sent before
                  sending the complete response. Default is 4000ms. Maximum is
                  10000ms.
                required: false
              - name: language
                type: string
                description: 'The language code, available options: `en`, `hi`'
                enumValues:
                  - en
                  - hi
                required: false
              - name: sample_rate
                type: integer
                description: Audio sample rate in Hz
                enumValues:
                  - 8000
                  - 16000
                  - 24000
                  - 44100
                required: false
              - name: speed
                type: number
                description: Speaking speed multiplier
                required: false
        headers: []
        jsonPayloadSchema:
          type: object
          required:
            - voice_id
            - text
          properties:
            voice_id:
              type: string
              description: The ID of the voice to use
              x-parser-schema-id: <anonymous-schema-2>
            text:
              type: string
              description: The text to convert to speech
              x-parser-schema-id: <anonymous-schema-3>
            max_buffer_flush_ms:
              type: integer
              description: >-
                The maximum time (in ms) to wait for more input before
                generating output. It flushes when either this time is reached
                or enough input is received for optimal output—whichever comes
                first. This is useful for input streams. Defaults to 0
              default: 0
              maximum: 1000
              minimum: 0
              x-parser-schema-id: <anonymous-schema-4>
            continue:
              type: boolean
              description: >-
                This setting controls whether the system should buffer and wait
                for more input after receiving the current one. If not set, it
                assumes no more input is coming.
              default: false
              x-parser-schema-id: <anonymous-schema-5>
            flush:
              type: boolean
              description: >-
                This setting controls whether the system should flush the
                current buffer.
              default: false
              x-parser-schema-id: <anonymous-schema-6>
            complete_backoff_ms:
              type: number
              description: >-
                The time in ms to wait after the last chunk is sent before
                sending the complete response. Default is 4000ms. Maximum is
                10000ms.
              default: 4000
              minimum: 0
              maximum: 10000
              x-parser-schema-id: <anonymous-schema-7>
            language:
              type: string
              description: 'The language code, available options: `en`, `hi`'
              default: en
              enum:
                - en
                - hi
              x-parser-schema-id: <anonymous-schema-8>
            sample_rate:
              type: integer
              description: Audio sample rate in Hz
              default: 44100
              enum:
                - 8000
                - 16000
                - 24000
                - 44100
              x-parser-schema-id: <anonymous-schema-9>
            speed:
              type: number
              description: Speaking speed multiplier
              minimum: 0.5
              maximum: 2
              default: 1
              x-parser-schema-id: <anonymous-schema-10>
          examples:
            - voice_id: ryan
              text: Hello, this is a sample text to convert to speech.
              max_buffer_flush_ms: 0
              continue: false
              flush: false
              language: en
              sample_rate: 24000
              speed: 1
              consistency: 0.5
              enhancement: 1
              similarity: 0
          x-parser-schema-id: <anonymous-schema-1>
        title: TTSRequest
        example: |-
          {
            "voice_id": "ryan",
            "text": "Hello, this is a sample text to convert to speech.",
            "max_buffer_flush_ms": 0,
            "continue": false,
            "flush": false,
            "language": "en",
            "sample_rate": 24000,
            "speed": 1,
            "consistency": 0.5,
            "enhancement": 1,
            "similarity": 0
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: ttsRequest.message
    bindings: []
    extensions: &ref_0
      - id: x-parser-unique-object-id
        value: /waves/v1/lightning-v3.1/get_speech/stream
  - &ref_2
    id: ttsResponse
    title: Tts response
    description: Receive audio stream chunks
    type: send
    messages:
      - &ref_4
        id: ttsResponse.message
        contentType: application/json
        payload:
          - name: TTSResponse
            type: object
            properties:
              - name: request_id
                type: string
                description: Unique identifier for the TTS request
                required: false
              - name: status
                type: string
                description: >-
                  Status of the TTS request, `chunk` indicates incoming audio
                  chunk, `complete` indicates completion.
                enumValues:
                  - chunk
                  - complete
                required: false
              - name: data
                type: object
                required: false
                properties:
                  - name: audio
                    type: string
                    description: Base64-encoded audio chunk
                    required: false
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            request_id:
              type: string
              description: Unique identifier for the TTS request
              x-parser-schema-id: <anonymous-schema-12>
            status:
              type: string
              enum:
                - chunk
                - complete
              description: >-
                Status of the TTS request, `chunk` indicates incoming audio
                chunk, `complete` indicates completion.
              x-parser-schema-id: <anonymous-schema-13>
            data:
              type: object
              properties:
                audio:
                  type: string
                  description: Base64-encoded audio chunk
                  x-parser-schema-id: <anonymous-schema-15>
              x-parser-schema-id: <anonymous-schema-14>
          x-parser-schema-id: <anonymous-schema-11>
        title: TTSResponse
        example: |-
          {
            "request_id": "<string>",
            "status": "<string>",
            "data": {
              "audio": "<string>"
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: ttsResponse.message
    bindings: []
    extensions: *ref_0
sendOperations:
  - *ref_1
receiveOperations:
  - *ref_2
sendMessages:
  - *ref_3
receiveMessages:
  - *ref_4
extensions:
  - id: x-parser-unique-object-id
    value: /waves/v1/lightning-v3.1/get_speech/stream
securitySchemes:
  - id: bearerAuth
    name: bearerAuth
    type: http
    description: Bearer token authentication
    scheme: bearer
    bearerFormat: JWT
    extensions: []

````