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

Code Snippet (English → Spanish Translation)

import {
    KrispVTSDK,
    LogLevel
} from '@krispai/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();
    },
    onMessage: (msg) => {
        // Server transcript / translation events
        if (msg.transcript) console.log('Original:', msg.transcript.text);
        if (msg.translate) console.log('Translated:', msg.translate.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')
});

// 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();