brainy-shoe-64693
12/11/2025, 10:59 AMtall-airline-16756
12/11/2025, 10:59 AMtall-airline-16756
12/11/2025, 10:59 AMnoise_cancellation.BVC() and self-hosted LiveKit: noise_cancellation.BVC() is not available for self-hosted deployments. It’s part of LiveKit Cloud’s enhanced noise-cancellation (licensed Krisp models) and must be removed from agent code when self-hosting.
If you'd like, I can suggest alternative noise-suppression approaches you can run in a self-hosted setup—what environment/language is your agent running in?
Sources: Voice AI quickstart | LiveKit docsbrainy-shoe-64693
12/11/2025, 11:01 AMtall-airline-16756
12/11/2025, 11:01 AMnoise_cancellation.BVC() in self-hosted. Here are practical alternatives you can apply now:
1) Enable Azure Realtime noise reduction
• Use Azure’s input_audio_noise_reduction (e.g., "non_linear") when creating the Realtime model to reduce noise before transcription/processing.
2) Apply client-side WebRTC noise/echo suppression
• Enable noiseSuppression and echoCancellation in browser/mobile capture so audio is cleaner before publishing.
3) Add server-side preprocessing in your agent pipeline (recommended for SIP)
• Intercept raw audio frames in your agent, run a DSP/noise-suppression library, then forward cleaned frames to Azure.
• Lightweight options: RNNoise (real-time, CPU-friendly). For higher quality with GPU, consider NVIDIA solutions.
• Use different filters for SIP (narrowband) vs. general participants — detect participant.kind == SIP and apply telephony-tuned filtering.
4) Use SIP/provider-side features
• Check your SIP trunk provider (Twilio, Telnyx, etc.) for echo suppression or noise reduction and enable those features.
5) Monitor and iterate
• Record samples and use session metrics to evaluate which combination (Azure reduction + client-side + RNNoise) gives the best tradeoff between quality and latency.
If you want, I can:
• Provide a short code example showing where to run RNNoise on LiveKit audio frames for your agent language (which language/runtime is your agent written in?).
• Show the exact Azure Realtime parameter snippet for input_audio_noise_reduction. Sources: Enhanced noise cancellation | LiveKit docs | Noise & echo cancellation | LiveKit docs | Pipeline nodes and hooks | LiveKit docs | Azure OpenAI Realtime API and LiveKit | LiveKit docs | sip | livekit/livekit_composite | DeepWikibrainy-shoe-64693
12/11/2025, 11:02 AMtall-airline-16756
12/11/2025, 11:03 AMlivekit Python interface that yields AudioFrame objects, and rnnoise library with RNNoise processor. Adapt to your SDK.
import numpy as np
import asyncio
import rnnoise # example binding; install or wrap C library
from your_livekit_agent_sdk import AudioFrame, get_audio_stream, send_audio_frame
import resampy # or librosa, torchaudio
RNNOISE_SR = 16000
FRAME_MS = 30
FRAME_SAMPLES = int(RNNOISE_SR * FRAME_MS / 1000) # 480 samples for 30ms
def pcm_bytes_to_int16_array(pcm_bytes):
return np.frombuffer(pcm_bytes, dtype=np.int16)
def int16_array_to_pcm_bytes(arr):
return arr.astype(np.int16).tobytes()
async def process_stream():
rn = rnnoise.RNNoise() # construct RNNoise processor
async for in_frame in get_audio_stream(): # yields AudioFrame with .data, .sample_rate, .channels
# 1) Downmix to mono if needed
data = pcm_bytes_to_int16_array(in_frame.data)
if in_frame.channels == 2:
data = data.reshape(-1, 2).mean(axis=1).astype(np.int16)
# 2) Resample to RNNoise SR if needed
if in_frame.sample_rate != RNNOISE_SR:
data = resampy.resample(data.astype(np.float32), in_frame.sample_rate, RNNOISE_SR)
data = np.clip(data, -32768, 32767).astype(np.int16)
# 3) Frame and process
processed = []
offset = 0
total_samples = data.shape[0]
while offset + FRAME_SAMPLES <= total_samples:
frame_samples = data[offset:offset + FRAME_SAMPLES]
out = rn.process(frame_samples) # returns int16 array of FRAME_SAMPLES
processed.append(out)
offset += FRAME_SAMPLES
# Handle tail (zero-pad)
if offset < total_samples:
tail = np.zeros(FRAME_SAMPLES, dtype=np.int16)
remaining = total_samples - offset
tail[:remaining] = data[offset:offset + remaining]
out = rn.process(tail)
processed.append(out)
processed_pcm = np.concatenate(processed)
# 4) Resample back if original sample rate differs
if in_frame.sample_rate != RNNOISE_SR:
processed_pcm = resampy.resample(processed_pcm.astype(np.float32), RNNOISE_SR, in_frame.sample_rate)
processed_pcm = np.clip(processed_pcm, -32768, 32767).astype(np.int16)
# 5) Send cleaned audio frame onward
out_bytes = int16_array_to_pcm_bytes(processed_pcm)
out_frame = AudioFrame(
data=out_bytes,
sample_rate=in_frame.sample_rate,
num_channels=1,
samples_per_channel=len(processed_pcm)
)
await send_audio_frame(out_frame)
# Run the processor
asyncio.run(process_stream())
Key implementation notes
• Telephony (SIP) is usually 8 kHz: resample 8 kHz → 16 kHz, run RNNoise, then resample back to 8 kHz. RNNoise works significantly better at 16 kHz than at 8 kHz.
• Use frame sizes RNNoise expects (20–30 ms). Keep strict framing to avoid artifacts.
• Minimize added latency: keep processing in streaming fashion, use a small processing buffer, and avoid batch resampling that adds delay.
• If using a compiled RNNoise C library, consider a thin C extension for performance rather than a pure-Python binding.
• Test CPU usage; RNNoise is lightweight but still consumes CPU per concurrent call. Scale horizontally or use worker pools for many concurrent SIP calls.
Where in LiveKit agent to hook this
• If you have an agent that gets raw audio from participants (e.g., via LiveKit’s audio pull or plugin hooks), intercept there before you hand audio to Azure Realtime or your STT.
• If integrating at SIP ingress, hook into the RTP to PCM conversion stage (before any encoding/transcoding to the model).
• If using LiveKit recordings or transforms pipeline, add a preprocessing transform step that replaces the audio track with the cleaned audio.
Would you like:
• A focused SIP-specific example handling 8 kHz RTP payload resample and RNNoise?
• A recommendation for a specific Python RNNoise binding or a small C wrapper example?brainy-shoe-64693
12/15/2025, 10:28 AMtall-airline-16756
12/15/2025, 10:28 AMinput_audio_noise_reduction can be used in combination (RNNoise preprocessing + Azure reduction) for stronger results.
If you want, I can provide:
• A SIP-focused code snippet showing resample 8 kHz → 16 kHz → RNNoise → resample → send to Azure realtime, or
• A short example in the specific language/runtime your agent uses. Which language is your agent written in?brainy-shoe-64693
12/15/2025, 10:29 AMtall-airline-16756
12/15/2025, 10:29 AMrnnoise with a process(frame_samples) method).
• A resampling library (example uses resampy).
• Access to raw PCM audio frames in your LiveKit agent (or RTP→PCM conversion for SIP).
Short example (assumes 16-bit PCM input; telephony 8 kHz resampled to 16 kHz):
import numpy as np
import resampy
import rnnoise # your RNNoise binding
# Hypothetical LiveKit agent functions:
# async for frame in pull_audio_frames(): yields AudioFrame(data: bytes, sample_rate: int, channels: int)
# await send_to_azure_realtime(pcm_bytes: bytes, sample_rate: int, channels: int)
RN_SR = 16000
FRAME_MS = 30
FRAME_SAMPLES = int(RN_SR * FRAME_MS / 1000) # 480 samples
def bytes_to_int16(arr_bytes):
return np.frombuffer(arr_bytes, dtype=np.int16)
def int16_to_bytes(arr):
return arr.astype(np.int16).tobytes()
async def rnnoise_pipeline():
rn = rnnoise.RNNoise()
async for in_frame in pull_audio_frames():
pcm = bytes_to_int16(in_frame.data)
# Downmix to mono if stereo
if in_frame.channels == 2:
pcm = pcm.reshape(-1, 2).mean(axis=1).astype(np.int16)
# Resample to RNNoise SR if needed
if in_frame.sample_rate != RN_SR:
pcm = resampy.resample(pcm.astype(np.float32), in_frame.sample_rate, RN_SR)
pcm = np.clip(pcm, -32768, 32767).astype(np.int16)
# Frame-wise processing
processed_frames = []
i = 0
total = len(pcm)
while i + FRAME_SAMPLES <= total:
frame_samples = pcm[i:i + FRAME_SAMPLES]
out = rn.process(frame_samples) # returns int16 numpy array length FRAME_SAMPLES
processed_frames.append(out)
i += FRAME_SAMPLES
# tail (zero-pad)
if i < total:
tail = np.zeros(FRAME_SAMPLES, dtype=np.int16)
rem = total - i
tail[:rem] = pcm[i:]
out = rn.process(tail)
processed_frames.append(out)
cleaned = np.concatenate(processed_frames)
# Resample back to original sample_rate if required by downstream
target_sr = in_frame.sample_rate
if target_sr != RN_SR:
cleaned = resampy.resample(cleaned.astype(np.float32), RN_SR, target_sr)
cleaned = np.clip(cleaned, -32768, 32767).astype(np.int16)
out_bytes = int16_to_bytes(cleaned)
await send_to_azure_realtime(out_bytes, sample_rate=target_sr, channels=1)
Where to add this code in your agent pipeline
• If you get audio from LiveKit participant tracks: hook this as a preprocessing step immediately after you receive raw PCM AudioFrames and before handing audio to the Azure Realtime input.
• If you ingest SIP RTP: add this after RTP→PCM decoding and before you encode/wrap audio to send to the realtime model.
• If you have a central audio transform pipeline or middleware, add this as a transform that replaces the incoming audio track with the cleaned track.
Practical tips
• For SIP (8 kHz) resample 8→16 kHz, run RNNoise, then 16→8 kHz if your downstream requires 8 kHz.
• Keep frame sizes strict (20–30 ms) to avoid artifacts and minimize latency.
• Use an efficient RNNoise binding (C extension) and consider a worker pool for many concurrent calls.
• Monitor CPU and latency when enabling this in production.
Would you like a SIP-specific variant handling RTP packet decoding and resampling, or a recommendation for a Python RNNoise binding to use?