voiceai-sdk
v0.2.0
Published
The official TypeScript library for the Slng API
Readme
VoiceAI SDK for TypeScript
The official TypeScript SDK for SLNG Voice AI. Use one client for text-to-speech, speech-to-text, and model discovery across SLNG-hosted and provider-backed speech models.
Install
npm install voiceai-sdkNode 18 or newer is required.
API Key
Create an API key in the SLNG dashboard, then set it in your environment:
export SLNG_API_KEY="zpka_..."import Slng from 'voiceai-sdk';
const client = new Slng();You can also pass apiKey directly:
const client = new Slng({ apiKey: process.env.SLNG_API_KEY });Text To Speech
Generate audio from text and save it locally:
import { writeFile } from 'node:fs/promises';
import Slng from 'voiceai-sdk';
const client = new Slng();
const response = await client.textToSpeech.create('slng/deepgram/aura:2-en', {
text: 'Hello from SLNG.',
voice: 'aura-2-thalia-en',
});
await writeFile('hello.wav', Buffer.from(await response.arrayBuffer()));Use region or 'world-part' when you need explicit routing:
await client.textToSpeech.create('slng/deepgram/aura:2-en', {
text: 'Hello from Europe.',
voice: 'aura-2-thalia-en',
region: 'eu-north-1',
});Speech To Text
Transcribe a local audio file:
import fs from 'node:fs';
import Slng from 'voiceai-sdk';
const client = new Slng();
const transcript = await client.speechToText.create('slng/deepgram/nova:3-en', {
audio: fs.createReadStream('meeting.wav'),
});
console.log(transcript.text);File uploads accept File, Response, fs.ReadStream, or the SDK toFile helper.
Discover Models
The SDK ships with a static catalog snapshot, so agents and scripts can choose valid models without credentials or network calls.
import { getModel, listModels } from 'voiceai-sdk';
const ttsModels = listModels({ service: 'tts', language: 'en' });
const sttModels = listModels({ service: 'stt' });
const aura = getModel('slng/deepgram/aura:2-en');
console.log(ttsModels.map((model) => model.id));
console.log(aura?.deployments);Model IDs from the catalog can be passed directly to client.textToSpeech.create() or client.speechToText.create().
Discover Voices
Use listVoices() to find voice IDs for a TTS model:
import { listVoices } from 'voiceai-sdk';
const voices = listVoices({
model: 'slng/deepgram/aura:2-en',
language: 'en',
});
console.log(voices.map((voice) => `${voice.name}: ${voice.voiceId}`));listVoices() returns an empty array when a model does not have a cataloged voice list.
Useful voice references:
- Voices in the SLNG docs
- Deepgram Aura voices
- Cartesia Sonic 3 voices
- Kugel voices
- Murf Falcon voices
- Orpheus voices
- Rime Arcana voices
- Sarvam Bulbul voices
- Soniox TTS voices
- Full voice catalogs and samples are available in the SLNG dashboard.
Streaming
For low-latency WebSocket sessions, use the streaming client:
import { streaming } from 'voiceai-sdk';
const client = new streaming.StreamingClient({
apiKey: process.env.SLNG_API_KEY!,
});
const session = await client.connectTts('slng/deepgram/aura:2-en');
session.send({
type: 'init',
model: 'slng/deepgram/aura:2-en',
voice: 'aura-2-thalia-en',
});
session.send({ type: 'text', text: 'Streaming text to speech.' });
session.send({ type: 'flush' });
for await (const message of session) {
console.log(message);
}Reference
- Full API surface: api.md
- General docs: docs.slng.ai
- Models by language: docs.slng.ai/models/by-language
- Source: github.com/slng-ai/voiceai-sdk
