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

LocalAudioTransport

class LocalAudioTransport(TransportBase)
源码Source agentscope/realtime/_transport/_local.py:15–209

本地音频传输层,处理低延迟的实时语音与多模态交互。位于 agentscope.realtime 包,继承自 TransportBase。核心成员包括 start、close、incoming、send_audio、clear_audio、playout。

Audio callbacks run on PortAudio's thread, not the event loop: captured chunks are handed to the loop with call_soon_threadsafe and playback pulls from a lock-guarded buffer. Playout accounting lives in that callback, the same place a browser's AudioWorklet does it.

构造器摘要Constructor Summary

构造器Constructor说明Description
def __init__(input_sample_rate: int = 16000, output_sample_rate: int = 24000, input_device: int | str | None = None, ou…
初始化 `LocalAudioTransport` 实例。
Initialize the transport.

方法摘要Method Summary

方法Method说明Description
async def start() -> Noneasync
返回启动。
Open both streams.
async def close() -> Noneasync
关闭连接并释放相关资源。
Stop both streams and end :meth:`incoming`.
async def incoming() -> AsyncIterator[TransportFrame]async
返回 `incoming` 结果。
Yield captured chunks until :meth:`close`.
async def send_audio(pcm: bytes, item_id: str) -> Noneasync
发送音频。
Queue assistant audio. A new item resets the playout counters.
async def clear_audio() -> PlayoutPositionasync
清空音频。
Fade the head of the queue out, drop the rest, report the cut.
def playout() -> PlayoutPosition
返回 `playout` 结果。
The current playback position.

构造器详情Constructor Detail

LocalAudioTransport

def __init__(input_sample_rate: int = 16000, output_sample_rate: int = 24000, input_device: int | str | None = None, output_device: int | str | None = None, chunk_ms: int = 100, fade_ms: int = 30) -> None

初始化 LocalAudioTransport 实例。

Initialize the transport.

参数Parameters
名称Name类型Type说明Description
input_sample_rate默认default 16000int输入 sample 速率(类型 `int`)。Capture rate; should match the model's input rate.
output_sample_rate默认default 24000int输出 sample 速率(类型 `int`)。Playback rate; should match the model's output rate.
input_device默认default Noneint | str | None输入 device(类型 `int | str | None`)。`sounddevice` input device, default if `None`.
output_device默认default Noneint | str | None输出 device(类型 `int | str | None`)。`sounddevice` output device, default if `None`.
chunk_ms默认default 100int分块 ms(类型 `int`)。Capture chunk length handed to :meth:`incoming`.
fade_ms默认default 30intfade ms(类型 `int`)。Fade-out applied by :meth:`clear_audio` to avoid a click.
源码Source agentscope/realtime/_transport/_local.py:24–68

方法详情Method Detail

start

async def start() -> None
async

返回启动。

Open both streams.

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

close

async def close() -> None
async

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

Stop both streams and end :meth:incoming.

返回Returns None
无返回值。No value is returned.
源码Source agentscope/realtime/_transport/_local.py:100–114

incoming

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

返回 incoming 结果。

Yield captured chunks until :meth:close.

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

send_audio

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

发送音频。

Queue assistant audio.

参数Parameters
名称Name类型Type说明Description
pcmbytespcm(类型 `bytes`)。The pcm.
item_idstr条目标识(类型 `str`)。The item id.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/realtime/_transport/_local.py:154–162

clear_audio

async def clear_audio() -> PlayoutPosition
async

清空音频。

Fade the head of the queue out, drop the rest, report the cut.

返回Returns PlayoutPosition
返回PlayoutPosition。Returns playout position.
源码Source agentscope/realtime/_transport/_local.py:186–196

playout

def playout() -> PlayoutPosition

返回 playout 结果。

The current playback position.

返回Returns PlayoutPosition
返回PlayoutPosition。Returns playout position.
源码Source agentscope/realtime/_transport/_local.py:198–201

继承成员Inherited Members

基于官方固定版本源码静态生成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.