Soniox
SDKs

Node SDK

Build speech-to-text workflows in Node with async and real-time APIs.

The Soniox Node SDK gives you fully typed access to our Async and Real-time Speech-to-Text APIs.

Quickstart

Install

Install via your preferred package manager:

npm install @soniox/node
yarn add @soniox/node
pnpm add @soniox/node
bun add @soniox/node

Set your API key

Terminal
export SONIOX_API_KEY=<YOUR_API_KEY>

Get API key

Create a Soniox account and log in to the Console to get your API key.

See all available environment variables in the SDK reference.

Create your first real-time session

import { SonioxNodeClient } from "@soniox/node";

const stream = await createFakeAudioStream();

// Create a Soniox client
// The API key is read from the SONIOX_API_KEY environment variable.
const client = new SonioxNodeClient();

// Create a real-time session
const session = client.realtime.stt({
    model: "stt-rt-v4",
});

// Listen for transcription results
session.on("result", (result) => {
    const text = result.tokens.map((t) => t.text).join("");
    if (text) console.log(text);
});

// Listen for errors
session.on("error", (err) => console.error("Error:", err));

// Connect to Soniox and stream audio
await session.connect();

// Stream audio in chunks
session.sendStream(stream,
    {
        pace_ms: 60, // Send audio in chunks of 60ms to simulate real-time transcription
        finish: true // Gracefully end the session after the stream is finished
    }
);


// Fake streaming: read audio.mp3 in chunks and send in 60ms interval to simulate real-time transcription. 
// In real use case, you would stream audio from a microphone or other stream source.
async function createFakeAudioStream() {
    const res = await fetch("https://soniox.com/media/examples/coffee_shop.mp3");
    if (!res.ok) throw new Error(`Request failed: ${res.status} ${res.statusText}`);
    if (!res.body) throw new Error("No response body");
    
    return res.body;
}

Learn more about Real-time transcription.

Create your first async transcription

import { SonioxNodeClient } from '@soniox/node';
import { readFile } from 'node:fs/promises';
const audio = await readFile('audio.mp3');

const client = new SonioxNodeClient();
const transcription = await client.stt.transcribe({
    model: 'stt-async-v4',
    file: audio,
    filename: 'audio.mp3',
    wait: true,
});

console.log(transcription.transcript?.text);

Learn more about Async transcription.

Next steps