worried-rocket-36543
09/04/2025, 12:34 PMtall-airline-16756
09/04/2025, 12:34 PMtall-airline-16756
09/04/2025, 12:35 PMffmpeg like this:
ffmpeg -i input.wav -ar 8000 -f mulaw output.g711u
2. Read the Audio Data: Then, use Node.js to read those raw μ-law encoded bytes:
import { readFileSync } from 'node:fs';
const audioData = readFileSync('output.g711u');
3. Create and Publish the Audio Track: Next, set up an AudioSource and LocalAudioTrack, and publish them using the rtc-node SDK:
import { AudioSource, LocalAudioTrack, Room, TrackPublishOptions, TrackSource } from '@livekit/rtc-node';
const room = new Room();
await room.connect(url, token, { autoSubscribe: true });
const source = new AudioSource(8000, 1); // 8kHz, mono
const track = LocalAudioTrack.createAudioTrack('mulaw-audio', source);
const options = new TrackPublishOptions();
options.source = TrackSource.SOURCE_MICROPHONE;
await room.localParticipant.publishTrack(track, options);
const buffer = new Uint8Array(audioData);
await source.captureFrame({ data: buffer, sampleRate: 8000, channels: 1, samples: buffer.length });
Just a quick tip: make sure the AudioSource sample rate (8000 Hz) matches your actual audio data to keep things smooth and avoid any resampling hiccups. If you run into any questions or want me to walk you through anything else, just give me a shout!
Sources: res/README.md | config-sample.yaml | livekit-plugins/livekit-plugins-upliftai/livekit/plugins/upliftai/tts.py | packages/livekit-rtc/CHANGELOG.md