You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 24.04 LTS下基于LiveKit构建语音AI代理时遭遇sounddevice.PortAudioError(无效采样率PaErrorCode -9997)问题求助

Fixing PortAudio Invalid Sample Rate Error with LiveKit Voice AI Agent on Ubuntu 24.04

That PortAudioError: Invalid sample rate (-9997) is super common when LiveKit's default audio settings don't play nice with your system's audio hardware. Let's walk through the fixes step by step:

1. First, find out what sample rates your audio device supports

Open up a terminal and run these commands to get your device details:

  • List all audio input devices:
    arecord -l
    
    You'll see output like card 0: XXXX [Device Name], device 0: XXXX [XXX] — note the card and device numbers (e.g., 0,0).
  • Check supported sample rates for that device:
    arecord --dump-hw-params -D plughw:<card>,<device>
    
    Look for lines starting with Sample rates: — this will tell you which rates your hardware accepts (common ones are 16000, 44100, 48000).

2. Force LiveKit to use a compatible sample rate

Modify your RoomInputOptions in the code to explicitly set a sample rate that your device supports. For example, if your device works with 48000:

room_input_options=RoomInputOptions(
    noise_cancellation=noise_cancellation.BVC(),
    sample_rate=48000,  # Replace with your device's supported rate
)

3. Reinstall PortAudio dependencies (if the above doesn't work)

Sometimes Ubuntu's PortAudio packages can get messed up. Reinstall them with:

sudo apt update && sudo apt install --reinstall libportaudio2 portaudio19-dev

Then restart your virtual environment and try running the agent again.

4. For headless/server environments (no physical audio device)

If you're running this on a server without a microphone, you'll need a virtual audio device. Install PulseAudio and set up a null sink:

sudo apt install pulseaudio pulseaudio-utils
pactl load-module module-null-sink sink_name=VirtualSink
pactl set-default-source VirtualSink.monitor

This creates a dummy audio input that LiveKit can use without issues.

Once you've tried these steps, re-run uv run agent.py — it should connect without the sample rate error.

内容的提问来源于stack exchange,提问作者sh1nata

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 06:38:20