Skip to main content

Overview

The Hamsa Real-Time WebSocket API enables bidirectional streaming communication for Text-to-Speech (TTS) and Speech-to-Text (STT) operations. A single persistent connection can handle multiple requests without reconnecting.

Connection

Endpoint

Authentication

Authenticate using your API key via query parameter or header:

Connection Response

Upon successful connection, the server sends:
Connections are automatically closed after 60 minutes of inactivity. The server sends ping frames every 30 seconds to keep connections alive.

Message Format

All messages follow this structure:

Text-to-Speech (TTS)

Convert text to speech with streaming audio output.

Request

type
string
required
Must be "tts"
payload
object
required

Example Request

Response Flow

1

Acknowledgment

Server confirms the request was received:
2

Audio Stream

Server streams raw audio data as binary chunks. Buffer these chunks to reconstruct the complete audio file.
3

Stream End

Server signals completion:

Code Example

Dialects and Voice Examples

Pick a speaker that matches your chosen dialect. Voice examples per dialect:

Speech-to-Text (STT)

Transcribe audio to text.

Request

type
string
required
Must be "stt"
payload
object
required

Example Request

Response

The server sends the transcribed text directly as a plain string (not JSON):

Code Example


Error Handling

Error Response Format

WebSocket Close Codes

Common Errors


Rate Limiting

  • Limit: 100 requests per 60 seconds per API key
  • Exceeding the limit returns: Rate limit exceeded for this API key