🛸 Lokutor JavaScript SDK
The Lokutor JavaScript SDK is a modern, TypeScript-first library designed for high-performance audio applications in both the Browser and Node.js.Installation
Initialization
🎙️ Text-to-Speech (TTS) Module
Thetts module handles all speech synthesis tasks.
1. Simple Synthesis (Batch)
Perfect for short texts where you need the full audio at once.text(required): Text to synthesize (1-50,000 characters)voice(required): Voice ID -M1,M2,F1,F2quality:ultra_fast,fast,medium,high,ultra_high(default:medium)speed: Speech speed multiplier, 0.5-2.0 (default: 1.05)outputFormat:pcm_22050,mp3_22050,ulaw_8000(default:pcm_22050)includeVisemes: Include viseme timing data (default:false)language:enores(default:en)
2. Real-Time Streaming
Use this for the lowest possible latency. RequiresvoiceId as a parameter.
POST /api/tts/{voice_id}/stream
3. Async Long-Form Jobs
For texts longer than 5,000 characters, use the async jobs API.POST /api/tts/{voice_id}/async
🗣️ Voice Chat Module (Flagship)
ThevoiceChat module is a high-level wrapper around Lokutor’s bidirectional WebSocket protocol. It manages the conversation state engine and audio processing.
Creating a Session
Event Handlers
| Event | Description | Data |
|---|---|---|
connected | Fired when WS connection is established. | void |
agentSpeaking | Agent started sending audio chunks. | boolean |
viseme | Real-time viseme for LipSync. | { id: number, offset_ms: number } |
interrupted | Fired when the agent stops due to user speech. | void |
textDelta | Partial transcript of user speech (real-time). | { text: string } |
configured | Configuration confirmation from server. | { voice_id, quality, sample_rate, include_visemes, language } |
error | Any session or network error. | { message: string } |
disconnected | Connection closed. | void |
Starting a Conversation (Browser)
WebSocket Message Format
The WebSocket connection uses JSON messages with the following structure: Client → Server:Authentication
WebSocket connections support multiple authentication methods:🛠️ Audio Utilities
The SDK exports internal utilities used by the modules, which you can use for custom implementations.LokutorPlayer (Browser Only)
A PCM/MP3 player optimized for streaming with a built-in Jitter Buffer.
LokutorRecorder (Browser Only)
A microphone recorder that handles everything for you.
🎭 Voices & Models
Retrieve available assets for your application.M1- Male voice 1M2- Male voice 2F1- Female voice 1F2- Female voice 2
en- Englishes- Spanish
Advanced: Latency & Jitter
The JS SDK implements Precise Scheduling. When a chunk arrives, it is scheduled in the Web Audio API timeline atcurrentTime + jitterBuffer. This prevents gaps in audio caused by transient network jitter.