asyncapi: 3.0.0
info:
  title: SLNG Gateway API - Soniox TTS
  version: 0.1.0
  description: Real-time text-to-speech with streaming WebSocket and one-shot HTTP synthesis
  contact:
    name: SLNG Support
    url: https://slng.ai
    email: support@slng.ai
  license:
    name: Proprietary
  tags: []
servers:
  production:
    host: api.slng.ai
    protocol: wss
    description: Production
    security:
      - $ref: "#/components/securitySchemes/bearer"
  staging:
    host: stageapi.slng.ai
    protocol: wss
    description: Staging
    security:
      - $ref: "#/components/securitySchemes/bearer"
channels:
  /v1/tts/soniox/tts-rt:v1:
    address: /v1/tts/soniox/tts-rt:v1
    title: Soniox TTS v1
    summary: Real-time text-to-speech with streaming WebSocket and one-shot HTTP synthesis
    description: Stream real-time speech synthesis from Soniox TTS v1 over WebSocket with low-latency incremental audio output and SLNG's unified TTS protocol.
    tags:
      - name: Soniox TTS v1
    servers:
      - $ref: "#/servers/production"
      - $ref: "#/servers/staging"
    messages:
      SonioxTtsRtV1Config:
        $ref: "#/components/messages/SonioxTtsRtV1Config"
      SonioxTtsRtV1TextStreaming:
        $ref: "#/components/messages/SonioxTtsRtV1TextStreaming"
      SonioxTtsRtV1Cancel:
        $ref: "#/components/messages/SonioxTtsRtV1Cancel"
      SonioxTtsRtV1AudioChunk:
        $ref: "#/components/messages/SonioxTtsRtV1AudioChunk"
      SonioxTtsRtV1Terminated:
        $ref: "#/components/messages/SonioxTtsRtV1Terminated"
      SonioxTtsRtV1Error:
        $ref: "#/components/messages/SonioxTtsRtV1Error"
    bindings:
      ws:
        method: GET
        headers:
          $ref: "#/components/schemas/WebsocketHeadersSoniox"
operations:
  ttsSonioxTtsRtV1ReceiveConfig:
    action: receive
    channel:
      $ref: "#/channels/~1v1~1tts~1soniox~1tts-rt:v1"
    summary: Initialize a TTS stream
    description: Send a Connection Config Message to initialize a TTS stream. Sent once per stream_id before any text frames.
    messages:
      - $ref: "#/channels/~1v1~1tts~1soniox~1tts-rt:v1/messages/SonioxTtsRtV1Config"
    tags: []
  ttsSonioxTtsRtV1ReceiveTextStreaming:
    action: receive
    channel:
      $ref: "#/channels/~1v1~1tts~1soniox~1tts-rt:v1"
    summary: Stream text to synthesize
    description: Send a Text Streaming Message to feed text incrementally to the active stream. Set text_end true on the final chunk.
    messages:
      - $ref: "#/channels/~1v1~1tts~1soniox~1tts-rt:v1/messages/SonioxTtsRtV1TextStreaming"
    tags: []
  ttsSonioxTtsRtV1ReceiveCancel:
    action: receive
    channel:
      $ref: "#/channels/~1v1~1tts~1soniox~1tts-rt:v1"
    summary: Cancel an in-flight stream
    description: Send a Cancel Message. Server stops audio and terminates the stream.
    messages:
      - $ref: "#/channels/~1v1~1tts~1soniox~1tts-rt:v1/messages/SonioxTtsRtV1Cancel"
    tags: []
  ttsSonioxTtsRtV1SendAudioChunk:
    action: send
    channel:
      $ref: "#/channels/~1v1~1tts~1soniox~1tts-rt:v1"
    summary: Receive synthesized audio chunks
    description: Receive an Audio Response. Server streams audio chunks; audio_end&#58; true marks the final audio payload (stream not yet terminated).
    messages:
      - $ref: "#/channels/~1v1~1tts~1soniox~1tts-rt:v1/messages/SonioxTtsRtV1AudioChunk"
    tags: []
  ttsSonioxTtsRtV1SendTerminated:
    action: send
    channel:
      $ref: "#/channels/~1v1~1tts~1soniox~1tts-rt:v1"
    summary: Receive stream termination event
    description: Receive a Terminal Stream Event. Server has fully closed the stream and released resources. stream_id may now be reused.
    messages:
      - $ref: "#/channels/~1v1~1tts~1soniox~1tts-rt:v1/messages/SonioxTtsRtV1Terminated"
    tags: []
  ttsSonioxTtsRtV1SendError:
    action: send
    channel:
      $ref: "#/channels/~1v1~1tts~1soniox~1tts-rt:v1"
    summary: Receive stream error
    description: Receive an Error Response. After an error the stream is typically terminated (a Terminal Stream Event will follow).
    messages:
      - $ref: "#/channels/~1v1~1tts~1soniox~1tts-rt:v1/messages/SonioxTtsRtV1Error"
    tags: []
