can I send mulaw/8000 audio to livekit using <@U07...
# ask-ai
w
can I send mulaw/8000 audio to livekit using @icy-policeman-64898/rtc-node?
t
Thanks for reaching out, Rohit. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Absolutely, you can send mulaw/8000 audio to LiveKit using rtc-node! LiveKit supports the PCMU/8000 codec (that’s μ-law encoded audio at an 8 kHz sample rate) for WebRTC audio transmission. Here’s a friendly step-by-step on how you can do it: 1. Prepare Your Audio File: First, convert your audio file to the .g711u format using
ffmpeg
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:
Copy code
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:
Copy code
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