rhythmic-room-80043
08/02/2025, 9:22 AMtall-airline-16756
08/02/2025, 9:22 AMtall-airline-16756
08/02/2025, 9:22 AMgo get <http://github.com/livekit/server-sdk-go/v2|github.com/livekit/server-sdk-go/v2>
go get <http://github.com/livekit/media-sdk/webm|github.com/livekit/media-sdk/webm>
2. Generate API Key and Secret: Use your LiveKit API credentials for authentication.
3. Connect to the Room: Use lksdk.ConnectToRoom with your server URL, API key, and secret.
4. Create an Audio Track: Use lkmedia.NewPCMLocalTrack to create an audio track specifying sample rate and channels.
5. Publish the Track: Publish the track to the room using room.LocalParticipant.PublishTrack.
6. Write Audio Samples: Continuously write audio samples to the track.
7. Handle Signals: Set up signal handling for graceful shutdown.
Here is an example code snippet:
package main
import (
"<http://github.com/livekit/server-sdk-go/v2|github.com/livekit/server-sdk-go/v2>"
"<http://github.com/livekit/server-sdk-go/v2/pkg/media|github.com/livekit/server-sdk-go/v2/pkg/media>"
)
func main() {
room, _ := lksdk.ConnectToRoom("<ws://localhost:7880>", lksdk.ConnectInfo{
APIKey: "your_api_key",
APISecret: "your_api_secret",
RoomName: "your_room_name",
ParticipantIdentity: "backend-server",
}, nil)
track, _ := media.NewPCMLocalTrack(48000, 1, nil)
room.LocalParticipant.PublishTrack(track, nil)
// Write audio samples to the track here
}
Let me know if you need further assistance or clarification!rhythmic-room-80043
08/02/2025, 9:23 AMtall-airline-16756
08/02/2025, 9:23 AMnpm install @livekit/rtc-node livekit-server-sdk fs path
2. Generate a JWT Token: Use the livekit-server-sdk to create a token that lets you join and publish audio in the room.
3. Connect to the Room: Use the Room class from @livekit/rtc-node along with your token to connect to the LiveKit server.
4. Create and Publish an Audio Track: Use AudioSource and LocalAudioTrack to make an audio track and publish it to your room.
5. Send Audio Frames: Capture audio frames (like from an audio file) and send them to the track.
Here’s a full example to get you started:
import { Room, LocalAudioTrack, AudioSource, TrackPublishOptions } from '@livekit/rtc-node';
import { AccessToken } from 'livekit-server-sdk';
import fs from 'fs';
const URL = '<ws://your-livekit-server.com>';
const API_KEY = 'your-api-key';
const API_SECRET = 'your-api-secret';
const ROOM_NAME = 'your-room-name';
async function main() {
const room = new Room();
const token = new AccessToken(API_KEY, API_SECRET, { identity: 'backend-participant' });
token.addGrant({ room: ROOM_NAME, roomJoin: true, canPublish: true });
const jwt = await token.toJwt();
await room.connect(URL, jwt);
console.log('Connected to the room');
const source = new AudioSource(16000, 1);
const track = LocalAudioTrack.createAudioTrack('audio', source);
const options = new TrackPublishOptions();
await room.localParticipant.publishTrack(track, options);
console.log('Audio track published successfully');
const audioData = fs.readFileSync('path/to/audio.wav');
const buffer = new Int16Array(audioData.buffer);
for (let i = 0; i < buffer.length; i += 16000) {
const frame = buffer.subarray(i, i + 16000);
await source.captureFrame(frame);
}
await room.disconnect();
}
main().catch(console.error);
If anything’s unclear or you want a hand with any part of this, just let me know—I’m here to help!rhythmic-room-80043
08/02/2025, 9:38 AMtall-airline-16756
08/02/2025, 9:39 AMRoom Name and Observer ID, then hit "Start Observing" to connect. You’ll see live logs showing events, participant changes, and more.
Or, if you prefer, you can use the LiveKit CLI to tail logs straight from an agent by running:
lk agent logs
Feel free to reach out if you want a hand with anything else!
Sources: agent-console/app/page.tsxrhythmic-room-80043
08/02/2025, 10:28 AMtall-airline-16756
08/02/2025, 10:28 AMDataReceived Event: Just listen for the DataReceived event on the Room object. This event fires whenever someone else in the room sends data.
`const room = new Room();
room.on(RoomEvent.DataReceived, (payload, participant, kind) => {
const message = new TextDecoder().decode(payload);
console.log(Received message from ${participant.identity}:, message);
});`
2. Delivery Options: LiveKit offers both reliable and lossy delivery modes. For chat messages, reliable delivery is your best friend since it ensures messages arrive in order and don’t get lost.
3. Message Size Limits: To keep things smooth, try to keep messages under 15KiB for reliable delivery. If you’re using lossy delivery, stay under 1300 bytes to avoid any hiccups with fragmentation.
If anything’s unclear or you want a hand with this, just let me know—I’m here to help!rhythmic-room-80043
08/02/2025, 10:33 AMtall-airline-16756
08/02/2025, 10:34 AMtrack_subscribed event to know when someone shares an audio track. For example:
`room.on(RoomEvent.TrackSubscribed, (track, publication, participant) => {
if (track.kind === 'audio') {
console.log(Subscribed to audio track from ${participant.identity});
// Process the audio track here
}
});`
2. Process Audio Frames: After subscribing, you can dive into the audio frames—maybe calculate dB levels, save the audio, or even play it live.
3. Handle Audio Stream Completion: Don’t forget to tidy up once the audio stream wraps up.
If you want me to walk you through any part or need some tailored examples, just let me know—I’m here to help!rhythmic-room-80043
08/02/2025, 10:37 AMtall-airline-16756
08/02/2025, 10:38 AMsid), name, kind (audio or video), source, and other useful info.
2. Subscription Management: Lets you subscribe or unsubscribe from the track and shows you if you’re currently subscribed.
3. State Control: Handles states like whether the track is muted, simulcasted, or encrypted.
4. Event Handling: Sends out events like muted, unmuted, and subscription changes, so your app can stay up-to-date in real time.
5. Track Association: Once you’re subscribed, it links to the actual media track, so you can play or work with the media directly.
If you’d like me to walk you through it more or show some examples, just let me know—I’m happy to help!