Refer to Hamsa Platforms to get the list of the available pre-built speakers where you can take the name of the speaker, or use a UUID for your custom cloned voice.
When using a custom cloned voice (UUID) as the speaker, you must preload the voice before establishing the WebSocket connection. This ensures optimal latency during streaming.
Preload Required for Custom VoicesCall the Preload Voice endpoint once when your application starts to avoid latency when using custom cloned voices.
Copy
Ask AI
// 1. Preload the custom voice at app startupawait fetch('https://api.tryhamsa.com/v2/tts/voices/custom/preload', { method: 'POST', headers: { 'Authorization': 'Token YOUR_API_KEY', 'Content-Type': 'application/json' }, body: JSON.stringify({ voiceId: 'your-custom-voice-uuid' })});// 2. Now connect to WebSocket and use the custom voiceconst ws = new WebSocket('wss://api.tryhamsa.com/v1/realtime/ws?api_key=YOUR_API_KEY');ws.onopen = () => { ws.send(JSON.stringify({ type: 'tts', payload: { text: 'Hello from my custom voice', speaker: 'your-custom-voice-uuid', // Use the same UUID dialect: 'modern', languageId: 'ar', mulaw: false } }));};