salmon-belgium-62133
11/03/2025, 2:31 PMtall-airline-16756
11/03/2025, 2:32 PMtall-airline-16756
11/03/2025, 2:32 PMsalmon-belgium-62133
11/03/2025, 2:34 PMtall-airline-16756
11/03/2025, 2:35 PMimport { Room, LocalAudioTrack, AudioSource, AudioFrame } from '@livekit/rtc-node';
import { readFileSync } from 'fs';
// Connect to a LiveKit room
const room = new Room();
await room.connect('wss://your-livekit-server-url', 'your-join-token');
// Set up audio source and track
const sampleRate = 48000; // Opus commonly uses 48kHz
const channels = 1;
const source = new AudioSource(sampleRate, channels);
const track = LocalAudioTrack.createAudioTrack('audio', source);
await room.localParticipant.publishTrack(track);
// Read and send audio data (PCM format)
const audioData = readFileSync('/path/to/audio.pcm'); // Raw PCM Int16 16-bit samples
const buffer = new Int16Array(audioData.buffer);
await source.captureFrame(new AudioFrame(buffer, sampleRate, channels, buffer.length));
// Cleanup when done
await track.close();
await room.disconnect();
This code shows you how to connect to a LiveKit room, set up an audio source, and send PCM audio data, which LiveKit will automatically encode to Opus for you. If you have any questions or need a hand with anything else, please don’t hesitate to ask—I’m here to help!
Sources: packages/livekit-rtc/README.md | pkg/sip/room.go | opus/opus.go | livekit-agents/livekit/agents/voice/room_io/_pre_connect_audio.pysalmon-belgium-62133
11/03/2025, 2:35 PMtall-airline-16756
11/03/2025, 2:37 PMaudio/opus).
• FFmpeg Integration: You might also consider using FFmpeg to encode your audio to Opus and then publish it to LiveKit via the CLI—this can be handy for testing or development.
If any of these sound like something you’d like to explore further, just let me know! I’m here to help you through it.
Sources: README.md | livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/stt.py | README.md | Track egress | LiveKit docs | WhatsApp Integration with LiveKitsalmon-belgium-62133
11/03/2025, 2:40 PMtall-airline-16756
11/03/2025, 2:41 PMsampleRate, channels, and the correct MIME type (for example, audio/opus).
• Use helpful tools such as the LiveKit Go SDK or the GStreamer Publisher to programmatically send your Opus stream into a LiveKit room.
• Just keep in mind that the stream should be raw Opus data—usually wrapped in an Ogg container—and not mixed into a video container format.
If you’d like, I’m here to guide you through the implementation or answer any questions you might have!
Sources: tests/change-sophie.opus | README.md | pkg/provider/opuslooper.go | README.md | Track egress | LiveKit docssalmon-belgium-62133
11/03/2025, 2:47 PMtall-airline-16756
11/03/2025, 2:48 PMimport { Room } from '@livekit/rtc-node';
// Connect to the room
const room = new Room();
await room.connect('wss://your-livekit-server-url', 'your-join-token');
const localParticipant = room.localParticipant;
// Open a byte stream writer
const writer = await localParticipant.streamBytes({
name: 'custom-opus-stream',
topic: 'audio/opus', // Custom topic to identify the stream
mimeType: 'audio/opus', // Indicate Opus format
});
// Simulate sending Opus packets (replace this with actual Opus data source)
const opusPackets = getOpusPacketStream(); // Your Opus data source
for (const packet of opusPackets) {
await writer.write(packet); // Send each Opus frame
}
// Close the stream when done
await writer.close();
Just a heads-up: you’ll want to replace getOpusPacketStream() with your actual Opus encoder output or file reader. If you run into any questions or need a hand with this, please don’t hesitate to reach out—I’m here to help!
Sources: livekit-agents/livekit/agents/voice/room_io/_pre_connect_audio.py | Track egress | LiveKit docs | Sending files & bytes | LiveKit docssalmon-belgium-62133
11/03/2025, 2:58 PMtall-airline-16756
11/03/2025, 2:59 PMAudioStreamDecoder utility that can help with this conversion. It takes your Opus audio and turns it into the PCM format that STT requires. If you’d like, I’m here to walk you through how to set this up—just let me know!
Sources: livekit-agents/livekit/agents/voice/agent_session.py | AI Agents Framework | livekit/livekit_composite | DeepWiki