Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.slng.ai/llms.txt

Use this file to discover all available pages before exploring further.

voiceai-sdk is the official TypeScript client for the SLNG API. It works in any runtime that supports Node 18+ (Node, Bun, Deno).

Install

npm install voiceai-sdk

Initialize the client

Get a key from app.slng.ai, then construct the client:
import Slng from "voiceai-sdk";

const client = new Slng({
  apiKey: process.env.SLNG_API_KEY,
});
The apiKey option defaults to process.env.SLNG_API_KEY. Pass an explicit string to override.

Text-to-speech

import { writeFile } from "node:fs/promises";
import Slng from "voiceai-sdk";

const client = new Slng({ apiKey: process.env.SLNG_API_KEY });

const audio = await client.textToSpeech.create("slng/deepgram/aura:2-en", {
  text: "Hello from the SLNG SDK.",
  voice: "aura-2-thalia-en",
});

await writeFile("hello.wav", Buffer.from(await audio.arrayBuffer()));

Speech-to-text

import { createReadStream } from "node:fs";
import Slng from "voiceai-sdk";

const client = new Slng({ apiKey: process.env.SLNG_API_KEY });

const transcript = await client.speechToText.create("slng/deepgram/nova:3-en", {
  audio: createReadStream("meeting.wav"),
});

console.log(transcript.text);

Streaming over WebSocket

For long passages of text-to-speech or live transcription, use the streaming client:
import { StreamingClient } from "voiceai-sdk/streaming";

const streaming = new StreamingClient({ apiKey: process.env.SLNG_API_KEY });
const session = await streaming.connectStt("slng/deepgram/nova:3-en");

session.send({
  type: "init",
  config: { language: "en", sample_rate: 16000, encoding: "linear16" },
});

for await (const msg of session) {
  if (msg.type === "final_transcript") console.log(msg.text);
}
See WebSockets for the full message schema.

Discover models

const models = await client.models.list();
const voices = await client.voices.list({ model: "slng/deepgram/aura:2-en" });