类class
agentscope.realtimeLocalAudioTransport
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 16000 | int | 输入 sample 速率(类型 `int`)。Capture rate; should match the model's input rate. |
output_sample_rate默认default 24000 | int | 输出 sample 速率(类型 `int`)。Playback rate; should match the model's output rate. |
input_device默认default None | int | str | None | 输入 device(类型 `int | str | None`)。`sounddevice` input device, default if `None`. |
output_device默认default None | int | str | None | 输出 device(类型 `int | str | None`)。`sounddevice` output device, default if `None`. |
chunk_ms默认default 100 | int | 分块 ms(类型 `int`)。Capture chunk length handed to :meth:`incoming`. |
fade_ms默认default 30 | int | fade 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.
None
无返回值。No value is returned.
源码Source
agentscope/realtime/_transport/_local.py:74–98close
async def close() -> None
async
关闭连接并释放相关资源。
Stop both streams and end :meth:incoming.
None
无返回值。No value is returned.
源码Source
agentscope/realtime/_transport/_local.py:100–114incoming
async def incoming() -> AsyncIterator[TransportFrame]
async
返回 incoming 结果。
Yield captured chunks until :meth:close.
AsyncIterator[TransportFrame]
以异步流的形式返回TransportFrame。Returns a stream of transport frame.
源码Source
agentscope/realtime/_transport/_local.py:120–126send_audio
async def send_audio(pcm: bytes, item_id: str) -> None
async
发送音频。
Queue assistant audio.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
pcm | bytes | pcm(类型 `bytes`)。The pcm. |
item_id | str | 条目标识(类型 `str`)。The item id. |
None
无返回值。No value is returned.
源码Source
agentscope/realtime/_transport/_local.py:154–162clear_audio
async def clear_audio() -> PlayoutPosition
async
清空音频。
Fade the head of the queue out, drop the rest, report the cut.
PlayoutPosition
返回PlayoutPosition。Returns playout position.
源码Source
agentscope/realtime/_transport/_local.py:186–196playout
def playout() -> PlayoutPosition
返回 playout 结果。
The current playback position.
PlayoutPosition
返回PlayoutPosition。Returns playout position.
源码Source
agentscope/realtime/_transport/_local.py:198–201