> ## 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.

# JavaScript SDK

> Install voiceai-sdk on npm and call text-to-speech, speech-to-text, and streaming endpoints from Node, Bun, or Deno.

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

## Install

<CodeGroup>
  ```bash npm theme={null}
  npm install voiceai-sdk
  ```

  ```bash pnpm theme={null}
  pnpm add voiceai-sdk
  ```

  ```bash yarn theme={null}
  yarn add voiceai-sdk
  ```

  ```bash bun theme={null}
  bun add voiceai-sdk
  ```
</CodeGroup>

## Initialize the client

Get an SLNG key from [app.slng.ai](https://app.slng.ai/api-keys), then construct the client:

```ts theme={null}
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

```ts theme={null}
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

```ts theme={null}
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:

```ts theme={null}
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](/websockets) for the full message schema.

## Discover models

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

## Links

* npm: [npmjs.com/package/voiceai-sdk](https://www.npmjs.com/package/voiceai-sdk)
* Source: [github.com/slng-ai/sdks](https://github.com/slng-ai/sdks)