components:
  securitySchemes:
    bearer:
      type: http
      scheme: bearer
  schemas:
    WebsocketHeadersSoniox:
      type: object
      properties:
        X-World-Part-Override:
          type: string
          description: Override target world part. Auto-selected if not provided.
          enum:
            - na
  messages:
    SonioxTtsRtV1Config:
      name: SonioxTtsRtV1Config
      title: Connection Config Message
      summary: Initialize a TTS stream. Sent once per stream_id before any text frames.
      contentType: application/json
      payload:
        type: object
        description: Initialize a TTS stream. Sent once per stream_id before any text frames.
        required:
          - type
          - stream_id
          - model
          - language
          - voice
          - audio_format
        properties:
          type:
            type: string
            const: init
            description: Message type discriminator. Always `init` for the connection config message.
          api_key:
            type: string
            description: Soniox API key or temporary API key. Created in Soniox Console. Optional on gateway routes — when provided it is ignored; upstream auth is injected by the gateway.
          stream_id:
            type: string
            description: Client-generated unique stream identifier. Must be unique among active streams on the same connection. Can be reused only after the previous stream is terminated.
          model:
            type: string
            default: tts-rt-v1
            description: TTS model to use. Example, `tts-rt-v1`.
          language:
            type: string
            default: en
            description: ISO 639-1 language code. Example, `en`.
            enum:
              - af
              - sq
              - ar
              - az
              - eu
              - be
              - bn
              - bs
              - bg
              - ca
              - zh
              - hr
              - cs
              - da
              - nl
              - en
              - et
              - fi
              - fr
              - gl
              - de
              - el
              - gu
              - he
              - hi
              - hu
              - id
              - it
              - ja
              - kn
              - kk
              - ko
              - lv
              - lt
              - mk
              - ms
              - ml
              - mr
              - no
              - fa
              - pl
              - pt
              - pa
              - ro
              - ru
              - sr
              - sk
              - sl
              - es
              - sw
              - sv
              - tl
              - ta
              - te
              - th
              - tr
              - uk
              - ur
              - vi
              - cy
          voice:
            type: string
            description: Voice name. Example, `Adrian`.
          audio_format:
            type: string
            enum:
              - wav
              - mp3
              - pcm_s16le
              - pcm_s16be
            description: Output audio format. Example, `wav`.
          sample_rate:
            type: integer
            description: Output sample rate in Hz. Example, `24000`.
          bitrate:
            type: integer
            description: Codec bitrate in bps. Only applicable to lossy compressed formats. Example, `128000`.
      examples:
        - name: configExample
          summary: Initialize a stream with default English voice
          payload:
            type: init
            stream_id: stream-1
            model: tts-rt-v1
            language: en
            voice: Adrian
            audio_format: wav
            sample_rate: 24000
    SonioxTtsRtV1TextStreaming:
      name: SonioxTtsRtV1TextStreaming
      title: Text Streaming Message
      summary: Stream text incrementally to the active stream. Set text_end true on the final chunk.
      contentType: application/json
      payload:
        type: object
        description: Stream text incrementally to the active stream. Set text_end true on the final chunk.
        required:
          - type
          - stream_id
          - text
          - text_end
        properties:
          type:
            type: string
            const: text
            description: Message type discriminator. Always `text` for streaming text chunks.
          stream_id:
            type: string
            description: Must match the stream_id used in the connection config message.
          text:
            type: string
            description: Text chunk to synthesize. Send incrementally as text is generated.
          text_end:
            type: boolean
            description: Set to true on the final text chunk to signal end of input. False for intermediate chunks.
      examples:
        - name: textStreamingChunk
          summary: Send an intermediate text chunk
          payload:
            type: text
            stream_id: stream-1
            text: Hello from Soniox text-to-speech.
            text_end: false
        - name: textStreamingFinal
          summary: Send the final text chunk and close input
          payload:
            type: text
            stream_id: stream-1
            text: Goodbye.
            text_end: true
    SonioxTtsRtV1Cancel:
      name: SonioxTtsRtV1Cancel
      title: Cancel Message
      summary: Cancel an in-flight stream. Server stops audio and terminates the stream.
      contentType: application/json
      payload:
        type: object
        description: Cancel an in-flight stream. Server stops audio and terminates the stream.
        required:
          - type
          - stream_id
          - cancel
        properties:
          type:
            type: string
            const: clear
            description: Message type discriminator. Always `clear` for the cancel message.
          stream_id:
            type: string
            description: Stream to cancel.
          cancel:
            const: true
            description: Must be `true` to trigger cancellation. Server will not send further audio and will terminate the stream.
      examples:
        - name: cancelExample
          summary: Cancel an active stream
          payload:
            type: clear
            stream_id: stream-1
            cancel: true
    SonioxTtsRtV1AudioChunk:
      name: SonioxTtsRtV1AudioChunk
      title: Audio Response
      summary: Audio bytes for the stream chunk. audio_end true marks the final audio payload (stream not yet terminated).
      contentType: application/json
      payload:
        type: object
        description: Audio bytes for the stream chunk. audio_end true marks the final audio payload (stream not yet terminated).
        required:
          - type
          - audio
          - audio_end
          - stream_id
        properties:
          type:
            type: string
            const: audio_chunk
            description: Message type discriminator. Always `audio_chunk` for audio response messages.
          audio:
            type: string
            format: base64
            description: Base64-encoded audio bytes for the stream chunk.
          audio_end:
            type: boolean
            description: True on the final audio chunk. No further audio payloads will follow, but the stream is not fully closed until a Terminal Stream Event arrives with terminated&#58; true.
          stream_id:
            type: string
            description: Identifies which stream this audio belongs to.
      examples:
        - name: audioChunkInterim
          summary: An intermediate audio chunk
          payload:
            type: audio_chunk
            audio: UklGRiQAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQAAAAA=
            audio_end: false
            stream_id: stream-1
        - name: audioChunkFinal
          summary: The final audio chunk for the stream
          payload:
            type: audio_chunk
            audio: UklGRiQAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQAAAAA=
            audio_end: true
            stream_id: stream-1
    SonioxTtsRtV1Terminated:
      name: SonioxTtsRtV1Terminated
      title: Terminal Stream Event
      summary: Server has fully closed the stream and released resources. stream_id may now be reused.
      contentType: application/json
      payload:
        type: object
        description: Server has fully closed the stream and released resources. stream_id may now be reused.
        required:
          - type
          - terminated
          - stream_id
        properties:
          type:
            type: string
            const: terminated
            description: Message type discriminator. Always `terminated` for the terminal stream event.
          terminated:
            const: true
            description: True signals the server has fully closed the stream and released resources. Safe to reuse stream_id only after this event.
          stream_id:
            type: string
            description: Stream this termination event applies to.
      examples:
        - name: terminatedExample
          summary: Stream fully terminated
          payload:
            type: terminated
            terminated: true
            stream_id: stream-1
    SonioxTtsRtV1Error:
      name: SonioxTtsRtV1Error
      title: Error Response
      summary: An error encountered on the stream. After an error the stream is typically terminated.
      contentType: application/json
      payload:
        type: object
        description: An error encountered on the stream. After an error the stream is typically terminated.
        required:
          - type
          - error_code
          - error_message
          - stream_id
        properties:
          type:
            type: string
            const: error
            description: Message type discriminator. Always `error` for error responses.
          error_code:
            type: integer
            description: "HTTP-style error code. Common values: 400, 401, 402, 408, 429, 500, 503."
          error_message:
            type: string
            description: 'Human-readable error description. Example: "Missing required field: model".'
          stream_id:
            type: string
            description: Stream that encountered the error.
      examples:
        - name: errorExample
          summary: Missing required field error
          payload:
            type: error
            error_code: 400
            error_message: "Missing required field: model"
            stream_id: stream-1
