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

DashScopeCosyVoiceTTSModel

class DashScopeCosyVoiceTTSModel(TTSModelBase)
源码Source agentscope/tts/_dashscope/_cosyvoice_model.py:30–397

DashScope Cosy 语音 TTS 模型,处理低延迟的实时语音与多模态交互。位于 agentscope.tts 包,继承自 TTSModelBase。核心成员包括 list_models、synthesize、connect、close、push。

DashScope CosyVoice TTS model using the WebSocket SpeechSynthesizer. Declared in agentscope.tts. Extends TTSModelBase.

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
Parameters类class
参数,处理低延迟的实时语音与多模态交互。
Frontend-exposed parameters for DashScope CosyVoice TTS models.

构造器摘要Constructor Summary

构造器Constructor说明Description
def __init__(credential: DashScopeCredential, model: str = 'cosyvoice-v3-flash', parameters: 'DashScopeCosyVoiceTTSMode…
初始化 `DashScopeCosyVoiceTTSModel` 实例。
Initialize the DashScope CosyVoice TTS model.

属性摘要Attribute Summary

属性Attribute类型Type说明Description值Value
typeLiteral['dashscope_cosyvoice_tts']
类型字段。
'dashscope_cosyvoice_tts'

方法摘要Method Summary

方法Method说明Description
def list_models(custom_yaml_dir: str | None = None) -> list[TTSModelCard]
列出模型。
List CosyVoice model cards from the dedicated card directory.
async def synthesize(text: str | None = None, **kwargs: Any) -> TTSResponse | AsyncGenerator[TTSResponse, None]async
执行 `synthesize` 方法。
Call the DashScope CosyVoice TTS API to synthesize speech.
async def connect() -> Noneasync
用于实时模式的初始化 SpeechSynthesizer。
Initialize the SpeechSynthesizer for realtime mode.
async def close() -> Noneasync
关闭连接并释放相关资源。
Close the realtime SpeechSynthesizer.
async def push(text: str, **kwargs: Any) -> TTSResponseasync
执行推送相关操作。
Push an incremental text delta for realtime synthesis.

构造器详情Constructor Detail

DashScopeCosyVoiceTTSModel

def __init__(credential: DashScopeCredential, model: str = 'cosyvoice-v3-flash', parameters: 'DashScopeCosyVoiceTTSModel.Parameters | None' = None, stream: bool = True, cold_start_length: int | None = None, cold_start_words: int | None = None, max_retries: int = 3, retry_delay: float = 5.0) -> None

初始化 DashScopeCosyVoiceTTSModel 实例。

Initialize the DashScope CosyVoice TTS model.

参数Parameters
名称Name类型Type说明Description
credentialDashScopeCredential凭证对象(类型 `DashScopeCredential`)。The DashScope credential used to authenticate the API call.
model默认default 'cosyvoice-v3-flash'strCosyVoice 模型名称。The CosyVoice model name.
parameters默认default None'DashScopeCosyVoiceTTSModel.Parameters | None'参数(类型 `'DashScopeCosyVoiceTTSModel.Parameters | None'`)。The TTS parameters. When `None`, the default voice is used.
stream默认default Truebool流(类型 `bool`)。Whether :meth:`synthesize` returns an async generator yielding `TTSResponse` chunks. When `False`, audio is aggregated.
cold_start_length默认default Noneint | Nonecold 启动长度(类型 `int | None`)。Minimum character count before the first realtime text chunk is sent to the synthesizer.
cold_start_words默认default Noneint | Nonecold 启动 words(类型 `int | None`)。Minimum word count before the first realtime text chunk is sent.
max_retries默认default 3int最大重试次数(类型 `int`)。Max retry attempts on realtime synthesis failure.
retry_delay默认default 5.0float重试延迟(类型 `float`)。Initial retry delay in seconds (exponential backoff).
源码Source agentscope/tts/_dashscope/_cosyvoice_model.py:52–104

属性详情Attribute Detail

type

Literal['dashscope_cosyvoice_tts'] = 'dashscope_cosyvoice_tts'

类型字段。声明为 Literal['dashscope_cosyvoice_tts']。

The type field.

源码Source agentscope/tts/_dashscope/_cosyvoice_model.py:47

方法详情Method Detail

list_models

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

列出模型。

List CosyVoice model cards from the dedicated card directory.

参数Parameters
名称Name类型Type说明Description
custom_yaml_dir默认default Nonestr | None自定义 yaml 目录(类型 `str | None`)。The custom yaml dir.
返回Returns list[TTSModelCard]
返回TTSModelCard列表。Returns a list of TTS model card.
源码Source agentscope/tts/_dashscope/_cosyvoice_model.py:107–114

synthesize

async def synthesize(text: str | None = None, **kwargs: Any) -> TTSResponse | AsyncGenerator[TTSResponse, None]
async

执行 synthesize 方法。

Call the DashScope CosyVoice TTS API to synthesize speech.

参数Parameters
名称Name类型Type说明Description
text默认default Nonestr | None文本(类型 `str | None`)。The text to be synthesized.
kwargsAny关键字参数(类型 `Any`)。The kwargs.
返回Returns TTSResponse | AsyncGenerator[TTSResponse, None]
返回TTSResponse|AsyncGenerator[TTSResponse,None]。`TTSResponse | AsyncGenerator[TTSResponse, None]`:
源码Source agentscope/tts/_dashscope/_cosyvoice_model.py:116–139

connect

async def connect() -> None
async

用于实时模式的初始化 SpeechSynthesizer。

Initialize the SpeechSynthesizer for realtime mode.

返回Returns None
无返回值。No value is returned.
源码Source agentscope/tts/_dashscope/_cosyvoice_model.py:187–194

close

async def close() -> None
async

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

Close the realtime SpeechSynthesizer.

返回Returns None
无返回值。No value is returned.
源码Source agentscope/tts/_dashscope/_cosyvoice_model.py:196–205

push

async def push(text: str, **kwargs: Any) -> TTSResponse
async

执行推送相关操作。

Push an incremental text delta for realtime synthesis.

参数Parameters
名称Name类型Type说明Description
textstr文本(类型 `str`)。The text.
kwargsAny关键字参数(类型 `Any`)。The kwargs.
返回Returns TTSResponse
返回TTSResponse。Returns TTS response.
源码Source agentscope/tts/_dashscope/_cosyvoice_model.py:219–261

嵌套类详情Nested Class Detail

Parameters

class Parameters

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

Frontend-exposed parameters for DashScope CosyVoice TTS models. Declared in agentscope.tts.

继承成员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.