Quick Start

This guide shows how to start a single-direction Voice Translation session using the Krisp Voice Translation SDK. In this example, spoken English audio is translated into Spanish in real time.

Each translation session processes audio in one direction (source → target). For bi-directional translation, create two independent sessions, one per direction.

High-Level Flow

All platform integrations follow the same basic flow:

  • Initialize the Voice Translation SDK
  • Create a translation session with source and target languages
  • Provide audio input to the session
  • Receive translated audio (and optional transcripts)
  • Stop and clean up the session

Installation

npm i @krisp.ai/krisp-vt-sdk

package.json:

{
  "dependencies": {
    "@krisp.ai/krisp-vt-sdk": "^1.1.1"
  }
}

The package ships ESM with TypeScript declarations and zero runtime dependencies. The SDK runs in the browser and needs a secure context (HTTPS or localhost) for microphone access.

Code Snippet (English → Spanish Translation)

import {
    KrispVTSDK,
    LogLevel
} from '@krisp.ai/krisp-vt-sdk';

// 1. Initialize SDK with your Krisp API key
const sdk = new KrispVTSDK({
    apiKey: 'YOUR_KRISP_API_KEY',
    logLevel: LogLevel.WARN, // NONE, ERROR, WARN, INFO, or DEBUG
});

// 2. Set up event hooks
sdk.setHooks({
    onProcessedAudio: (stream) => {
        // Play or send the translated audio
        const audio = new Audio();
        audio.srcObject = stream;
        audio.play();
    },
    onTranscript: (event) => {
        // Recognized speech in the source language
        console.log('Original:', event.text, event.final ? '(final)' : '(interim)');
    },
    onTranslate: (event) => {
        // Translated text in the target language
        console.log('Translated:', event.text);
    },
    onError: (error) => {
        console.error('SDK error:', error.code, error.message);
    },
});

// 3. Start translation service
await sdk.start({
    from: 'en-US', // Source language (BCP 47)
    to: 'es-ES', // Target language (BCP 47)
    voice: 'female', // 'male' or 'female' (default: 'male')
    transcript: { // Optional — omit to enable all three
        interim: true, // Partial results while the speaker talks
        final: true, // Completed utterances
        translate: true, // Translated text
    },
});

// 4. Get microphone and process audio
const mic = await navigator.mediaDevices.getUserMedia({
    audio: true
});
await sdk.process(mic);

// 5. Stop when done
await sdk.stop();

Text event shape

Both onTranscript and onTranslate receive the same object:

FieldTypeDescription
textstringText as sent by the server. Never empty.
finalbooleanfalse for an interim result superseded by a later event, true for a completed utterance.
utteranceIdstring | undefinedLinks the transcript and translate events of one utterance — use it to pair the two.
startstring | undefinedISO 8601 start of the covered audio. Transcript events only.
durationMsnumber | undefinedDuration of the covered audio in milliseconds. Transcript events only.

onTranscript requires transcript.interim and/or transcript.final; onTranslate requires transcript.translate. Omitting the transcript block entirely enables all three; passing {} leaves all of them off.

Deprecated: the untyped onMessage hook still fires for every inbound frame and remains available for backward compatibility, but new integrations should use onTranscript / onTranslate. It will be removed in a future major version.



Did this page help you?