agentscope.realtimeTransportBase
class TransportBase(ABC)
agentscope/realtime/_transport/_base.py:48–110传输层基类,处理低延迟的实时语音与多模态交互。位于 agentscope.realtime 包,继承自 ABC。核心成员包括 start、close、incoming、send_audio、clear_audio、playout。
A transport is a browser connection, a local sound card, or a queue
the caller drives — the agent cannot tell the difference. It is owned
by whoever created it, not by the agent; :meth:RealtimeAgent.run
only borrows it.
属性摘要Attribute Summary
| 属性Attribute | 类型Type | 说明Description | 值Value |
|---|---|---|---|
input_sample_rate | int | `input_sample_rate` 字段。 | — |
output_sample_rate | int | `output_sample_rate` 字段。 | — |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
async def __aenter__() -> 'TransportBase'async | 进入异步上下文并返回自身。 Start on entry; the transport's owner is whoever entered. |
async def __aexit__(*exc: object) -> Noneasync | 退出异步上下文并清理资源。 Close on exit. |
async def start() -> Noneasyncabstractabstractmethod | 返回启动。 Open the transport and begin capturing. |
async def close() -> Noneasyncabstractabstractmethod | 关闭连接并释放相关资源。 Release every resource held by the transport. |
async def incoming() -> AsyncIterator[TransportFrame]asyncabstractabstractmethod | 返回 `incoming` 结果。 Yield upstream frames until the transport closes. |
async def send_audio(pcm: bytes, item_id: str) -> Noneasyncabstractabstractmethod | 发送音频。 Queue assistant audio for playback. |
async def clear_audio() -> PlayoutPositionasyncabstractabstractmethod | 清空音频。 Clear audio playback and return its position before the cut. |
def playout() -> PlayoutPositionabstractabstractmethod | 返回 `playout` 结果。 The current playback position, without interrupting. |
属性详情Attribute Detail
input_sample_rate
intinput_sample_rate 字段。声明为 int。
The input sample rate field.
agentscope/realtime/_transport/_base.py:58output_sample_rate
intoutput_sample_rate 字段。声明为 int。
The output sample rate field.
agentscope/realtime/_transport/_base.py:61方法详情Method Detail
__aenter__
async def __aenter__() -> 'TransportBase'
进入异步上下文并返回自身。
Start on entry; the transport's owner is whoever entered.
agentscope/realtime/_transport/_base.py:64–67__aexit__
async def __aexit__(*exc: object) -> None
退出异步上下文并清理资源。
Close on exit.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
exc | object | exc(类型 `object`)。The exc. |
agentscope/realtime/_transport/_base.py:69–71start
async def start() -> None
返回启动。
Open the transport and begin capturing.
agentscope/realtime/_transport/_base.py:74–75close
async def close() -> None
关闭连接并释放相关资源。
Release every resource held by the transport.
agentscope/realtime/_transport/_base.py:78–79incoming
async def incoming() -> AsyncIterator[TransportFrame]
返回 incoming 结果。
Yield upstream frames until the transport closes.
agentscope/realtime/_transport/_base.py:82–85send_audio
async def send_audio(pcm: bytes, item_id: str) -> None
发送音频。
Queue assistant audio for playback.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
pcm | bytes | pcm(类型 `bytes`)。PCM16 mono at :attr:`output_sample_rate`. |
item_id | str | 条目标识(类型 `str`)。The assistant item this audio belongs to, so that playback position can be attributed to it. |
agentscope/realtime/_transport/_base.py:88–97clear_audio
async def clear_audio() -> PlayoutPosition
清空音频。
Clear audio playback and return its position before the cut.
agentscope/realtime/_transport/_base.py:100–106playout
def playout() -> PlayoutPosition
返回 playout 结果。
The current playback position, without interrupting.
agentscope/realtime/_transport/_base.py:109–110