Skip to main content
WSS
The Text-to-Speech WebSocket API is designed to generate audio from partial text input while ensuring consistency throughout the generated audio. Although highly flexible, the WebSocket API isn’t a one-size-fits-all solution. It’s well-suited for scenarios where:
  • The input text is being streamed or generated in chunks.
  • Real-time audio generation is required with low latency.
  • You need to send text incrementally as it becomes available.
However, it may not be the best choice when:
  • The entire input text is available upfront. Given that the generations are partial, some buffering is involved, which could potentially result in slightly higher latency compared to a standard HTTP request.
  • You want to quickly experiment or prototype. Working with WebSockets can be harder and more complex than using a standard HTTP API, which might slow down rapid development and testing.

Endpoint

Connection URL

Authentication

Requires API key authentication via x-api-key query parameter or in the initial connection message.

Query Parameters

Message Types

Initialize Connection

After establishing the WebSocket connection, you must send an initialization message. Request:
Request Fields: Response:

Send Text

Send text chunks for audio generation. Request:
Request Fields: Response:
Response Fields:

Clear Buffer

Clear the current text buffer. Request:
Response: No response message.

Close Connection

Close the WebSocket connection gracefully. Request:
Response: Connection closes.

Error Responses

If an error occurs, you’ll receive:
Error Response Fields:

Example Usage

Best Practices

  1. Always initialize: Send initConnection immediately after opening the connection
  2. Handle errors: Check for error messages in responses
  3. Flush when done: Use flush: true when sending the last text chunk to ensure all audio is generated
  4. Close gracefully: Send closeConnection before closing the WebSocket
  5. Buffer audio: Collect audio chunks and play them sequentially for smooth playback
query
type:object
x-api-key
type:string
required

Your Munsit API key

Audio Response
type:object

Audio chunk response

Connection Initialized
type:object

Response confirming connection initialization

Error
type:object

Error response

Initialize Connection
type:object

Initialize the WebSocket connection

Send Text
type:object

Send text for audio generation