Skip to main content
Version: 0.11.x

Examples

Explore our examples to discover what you can build with the ODIN Node.js SDK.

Available Examples

Stream Audio Files

Stream audio files into ODIN rooms using high-level convenience methods (sendMP3, sendWAV) or low-level control. Perfect for AI voice assistants, music bots, and sound effects.

Learn more
Transcribe Audio

Capture audio streams from room participants and transcribe them in real-time using OpenAI Whisper or other speech-to-text services. Build voice assistants, chatbots, and content moderation tools.

Quick Examples

Basic Recording Bot

import odin from '@4players/odin-nodejs';
import wav from 'wav';

const { OdinClient } = odin;

const client = new OdinClient();
const token = client.generateToken("YOUR_ACCESS_KEY", "room-id", "RecorderBot");
const room = client.createRoom(token);

const recordings = {};

room.onAudioDataReceived((data) => {
const { mediaId, peerId, samples16 } = data;

if (!recordings[mediaId]) {
recordings[mediaId] = new wav.FileWriter(`recording_${peerId}.wav`, {
channels: 2, sampleRate: 48000, bitDepth: 16
});
}

recordings[mediaId].write(Buffer.from(samples16.buffer, samples16.byteOffset, samples16.byteLength));
});

room.onMediaStopped((event) => {
if (recordings[event.mediaId]) {
recordings[event.mediaId].end();
delete recordings[event.mediaId];
}
});

room.join("https://gateway.odin.4players.io");

Simple Music Bot

import odin from '@4players/odin-nodejs';
const { OdinClient } = odin;

const client = new OdinClient();
const token = client.generateToken("YOUR_ACCESS_KEY", "room-id", "MusicBot");
const room = client.createRoom(token);

room.onJoined(async () => {
const media = room.createAudioStream(44100, 2);
await media.sendMP3('./music.mp3');
media.close();
room.close();
});

room.join("https://gateway.odin.4players.io");

More Examples

Check out the tests/ folder in the SDK repository for additional examples:

  • tests/connection-test/ - Basic connection, events, and diagnostics
  • tests/audio-recording/ - Recording peer audio to files
  • tests/sending-audio/ - Sending audio with high-level and low-level APIs