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

ASRModelBase

class ASRModelBase(ABC)
源码Source agentscope/asr/_asr_base.py:19–239

ASR 模型基类,处理低延迟的实时语音与多模态交互。位于 agentscope.asr 包,继承自 ABC。核心成员包括 connect、close、push、list_models、transcribe。

Batch implementations transcribe complete audio by calling :meth:transcribe directly. Realtime implementations use the asynchronous context manager, call :meth:push for each audio chunk, and finally call :meth:transcribe without audio to finalize the current transcription.

Every concrete implementation must override :meth:transcribe. Realtime implementations must additionally override :meth:connect, :meth:close, and :meth:push.

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
Parameters类class
参数,处理低延迟的实时语音与多模态交互。
Base schema for provider-specific transcription parameters.

构造器摘要Constructor Summary

构造器Constructor说明Description
def __init__(credential: CredentialBase, model: str, parameters: BaseModel | None = None) -> None
初始化 `ASRModelBase` 实例。
Initialize the ASR model.

属性摘要Attribute Summary

属性Attribute类型Type说明Description值Value
credentialCredentialBase
凭证字段。
—
modelstr
模型字段。
—
parametersBaseModel
参数字段。
—
realtimebool
实时字段。
False

方法摘要Method Summary

方法Method说明Description
async def __aenter__() -> 'ASRModelBase'async
进入异步上下文并返回自身。
Enter the model's asynchronous context.
async def __aexit__(exc_type: Any, exc_value: Any, traceback: Any) -> Noneasync
退出异步上下文并清理资源。
Exit the model's asynchronous context.
async def connect() -> Noneasync
建立连接并完成初始化。
Establish the realtime provider connection.
async def close() -> Noneasync
关闭连接并释放相关资源。
Close the realtime provider connection.
async def push(audio: bytes, **kwargs: Any) -> ASRResponseasync
执行推送相关操作。
Send an audio chunk and return currently available text.
def list_models(custom_yaml_dir: str | None = None) -> list['ASRModelCard']
列出模型。
List model cards associated with the concrete implementation.
async def transcribe(audio: bytes | None = None, filename: str = 'audio.wav', **kwargs: Any) -> ASRResponseasyncabstractabstractmethod
执行 `transcribe` 方法。
Transcribe complete audio or finalize realtime input.

构造器详情Constructor Detail

ASRModelBase

def __init__(credential: CredentialBase, model: str, parameters: BaseModel | None = None) -> None

初始化 ASRModelBase 实例。

Initialize the ASR model.

参数Parameters
名称Name类型Type说明Description
credentialCredentialBase凭证对象(类型 `CredentialBase`)。The credential used to authenticate with the provider.
modelstr提供者模型名称。The provider model name.
parameters默认default NoneBaseModel | None参数(类型 `BaseModel | None`)。Provider-specific parameters. When omitted, an instance of :attr:`Parameters` is created.
源码Source agentscope/asr/_asr_base.py:51–70

属性详情Attribute Detail

credential

CredentialBase

凭证字段。声明为 CredentialBase。

The credential field.

源码Source agentscope/asr/_asr_base.py:39

model

str

模型字段。声明为 str。

The model field.

源码Source agentscope/asr/_asr_base.py:42

parameters

BaseModel

参数字段。声明为 BaseModel。

The parameters field.

源码Source agentscope/asr/_asr_base.py:45

realtime

bool = False

实时字段。声明为 bool。

The realtime field.

源码Source agentscope/asr/_asr_base.py:48

方法详情Method Detail

__aenter__

async def __aenter__() -> 'ASRModelBase'
async

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

Realtime models establish their provider connection by calling :meth:connect.

返回Returns 'ASRModelBase'
返回'ASRModelBase'。`ASRModelBase`:
源码Source agentscope/asr/_asr_base.py:72–84

__aexit__

async def __aexit__(exc_type: Any, exc_value: Any, traceback: Any) -> None
async

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

Realtime models close their provider connection by calling :meth:close, including when the context exits with an exception.

参数Parameters
名称Name类型Type说明Description
exc_typeAnyexc 类型(类型 `Any`)。The type of the exception that caused the context to exit, or `None` for a normal exit.
exc_valueAnyexc 值(类型 `Any`)。The exception instance, or `None` for a normal exit.
tracebackAnytraceback(类型 `Any`)。The exception traceback, or `None` for a normal exit.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/asr/_asr_base.py:86–108

connect

async def connect() -> None
async

建立连接并完成初始化。

Realtime implementations must override this method and prepare any provider resources needed by :meth:push and :meth:transcribe.

返回Returns None
无返回值。No value is returned.
源码Source agentscope/asr/_asr_base.py:110–118

close

async def close() -> None
async

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

Realtime implementations must override this method and release any resources created by :meth:connect.

返回Returns None
无返回值。No value is returned.
源码Source agentscope/asr/_asr_base.py:120–127

push

async def push(audio: bytes, **kwargs: Any) -> ASRResponse
async

执行推送相关操作。

Realtime implementations must override this method.

参数Parameters
名称Name类型Type说明Description
audiobytes音频(类型 `bytes`)。An incremental audio chunk in the format expected by the provider.
kwargsAny关键字参数(类型 `Any`)。The kwargs.
返回Returns ASRResponse
返回ASRResponse。`ASRResponse`:
异常Raises
  • RuntimeError 可能抛出 `RuntimeError`。If this model does not support realtime audio input.
源码Source agentscope/asr/_asr_base.py:129–158

list_models

def list_models(custom_yaml_dir: str | None = None) -> list['ASRModelCard']

列出模型。

Cards whose realtime value differs from the implementation are excluded.

参数Parameters
名称Name类型Type说明Description
custom_yaml_dir默认default Nonestr | None自定义 yaml 目录(类型 `str | None`)。Directory containing model-card YAML files. When omitted, the `_models` directory beside the concrete implementation is used.
返回Returns list['ASRModelCard']
返回'ASRModelCard'列表。`list[ASRModelCard]`:
源码Source agentscope/asr/_asr_base.py:161–206

transcribe

async def transcribe(audio: bytes | None = None, filename: str = 'audio.wav', **kwargs: Any) -> ASRResponse
asyncabstractabstractmethod

执行 transcribe 方法。

Batch subclasses require complete audio.

参数Parameters
名称Name类型Type说明Description
audio默认default Nonebytes | None音频(类型 `bytes | None`)。Complete in-memory audio for a batch model. For a realtime model, `None` finalizes previously pushed audio; a byte string may provide one last chunk before finalization.
filename默认default 'audio.wav'strfilename(类型 `str`)。Filename metadata used by multipart batch APIs to identify the in-memory audio format.
kwargsAny关键字参数(类型 `Any`)。The kwargs.
返回Returns ASRResponse
返回ASRResponse。`ASRResponse`:
源码Source agentscope/asr/_asr_base.py:209–239

嵌套类详情Nested Class Detail

Parameters

class Parameters

参数,处理低延迟的实时语音与多模态交互。位于 agentscope.asr 包。

Concrete ASR implementations should override this class with the parameters supported by their provider.

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