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:Message Format
All messages follow this structure:Text-to-Speech (TTS)
Convert text to speech with streaming audio output.Request
Must be
"tts"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 aspeaker that matches your chosen dialect. Voice examples per dialect:
Speech-to-Text (STT)
Transcribe audio to text.Request
Must be
"stt"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