Windows Python3.13运行Livekit Agent时出现AudioFrame属性错误求助
解决livekit.rtc模块无AudioFrame属性的错误
问题描述
Windows系统Python 3.13环境下,运行命令uv run agent.py download-files时触发错误:
AttributeError: module 'livekit.rtc' has no attribute 'AudioFrame'
使用的代码如下:
import logging from dotenv import load_dotenv from livekit import agents from livekit.agents import Agent, AgentServer, AgentSession, JobContext, room_io from livekit.plugins import noise_cancellation, silero load_dotenv() # Define your agent's behavior by extending the Agent class class Assistant(Agent): def __init__(self) -> None: super().__init__( instructions="You are a helpful voice AI assistant.", # System prompt for the LLM ) server = AgentServer() # The entrypoint function runs when a participant joins the room @server.rtc_session() async def entrypoint(ctx: JobContext): # Configure the voice pipeline with STT, LLM, TTS, and VAD providers session = AgentSession( stt="assemblyai/universal-streaming:en", # Speech-to-text provider llm="openai/gpt-4.1-mini", # Language model for responses tts="cartesia/sonic-3", # Text-to-speech voice vad=silero.VAD.load(), # Voice activity detection ) # Start the session with noise cancellation enabled await session.start( agent=Assistant(), room=ctx.room, room_options=room_io.RoomOptions( audio_input=room_io.AudioInputOptions( noise_cancellation=noise_cancellation.BVC(), # Background voice cancellation ), ), ) if __name__ == "__main__": logging.basicConfig(level=logging.INFO) agents.cli.run_app(server)
解决方案
这个错误通常是LiveKit相关依赖包版本不兼容或对Python 3.13支持不完善导致的,按以下步骤处理:
统一LiveKit依赖版本
先卸载现有相关包,再安装经过验证的兼容版本:# 卸载旧包 pip uninstall -y livekit livekit-agents livekit-plugins # 用pip安装兼容版本 pip install livekit==0.17.0 livekit-agents==0.11.0 livekit-plugins==0.5.0 # 或者用uv安装 uv add livekit==0.17.0 livekit-agents==0.11.0 livekit-plugins==0.5.0这些版本的内部模块结构稳定,不会出现
AudioFrame找不到的问题。验证Python版本兼容性
Python 3.13属于较新的版本,部分LiveKit包可能还未完全适配。如果上述步骤无效,可以暂时降级到Python 3.12,再重新安装依赖包测试。检查依赖完整性
运行uv pip list或pip list确认所有LiveKit相关包都已正确安装,没有遗漏或版本不一致的情况。
内容的提问来源于stack exchange,提问作者Archie Enstone
相关产品推荐
相关产品推荐

