实时语音模型在智能体中的接入方式与能力边界
LiveKit 文档介绍实时模型可直接处理语音输入输出,省去语音转文字与文字转语音环节,并能捕捉情绪等文本转写难以保留的线索。文中说明在 AgentSession 中把实时模型实例传给 llm 参数即可接入,并讨论了全双工模型的行为差异与轮次检测方面的限制。
LiveKit 文档 › 构建智能体 › 模型 › 实时 › 概述 --- # 实时模型概览 > 为您的代理添加实时模型集成的指南 。 ## 概览 实时模型能够直接消耗和生成语音,绕过带有speech-to-text和text-to-speech组件的语音管道的需要,它们可以更好地理解输入语音的情感背景,以及其他可能无法很好地翻译为文本转录的口头提示.此外,生成的语音还可以包括类似的情感方面,以及对text-to-speech模型所能产生的其它改进. 您也可以同时使用支持的实时模型 [TTS](https://docs.livekit.io/agents/models/tts.md) 以获取实时语音理解的好处,同时保持对语音输出的完全控制。 您可以选择通过 LiveKit 推论服务的一个实时模型, 包含 LiveKit Cloud 。 在 LiveKit 推论中, 您可以使用您的 LiveKit Cloud 证书, 而不是提供 API 密钥, 以及 LiveKit Cloud 向您收取使用费。 如果您更愿意管理自己的帐单, 或者需要访问目前无法通过 LiveKit 推论获取的供应商, 请使用插件 。 ### 基于圆形和全复式模型 实时模型要么是回合制,要么是完全双倍式: - **回合制**:模型等待用户完成发言,然后回复。大多数实时模型都是这样工作的,包括: [OpenAI 实时 API](https://docs.livekit.io/agents/models/realtime/openai.md). - **完全复数**:模型同时聆听和说话,决定每个转弯开始和停止的时间. [OpenAI GPT-Live (英语).](https://docs.livekit.io/agents/models/realtime/gpt-live.md) 是一个完全复杂的模型。 在自然对话流最紧要时选择一个全复式模型。 它比回合式模型更自然地处理重叠的语音和回通道。 选择一个回合式模型, 如 OpenAI 实时 API, 当您想要配置自己转动检测或者将模型与单独的 TTS 组合在一起时 [实时混合结构](#separate-tts). GPT-Live 也不支持. 完全复式模型在几个方面与回合式模型不同。详情请参见 [完全复式模型](#duplex-models). ### LiveKit 推论 下表列出可通过下列方式获得的实时模型: [LiveKit 推论](https://docs.livekit.io/agents/models/inference.md#realtime)。请参考每个提供者的指南,了解更多关于其他配置选项的详情。 检查标记在 **EU 终点** 以下表格中的列表示该模型除了全局端点外,还有一个专用的EU端点。要了解更多,请参见 [数据居住情况](https://docs.livekit.io/agents/models/inference.md#data-residency). #### [双子座直播 API](https://docs.livekit.io/agents/models/realtime/gemini.md) | 型号名称 | 型号 ID | 类型 | EU 终点 | | ---------- | -------- | ---- | ------ | | Gemini 3.8 现场 | `google/gemini-3.8-live` | 回合制 | ✓ | | Gemini 3.8 现场扩展思维 | `google/gemini-3.8-live-extended-thinking` | 回合制 | | #### [OpenAI GPT-Live (英语).](https://docs.livekit.io/agents/models/realtime/gpt-live.md) | 型号名称 | 型号 ID | 类型 | EU 终点 | | ---------- | -------- | ---- | ------ | | GPT - Live 1 (英语). | `openai/gpt-live-1` | 完全复数 | ✓ | #### [OpenAI 实时 API](https://docs.livekit.io/agents/models/realtime/openai.md) | 型号名称 | 型号 ID | 类型 | EU 终点 | | ---------- | -------- | ---- | ------ | | GPT - Live 1.1 (英语). | `openai/gpt-live-1.1` | 回合制 | | | GPT 实时 2.1 | `openai/gpt-realtime-2.1` | 回合制 | ✓ | | GPT 实时 2.1 小型 | `openai/gpt-realtime-2.1-mini` | 回合制 | ✓ | #### [里梅棱镜](https://docs.livekit.io/agents/models/realtime/rime.md) | 型号名称 | 型号 ID | 类型 | EU 终点 | | ---------- | -------- | ---- | ------ | | 棱镜 | `rime/prism` | 回合制 | | #### [SpaceXAI 格罗克语音代理 API](https://docs.livekit.io/agents/models/realtime/spacexai.md) | 型号名称 | 型号 ID | 类型 | EU 终点 | | ---------- | -------- | ---- | ------ | | 格罗克之声 3.0 | `xai/grok-voice-3.0` | 回合制 | | ### 插件 LiveKit代理框架还包括流行的实时模型的插件. 插件需要由提供者自己认证,通常使用API密钥,您自己管理账单. 下表列出可用的实时模型提供者,以及它们对于Python或Node.js的可用性. | 供应商 | Python 键 | 节点.js | | -------- | ------ | ------- | | [亚马逊新索尼奇](https://docs.livekit.io/agents/models/realtime/nova-sonic.md) | ✓ | — | | [Azure OpenAI 实时 API](https://docs.livekit.io/agents/models/realtime/azure-openai.md) | ✓ | ✓ | | [双子座直播 API](https://docs.livekit.io/agents/models/realtime/gemini.md) | ✓ | ✓ | | [NVIDIA PersonaPlex](https://docs.livekit.io/agents/models/realtime/personaplex.md) | ✓ | — | | [OpenAI GPT-Live (英语).](https://docs.livekit.io/agents/models/realtime/gpt-live.md) | ✓ | ✓ | | [OpenAI 实时 API](https://docs.livekit.io/agents/models/realtime/openai.md) | ✓ | ✓ | | [语音对语音](https://docs.livekit.io/agents/models/realtime/phonic.md) | ✓ | ✓ | | [里梅棱镜](https://docs.livekit.io/agents/models/realtime/rime.md) | ✓ | — | | [SpaceXAI 格罗克语音代理 API](https://docs.livekit.io/agents/models/realtime/spacexai.md) | ✓ | ✓ | | [ThunderPhone](https://docs.livekit.io/agents/models/realtime/thunderphone.md) | ✓ | — | | [Ultravox 实时](https://docs.livekit.io/agents/models/realtime/ultravox.md) | ✓ | — | LiveKit是开源的,欢迎 [新插件贡献](https://docs.livekit.io/agents/models.md#contribute). ## 使用量 建立一个实时的模型在一个 `AgentSession`,将一个实时模型实例传递给 `llm` 参数,代替 [LLM 实例](https://docs.livekit.io/agents/models/llm.md). ### LiveKit 推论用法 用 LiveKit 推论,使用 `RealtimeModel` 课从 `inference` 模块。 [模型列表](#inference) 用于可供使用的模型。 ** 文件名 : `agent.py`** ```python from livekit.agents import AgentSession, inference session = AgentSession( llm=inference.RealtimeModel(model="openai/gpt-realtime-2.1"), ) ``` ** 文件名 : `agent.ts`** ```typescript import { AgentSession, inference } from '@livekit/agents'; const session = new AgentSession({ llm: new inference.RealtimeModel({ model: "openai/gpt-realtime-2.1" }), }); ``` ### 插件使用 实时模型插件具有创建模型实例的构造器方法。 您可以直接将此实例传递给一个 `AgentSession` 或 时 间 `Agent` 在它的构造器。 以下示例使用 [OpenAI GPT-Live (英语).](https://docs.livekit.io/agents/models/realtime/gpt-live.md)。对于与另一个提供者的等效,请参见提供者的插件页。 ** 文件名 : `agent.py`** ```python from livekit.agents import AgentSession from livekit.plugins import openai session = AgentSession( llm=openai.realtime.GPTLiveModel(voice="marin") ) ``` ** 文件名 : `agent.ts`** ```typescript import voice from '@livekit/agents'; import * as openai from '@livekit/agents-plugin-openai'; const session = new voice.AgentSession({ llm: new openai.realtime.GPTLiveModel({ voice: 'marin' }) }); ``` 关于安装和使用插件的更多信息,请参见: [插件概览](https://docs.livekit.io/agents/models.md#plugins). ### 单独的 TTS 配置 使用不同的实时模型 [TTS 实例](https://docs.livekit.io/agents/models/tts.md),配置实时模型,以使用文本唯一的响应模式,并包含一个TTS实例中 `AgentSession` 配置 。 在此设置中, 实时模型不生成音频; 所有语音合成都由配置的 TTS 处理 。 这通常被称为实时混合架构(或非正式地作为半卡片或半复式管道),当您想要实时语音理解和完全控制您的代理人所说的话时使用它。实时混合架构具有以下优点: - **实时语音理解**: 实时模型在用户语音中仍然能听到流畅和情感的提示. - **输出控制**: 一个单独的TTS允许您讲精确的脚本,并选择您TTS提供商支持的任何语音. 取舍在于您同时配置和操作一个实时模型和一个TTS,因此设置比纯实时代理更接近管道. **LiveKit 推论**: ** 文件名 : `agent.py`** ```python from livekit.agents import AgentSession, inference session = AgentSession( llm=inference.RealtimeModel(model="openai/gpt-realtime-2.1", modalities=["text"]), tts="fishaudio/s2.1-pro:fa4c9eb3dccc4806b382b40d61c6b10a", # Or other TTS instance of your choice ) ``` ** 文件名 : `agent.ts`** ```typescript import { AgentSession, inference } from '@livekit/agents'; const session = new AgentSession({ llm: new inference.RealtimeModel({ model: 'openai/gpt-realtime-2.1', modalities: ['text'] }), tts: 'fishaudio/s2.1-pro:fa4c9eb3dccc4806b382b40d61c6b10a', // Or other TTS instance of your choice }); ``` --- **插头**: ** 文件名 : `agent.py`** ```python session = AgentSession( llm=openai.realtime.RealtimeModel(modalities=["text"]), # Or other realtime model plugin tts="fishaudio/s2.1-pro:fa4c9eb3dccc4806b382b40d61c6b10a" # Or other TTS instance of your choice ) ``` ** 文件名 : `agent.ts`** ```typescript const session = new voice.AgentSession({ llm: new openai.realtime.RealtimeModel({ modalities: ["text"] }), // Or other realtime model plugin tts: "fishaudio/s2.1-pro:fa4c9eb3dccc4806b382b40d61c6b10a" // Or other TTS instance of your choice }); ``` 此功能需要实时模式支持文本唯一的响应模式. 访问相关提供者页面了解所支持的特性的细节. ## 完全复式模型 用一个 [完全复式模型](#realtime-model-types),传递给 `llm` 理由 `AgentSession` 或 时 间 `Agent`。其余的代理代码不变。关于完整的API,请参见 [`llm` 模块参考](https://docs.livekit.io/reference/python/livekit/agents/llm/index.html.md#livekit.agents.llm.DuplexModel) 为彼菩萨. ### 行为差异 下表描述一个代理人在使用全复式模型时的表现: | 特性 | 具有全复式模型的行为 | | --- | --- | | 中断 | 当用户中断时,LiveKit Agents可以阻止代理的音频,但该模型继续说话,直到自己停止. | | 语录 | 对话项目在它们描述的音频后到达. LiveKit Agents计算从音频中转换边界,因为模型的输出是连续的,包含沉默. | | 脚本发言 | 代理人不能逐字说一个脚本字. `session.say()` 只有在您添加一个 [TTS](https://docs.livekit.io/agents/models/tts.md) 页:1 `AgentSession`,而模型可以和TTS同时说话。对于确切的措辞,请使用一个 [STT-LLM-TTS输油管](https://docs.livekit.io/agents/models/pipelines.md). | | 聊天上下文 | 会话开始后,模型只获得新的聊天项目。如果修改或删除一个项目,LiveKit代理记录一个警告,模型保留原始内容. | | `generate_reply()` | 只有在提供者支持的情况下才有效。模型的下一个发言是回答。如果提供者不支持,或者模型在10秒内没有开始说话,则回答失败。 `RealtimeError`. | | 测试 | 文本模拟不可用。 使用 `lk agent simulate audio` 改为: [测试](https://docs.livekit.io/testing/simulations.md) 经纪人。 | ### 访问双层会话 `AgentSession` 只使用所有实时模型共享的方法和事件。要使用特定提供者的特性,例如 GBT-Live `append_thinking()` 方法或软件 `delegation_created` 中,从 `Agent.duplex_session` 在 Python 中属性或 `Agent.duplexSession` 在节点.js。 如果代理商没有运行,或者其模型不是全复模型,则该属性会产生错误。在Node.js中,该属性有底部 `DuplexSession` 类型,所以在调用提供者方法之前请检查该插件的会话类实例。 以下示例使用了来自 [GPT - 生活( GPT- Live)](https://docs.livekit.io/agents/models/realtime/gpt-live.md#conversation-context) 。其他提供者有不同的方法。 **Python 键**: ```python from livekit.agents import Agent from livekit.plugins import openai class Assistant(Agent): def __init__(self) -> None: super().__init__( instructions="You are a helpful voice assistant.", llm=openai.realtime.GPTLiveModel(), ) async def on_enter(self) -> None: # append_thinking is a GPT-Live method, not part of DuplexSession self.duplex_session.append_thinking("The caller is a Priority Plus member.") ``` --- **节点.js**: ```typescript import { voice } from '@livekit/agents'; import * as openai from '@livekit/agents-plugin-openai'; class Assistant extends voice.Agent { constructor() { super({ instructions: 'You are a helpful voice assistant.', llm: new openai.realtime.GPTLiveModel(), }); } async onEnter(): Promise<void> { // appendThinking is a GPT-Live method, not part of DuplexSession const live = this.duplexSession; if (!(live instanceof openai.realtime.GPTLiveSession)) { throw new Error('Expected GPTLiveSession'); } live.appendThinking('The caller is a Priority Plus member.'); } } ``` ## B. 考虑和限制 实时模型因其音频理解和表达输出范围更广而带来巨大好处,但是,它们也有一些限制和考虑需要记住。关于所有管道类型的side-by-side比较,请参见 [管道类型](https://docs.livekit.io/agents/models/pipelines.md). ### 转向检测和 VAD 一般来说,LiveKit 建议尽可能使用实时模型内置的轮次检测能力。准确的轮次检测依赖于 VAD 以及从实时语音转文本中获得的上下文,而如下文所述,实时模型并不具备这一能力。如果你需要使用 LiveKit [转弯探测器模型](https://docs.livekit.io/agents/logic/turns/turn-detector.md),您还必须添加一个单独的 STT 插件,以提供必要的临时笔录。 ### 延迟转录 实时模型不提供临时的转录结果,一般来说,用户输入转录可以被大大延迟,并且经常在代理回复后到达. 需要实时转录的,应当考虑STT-LLM-TTS管道,或者为实时转录添加单独的STT插件. ### 脚本语音输出 实时模型不提供直接从文本脚本生成语音的方法,例如使用 `say` 方法。您可以通过 `generate_reply(instructions='...')` 并包含特定指令,但不能保证输出精确遵循任何提供的脚本。如果您的应用程序需要使用特定的脚本,请考虑使用该模型 [带有单独的 TTS 实例](#separate-tts) 完全复式模型不支持这种设置。 [完全复式模型](#duplex-models) 以获取更多信息。 ### 正在装入对话历史 当前的模型只支持文本格式的加载调用历史。 这限制了它们解释情绪背景和其他可能无法很好地翻译为文本转录的口头提示的能力。 此外, OpenAI 实时 API 在加载大量历史之后, 也更有可能在文本中响应, 即使配置为使用语音。 对于 OpenAI, 建议您使用一个 [单独的 TTS 实例](#separate-tts) 如果您需要加载对话历史。 --- 该文件在2026 - 12-01T16:19:24.563Z. 本文件的最新版本见: [https://docs.livekit.io/agents/models/realtime.md](https://docs.livekit.io/agents/models/realtime.md). 要探索所有 LiveKit 文档,请参见 [页:1](https://docs.livekit.io/llms.txt).
查看原始来源