agentscope.ttsDashScopeCosyVoiceTTSModel
class DashScopeCosyVoiceTTSModel(TTSModelBase)
agentscope/tts/_dashscope/_cosyvoice_model.py:30–397DashScope 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 |
|---|---|---|---|
type | Literal['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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
credential | DashScopeCredential | 凭证对象(类型 `DashScopeCredential`)。The DashScope credential used to authenticate the API call. |
model默认default 'cosyvoice-v3-flash' | str | CosyVoice 模型名称。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 True | bool | 流(类型 `bool`)。Whether :meth:`synthesize` returns an async generator yielding `TTSResponse` chunks. When `False`, audio is aggregated. |
cold_start_length默认default None | int | None | cold 启动长度(类型 `int | None`)。Minimum character count before the first realtime text chunk is sent to the synthesizer. |
cold_start_words默认default None | int | None | cold 启动 words(类型 `int | None`)。Minimum word count before the first realtime text chunk is sent. |
max_retries默认default 3 | int | 最大重试次数(类型 `int`)。Max retry attempts on realtime synthesis failure. |
retry_delay默认default 5.0 | float | 重试延迟(类型 `float`)。Initial retry delay in seconds (exponential backoff). |
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.
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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
custom_yaml_dir默认default None | str | None | 自定义 yaml 目录(类型 `str | None`)。The custom yaml dir. |
agentscope/tts/_dashscope/_cosyvoice_model.py:107–114synthesize
async def synthesize(text: str | None = None, **kwargs: Any) -> TTSResponse | AsyncGenerator[TTSResponse, None]
执行 synthesize 方法。
Call the DashScope CosyVoice TTS API to synthesize speech.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
text默认default None | str | None | 文本(类型 `str | None`)。The text to be synthesized. |
kwargs | Any | 关键字参数(类型 `Any`)。The kwargs. |
agentscope/tts/_dashscope/_cosyvoice_model.py:116–139connect
async def connect() -> None
用于实时模式的初始化 SpeechSynthesizer。
Initialize the SpeechSynthesizer for realtime mode.
agentscope/tts/_dashscope/_cosyvoice_model.py:187–194close
async def close() -> None
关闭连接并释放相关资源。
Close the realtime SpeechSynthesizer.
agentscope/tts/_dashscope/_cosyvoice_model.py:196–205push
async def push(text: str, **kwargs: Any) -> TTSResponse
执行推送相关操作。
Push an incremental text delta for realtime synthesis.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
text | str | 文本(类型 `str`)。The text. |
kwargs | Any | 关键字参数(类型 `Any`)。The kwargs. |
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.