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

# Upgrade to WebSocket for real-time streaming

> Upgrades the HTTP connection to a WebSocket for real-time audio streaming.

## Usage

1. Create a transcription session with `stream=true`
2. Connect to this WebSocket endpoint
3. Send audio chunks as JSON messages
4. Receive transcription results in real-time

## Client → Server (Audio Chunks)
```json
{
  "message_type": "transcriptions_session_audio",
  "message_source": "audio_analytics_api",
  "session_id": "session123",
  "type": "input_audio",
  "data": "<BASE64_ENCODED_AUDIO>"
}
```

## Server → Client (Event Sequence per Utterance)

**1. Speech detected:**
```json
{ "session_id": "session123", "type": "transcript.event", "state": "speech_start" }
```

**2. Partial transcription (zero or more):**
```json
{ "session_id": "session123", "text": "Partial transcription text", "language": "en", "type": "transcript.text.delta", "state": "transcription" }
```

**3. End of speech detected:**
```json
{ "session_id": "session123", "type": "transcript.event", "state": "speech_end" }
```

**4. Final transcription:**
```json
{ "session_id": "session123", "text": "Complete transcription text.", "language": "en", "type": "transcript.text.done", "state": "transcription" }
```

After step 4 the engine resets and listens for the next utterance.
The session stays open until the client calls `/transcriptions/close`.

## Connection
- Protocol: WebSocket (ws:// or wss://)
- URL: `ws://<host>:8085/stream`
- Requires prior session creation via `/transcriptions/create`




## OpenAPI

````yaml /Ubuntu/ai-workflows/api-specs/audio-analytics/openapi.yaml get /stream
openapi: 3.0.3
info:
  title: Audio Analytics API
  version: 1.0.0
  description: >
    REST API providing AI-powered audio processing: speech recognition (ASR),

    text translation (T2T), and speech synthesis (TTS).


    ## Services


    | Service | Endpoint prefix | Description |

    |---------|----------------|-------------|

    | ASR | `/transcriptions/` | Whisper-based speech-to-text (file or live
    WebSocket streaming) |

    | T2T | `/translations/` | Opus/NLLB text translation (batch supported) |

    | TTS | `/tts/` | MeloTTS speech synthesis; returns raw PCM audio |


    ## Audio formats (ASR input)

    - WAV, 16-bit PCM; 16 kHz mono recommended; max 25 MB


    ## TTS output

    - Supported sample rates: 44100, 22050, 16000 Hz (auto-resampled)


    ## WebSocket streaming sequence


    ```

    App                                           Server
     |===POST /transcriptions/create================>|
     |<==200 {session_id, state: asr_initialized}====|
     |
     |===WS /stream=================================>|
     |<==  {state: connection_established}===========|
     |
     |===WS {transcriptions_session_audio} (loop)===>|
     |<===WS {transcript.event,     speech_start}====|
     |<===WS {transcript.text.delta, ...}============|  (zero or more)
     |<===WS {transcript.event,     speech_end}======|
     |<===WS {transcript.text.done,  ...}============|
     |
     |===POST /transcriptions/close=================>|  (after transcript.text.done)
    ```


    ## Authentication

    None required.
  contact:
    name: Qualcomm Support Forums
    url: https://mysupport.qualcomm.com/supportforums/s/
  license:
    name: BSD-3-Clause-Clear
    url: https://opensource.org/licenses/BSD-3-Clause-Clear
servers:
  - url: http://{device-ip}:{device-port}/audio-analytics/v1/api
    description: Audio Analytics API Server
    variables:
      device-ip:
        description: IP address and port of the host device running the Audio Analytics API
        default: localhost
      device-port:
        default: '8085'
security: []
tags:
  - name: Health
    description: Service health and status endpoints
  - name: Transcriptions
    description: Speech-to-text audio transcription (ASR)
  - name: Translations
    description: Text-to-text translation between languages
  - name: TTS
    description: Text-to-speech synthesis
  - name: WebSocket
    description: Real-time streaming communication
paths:
  /stream:
    get:
      tags:
        - WebSocket
      summary: Upgrade to WebSocket for real-time streaming
      description: >
        Upgrades the HTTP connection to a WebSocket for real-time audio
        streaming.


        ## Usage


        1. Create a transcription session with `stream=true`

        2. Connect to this WebSocket endpoint

        3. Send audio chunks as JSON messages

        4. Receive transcription results in real-time


        ## Client → Server (Audio Chunks)

        ```json

        {
          "message_type": "transcriptions_session_audio",
          "message_source": "audio_analytics_api",
          "session_id": "session123",
          "type": "input_audio",
          "data": "<BASE64_ENCODED_AUDIO>"
        }

        ```


        ## Server → Client (Event Sequence per Utterance)


        **1. Speech detected:**

        ```json

        { "session_id": "session123", "type": "transcript.event", "state":
        "speech_start" }

        ```


        **2. Partial transcription (zero or more):**

        ```json

        { "session_id": "session123", "text": "Partial transcription text",
        "language": "en", "type": "transcript.text.delta", "state":
        "transcription" }

        ```


        **3. End of speech detected:**

        ```json

        { "session_id": "session123", "type": "transcript.event", "state":
        "speech_end" }

        ```


        **4. Final transcription:**

        ```json

        { "session_id": "session123", "text": "Complete transcription text.",
        "language": "en", "type": "transcript.text.done", "state":
        "transcription" }

        ```


        After step 4 the engine resets and listens for the next utterance.

        The session stays open until the client calls `/transcriptions/close`.


        ## Connection

        - Protocol: WebSocket (ws:// or wss://)

        - URL: `ws://<host>:8085/stream`

        - Requires prior session creation via `/transcriptions/create`
      operationId: streamAudioWebSocket
      responses:
        '101':
          description: Switching Protocols - WebSocket connection established
        '400':
          description: Bad request - invalid WebSocket upgrade
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Session not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    ErrorResponse:
      type: object
      description: Standard error response structure
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              description: Human-readable error message
              example: Invalid request, missing 'file' parameter
            type:
              type: string
              description: Error type or category
              example: invalid_request_error
            param:
              type: string
              nullable: true
              description: Parameter related to the error (if applicable)
              example: file
            code:
              type: string
              nullable: true
              description: Error code (if applicable)
              example: null
          required:
            - message
            - type
      required:
        - error

````