agentscope.asrASRModelBase
class ASRModelBase(ABC)
agentscope/asr/_asr_base.py:19–239ASR 模型基类,处理低延迟的实时语音与多模态交互。位于 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 |
|---|---|---|---|
credential | CredentialBase | 凭证字段。 | — |
model | str | 模型字段。 | — |
parameters | BaseModel | 参数字段。 | — |
realtime | bool | 实时字段。 | 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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
credential | CredentialBase | 凭证对象(类型 `CredentialBase`)。The credential used to authenticate with the provider. |
model | str | 提供者模型名称。The provider model name. |
parameters默认default None | BaseModel | None | 参数(类型 `BaseModel | None`)。Provider-specific parameters. When omitted, an instance of :attr:`Parameters` is created. |
agentscope/asr/_asr_base.py:51–70属性详情Attribute Detail
credential
CredentialBase凭证字段。声明为 CredentialBase。
The credential field.
agentscope/asr/_asr_base.py:39model
str模型字段。声明为 str。
The model field.
agentscope/asr/_asr_base.py:42parameters
BaseModel参数字段。声明为 BaseModel。
The parameters field.
agentscope/asr/_asr_base.py:45realtime
bool = False实时字段。声明为 bool。
The realtime field.
agentscope/asr/_asr_base.py:48方法详情Method Detail
__aenter__
async def __aenter__() -> 'ASRModelBase'
进入异步上下文并返回自身。
Realtime models establish their provider connection by calling :meth:connect.
agentscope/asr/_asr_base.py:72–84__aexit__
async def __aexit__(exc_type: Any, exc_value: Any, traceback: Any) -> None
退出异步上下文并清理资源。
Realtime models close their provider connection by calling :meth:close, including when the context exits with an exception.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
exc_type | Any | exc 类型(类型 `Any`)。The type of the exception that caused the context to exit, or `None` for a normal exit. |
exc_value | Any | exc 值(类型 `Any`)。The exception instance, or `None` for a normal exit. |
traceback | Any | traceback(类型 `Any`)。The exception traceback, or `None` for a normal exit. |
agentscope/asr/_asr_base.py:86–108connect
async def connect() -> None
建立连接并完成初始化。
Realtime implementations must override this method and prepare any provider resources needed by :meth:push and :meth:transcribe.
agentscope/asr/_asr_base.py:110–118close
async def close() -> None
关闭连接并释放相关资源。
Realtime implementations must override this method and release any resources created by :meth:connect.
agentscope/asr/_asr_base.py:120–127push
async def push(audio: bytes, **kwargs: Any) -> ASRResponse
执行推送相关操作。
Realtime implementations must override this method.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
audio | bytes | 音频(类型 `bytes`)。An incremental audio chunk in the format expected by the provider. |
kwargs | Any | 关键字参数(类型 `Any`)。The kwargs. |
RuntimeError可能抛出 `RuntimeError`。If this model does not support realtime audio input.
agentscope/asr/_asr_base.py:129–158list_models
def list_models(custom_yaml_dir: str | None = None) -> list['ASRModelCard']
列出模型。
Cards whose realtime value differs from the implementation are excluded.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
custom_yaml_dir默认default None | str | None | 自定义 yaml 目录(类型 `str | None`)。Directory containing model-card YAML files. When omitted, the `_models` directory beside the concrete implementation is used. |
agentscope/asr/_asr_base.py:161–206transcribe
async def transcribe(audio: bytes | None = None, filename: str = 'audio.wav', **kwargs: Any) -> ASRResponse
执行 transcribe 方法。
Batch subclasses require complete audio.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
audio默认default None | bytes | 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' | str | filename(类型 `str`)。Filename metadata used by multipart batch APIs to identify the in-memory audio format. |
kwargs | Any | 关键字参数(类型 `Any`)。The kwargs. |
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.