修复克隆音色情绪参数未传递问题 #1822

Open
opened 2026-09-09 16:49:33 +08:00 by xiaoxia · 0 comments
Owner

问题描述

前端 AI 数字人页面有情绪选择(自然/兴奋/沉稳/亲切),但克隆音色生成配音时情绪参数没有传到 CosyVoice API,导致情绪选择无效。

根因

packages/application/cosyvoice_service.pysynthesize_speech() 方法没有接收和传递 emotion 参数。

修改内容

1. synthesize_speech() 方法加 emotion 参数

def synthesize_speech(
    self,
    text: str,
    voice_id: str = "",
    sample_rate: int = 0,
    format: str = "",
    speed: float = 1.0,
    volume: int = 50,
    emotion: str = "",  # 新增:情绪参数
    timeout: float = 120.0,
) -> SynthesizeResult:

2. 在 payload 里传递 emotion

payload = {
    "model": self._model,
    "input": {
        "text": text,
        "voice": voice_id,
        "format": format or settings.cosyvoice_format,
        "sample_rate": sample_rate or settings.cosyvoice_sample_rate,
        "rate": speed,
        "volume": volume,
        "emotion": emotion,  # 新增
    },
}

3. 同步修改 submit_synthesize_task() 方法

同样加 emotion 参数并传递到 payload。

CosyVoice 支持的情绪值

  • natural(自然)
  • excited(兴奋)
  • calm(沉稳)
  • friendly(亲切)

前端对接

前端需要把选择的情绪值映射到英文传给后端:

  • 自然 → natural
  • 兴奋 → excited
  • 沉稳 → calm
  • 亲切 → friendly

交付物

  • 修改后的 cosyvoice_service.py
  • 说明情绪参数如何从前端传到后端
## 问题描述 前端 AI 数字人页面有情绪选择(自然/兴奋/沉稳/亲切),但克隆音色生成配音时情绪参数没有传到 CosyVoice API,导致情绪选择无效。 ## 根因 `packages/application/cosyvoice_service.py` 的 `synthesize_speech()` 方法没有接收和传递 `emotion` 参数。 ## 修改内容 ### 1. synthesize_speech() 方法加 emotion 参数 ```python def synthesize_speech( self, text: str, voice_id: str = "", sample_rate: int = 0, format: str = "", speed: float = 1.0, volume: int = 50, emotion: str = "", # 新增:情绪参数 timeout: float = 120.0, ) -> SynthesizeResult: ``` ### 2. 在 payload 里传递 emotion ```python payload = { "model": self._model, "input": { "text": text, "voice": voice_id, "format": format or settings.cosyvoice_format, "sample_rate": sample_rate or settings.cosyvoice_sample_rate, "rate": speed, "volume": volume, "emotion": emotion, # 新增 }, } ``` ### 3. 同步修改 submit_synthesize_task() 方法 同样加 `emotion` 参数并传递到 payload。 ## CosyVoice 支持的情绪值 - `natural`(自然) - `excited`(兴奋) - `calm`(沉稳) - `friendly`(亲切) ## 前端对接 前端需要把选择的情绪值映射到英文传给后端: - 自然 → `natural` - 兴奋 → `excited` - 沉稳 → `calm` - 亲切 → `friendly` ## 交付物 - 修改后的 cosyvoice_service.py - 说明情绪参数如何从前端传到后端
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: xiaoxia/xiaoxia-saas#1822