AS AgentScopeAPI 手册 / API Reference
类class agentscope.realtime

TransportBase

class TransportBase(ABC)
源码Source 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_rateint
`input_sample_rate` 字段。
—
output_sample_rateint
`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

int

input_sample_rate 字段。声明为 int。

The input sample rate field.

源码Source agentscope/realtime/_transport/_base.py:58

output_sample_rate

int

output_sample_rate 字段。声明为 int。

The output sample rate field.

源码Source agentscope/realtime/_transport/_base.py:61

方法详情Method Detail

__aenter__

async def __aenter__() -> 'TransportBase'
async

进入异步上下文并返回自身。

Start on entry; the transport's owner is whoever entered.

返回Returns 'TransportBase'
返回'TransportBase'。Returns transport base.
源码Source agentscope/realtime/_transport/_base.py:64–67

__aexit__

async def __aexit__(*exc: object) -> None
async

退出异步上下文并清理资源。

Close on exit.

参数Parameters
名称Name类型Type说明Description
excobjectexc(类型 `object`)。The exc.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/realtime/_transport/_base.py:69–71

start

async def start() -> None
asyncabstractabstractmethod

返回启动。

Open the transport and begin capturing.

返回Returns None
无返回值。No value is returned.
源码Source agentscope/realtime/_transport/_base.py:74–75

close

async def close() -> None
asyncabstractabstractmethod

关闭连接并释放相关资源。

Release every resource held by the transport.

返回Returns None
无返回值。No value is returned.
源码Source agentscope/realtime/_transport/_base.py:78–79

incoming

async def incoming() -> AsyncIterator[TransportFrame]
asyncabstractabstractmethod

返回 incoming 结果。

Yield upstream frames until the transport closes.

返回Returns AsyncIterator[TransportFrame]
以异步流的形式返回TransportFrame。Returns a stream of transport frame.
源码Source agentscope/realtime/_transport/_base.py:82–85

send_audio

async def send_audio(pcm: bytes, item_id: str) -> None
asyncabstractabstractmethod

发送音频。

Queue assistant audio for playback.

参数Parameters
名称Name类型Type说明Description
pcmbytespcm(类型 `bytes`)。PCM16 mono at :attr:`output_sample_rate`.
item_idstr条目标识(类型 `str`)。The assistant item this audio belongs to, so that playback position can be attributed to it.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/realtime/_transport/_base.py:88–97

clear_audio

async def clear_audio() -> PlayoutPosition
asyncabstractabstractmethod

清空音频。

Clear audio playback and return its position before the cut.

返回Returns PlayoutPosition
返回PlayoutPosition。`PlayoutPosition`: The playback position before audio was
源码Source agentscope/realtime/_transport/_base.py:100–106

playout

def playout() -> PlayoutPosition
abstractabstractmethod

返回 playout 结果。

The current playback position, without interrupting.

返回Returns PlayoutPosition
返回PlayoutPosition。Returns playout position.
源码Source agentscope/realtime/_transport/_base.py:109–110
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.