How to receive audio in mulaw 8000 format in livek...
# ask-ai
w
How to receive audio in mulaw 8000 format in livekit agent and convert to PCM there?
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.
I'm here to help you receive audio in μ-law 8000 format in a LiveKit agent and convert it to PCM. Let's walk through the steps together: 1. First, please make sure that the incoming audio stream is using the PCMU/8000 codec. 2. Next, you can use the
DecodeULaw
function from the
media-sdk
package to decode the μ-law audio into PCM16 format. Here's a simple example to guide you:
Copy code
// Create a PCM16Writer (e.g., your agent's audio processor or sink)
pcmWriter := yourPcm16Writer

// Wrap it with DecodeULaw to create a ULawWriter
ulawWriter := DecodeULaw(pcmWriter)

// Write μ-law samples directly to ulawWriter
err := ulawWriter.WriteSample(ULawSample{0x83, 0x87, 0x96, ...})
if err != nil {
    log.Fatal(err)
}
1. If you encounter any sample rate mismatches, no worries! You can handle them using the built-in resampling feature of
DecodeULaw
. 2. Also, please double-check that your upstream components or plugins provide μ-law 8000 audio. Plugins like Uplift AI TTS and Speechmatics are great examples that support μ-law encoding. This approach is a reliable and efficient way to convert μ-law audio to PCM16 format, making it perfect for real-time audio processing. If you have any questions or need further assistance, feel free to ask—I'm here to help! Sources: g711/g711.go | livekit-plugins/livekit-plugins-lmnt/livekit/plugins/lmnt/models.py
w
How to push the base64 mulaw 8000 string to Livekit using @livekit/rtc-node?
t
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!