Step 1: Get an API key
Sign up at app.lokutor.com and create an API key from the dashboard.export LOKUTOR_API_KEY=sk_your_key_here
Step 2: Install
# JavaScript / TypeScript
npm install @lokutor/sdk
# Python
pip install lokutor
Step 3: Synthesize audio
- Node.js (save to file)
- Browser
- Python
- Raw WebSocket
import { TTSClient, VoiceStyle } from '@lokutor/sdk';
import fs from 'fs';
const client = new TTSClient({ apiKey: process.env.LOKUTOR_API_KEY! });
const chunks: Buffer[] = [];
await client.synthesize({
text: 'Hello from Lokutor.',
voice: VoiceStyle.F1,
onAudio: (data) => chunks.push(Buffer.from(data)),
});
fs.writeFileSync('output.raw', Buffer.concat(chunks));
console.log('Saved output.raw');
// Convert: ffmpeg -f s16le -ar 44100 -ac 1 -i output.raw output.wav
import { TTSClient, VoiceStyle } from '@lokutor/sdk';
const audioCtx = new AudioContext();
let nextTime = audioCtx.currentTime;
const client = new TTSClient({
apiKey: import.meta.env.VITE_LOKUTOR_API_KEY,
});
await client.synthesize({
text: 'Hello from Lokutor.',
voice: VoiceStyle.F1,
onAudio: (pcm16) => {
const int16 = new Int16Array(pcm16.buffer, pcm16.byteOffset, pcm16.length / 2);
const float32 = new Float32Array(int16.length);
for (let i = 0; i < int16.length; i++) float32[i] = int16[i] / 32768;
const buffer = audioCtx.createBuffer(1, float32.length, 44100);
buffer.getChannelData(0).set(float32);
const source = audioCtx.createBufferSource();
source.buffer = buffer;
source.connect(audioCtx.destination);
source.start(nextTime);
nextTime += buffer.duration;
},
});
console.log('Playback complete');
from lokutor import TTSClient, VoiceStyle
import os
client = TTSClient(api_key=os.environ['LOKUTOR_API_KEY'])
client.synthesize(
text='Hello from Lokutor.',
voice=VoiceStyle.F1,
play=True,
block=True,
)
const ws = new WebSocket(
`wss://api.lokutor.com/ws/tts?api_key=${process.env.LOKUTOR_API_KEY}`
);
const chunks = [];
ws.onopen = () => {
ws.send(JSON.stringify({ text: 'Hello from Lokutor.', voice: 'F1' }));
};
ws.onmessage = (event) => {
if (event.data instanceof ArrayBuffer) {
chunks.push(Buffer.from(event.data));
} else if (event.data === 'EOS') {
require('fs').writeFileSync('output.raw', Buffer.concat(chunks));
ws.close();
}
};
Next steps
- Build a voice agent — My First Agent
- Explore the SDK — SDK Overview
- Browse the API — REST and Streaming