This message was deleted.
# ask-ai
s
This message was deleted.
t
Thanks for reaching out, Harsh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'd be happy to guide you through sending PCM 48kHz audio data to a LiveKit room using the
livekit-rtc
SDK on Node.js. Here’s a simple step-by-step approach: 1. Initialize the Room Connection: Connect to your LiveKit room using the provided URL and access token. Make sure to set up auto-subscription and handle signals properly for graceful shutdowns. 2. Create AudioSource and LocalAudioTrack: Start by creating an
AudioSource
with a sample rate of 48000 Hz, then create a
LocalAudioTrack
from that source. 3. Publish the Track: Publish your track using
room.localParticipant.publishTrack()
, specifying the source as a microphone to let others hear you. 4. Prepare PCM Data: It’s important that your PCM data is in signed 16-bit little-endian format (
pcm_s16le
). Convert this data to an
Int16Array
so it’s ready to be sent. 5. Send Audio Frames: Send audio frames consistently—for example, 10 ms frames, which equals 480 samples at 48kHz—using
source.captureFrame()
. This helps maintain smooth audio streaming. 6. Handle Errors and Cleanup: Wrap your code in try-catch blocks to catch any issues, and don’t forget to clean up resources properly with
waitForPlayout()
and
close()
when you’re done. Making sure your PCM data matches the expected format and timing will really help avoid any hiccups. If you’d like, I can provide more details or even some example code—just let me know! I’m here to help. Sources: Camera & microphone | LiveKit Docs | Docs::Home | examples/publish-wav/index.ts | Track egress | LiveKit Docs | Universal Egress
Thank you for sharing your code! Your approach to connecting to the LiveKit room, creating an
AudioSource
, and publishing the track looks solid. I also see that your method for converting MuLaw to PCM and sending frames with
AudioSource.captureFrame
follows the right steps. Just a few things to double-check to keep everything running smoothly: • Make sure the PCM data is in signed 16-bit little-endian format (
pcm_s16le
). • Confirm that the sample rate matches what you've set in your
AudioSource
configuration (like 48000 Hz). • Verify that your
samplesPerChannel
calculation is spot on—basically, the buffer length divided by the number of channels. • Try to send frames at steady intervals (for example, every 10 ms or 20 ms) to help avoid any audio glitches. If you run into any specific issues or notice errors, please don’t hesitate to share the details. I’m here to help you work through them!
Let’s make sure your audio data is being sent correctly by going through these helpful debugging steps together: 1. Verify PCM Data: Double-check that your PCM data is in the right format (signed 16-bit little-endian) and that it matches the sample rate and channel setup of your
AudioSource
. This is a common spot where things can go off track. 2. Check Frame Timing: Try to keep frames sent at steady intervals (like every 10 ms or 20 ms). Irregular timing can sometimes cause playback hiccups. 3. Monitor Logs: It’s super useful to add some logging to see that
captureFrame
is actually being called and frames are captured properly. For example, logging the size of each frame and its timestamp can give you great insights. 4. Inspect LiveKit Room: Use LiveKit’s room monitoring tools to check if your track is published and active. Also, make sure the track isn’t muted or unsubscribed, as that can silently stop the audio. 5. Test with a Known Source: To narrow down the problem, try swapping your audio input with a known PCM source, like a pre-recorded file. This can help identify if the issue lies in the data conversion process. 6. Check Network Stability: Lastly, a stable network is key! Make sure there are no connectivity issues that might interrupt your audio data transmission. If you’re still running into trouble, please don’t hesitate to share any specific errors or logs from your app or the LiveKit agent. I’m here to help you get this sorted out!
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!