fix(#1898): TTS 情绪映射修正为 CosyVoice v3 官方英文枚举(P1 更正) #1933

Merged
xiaoxia merged 1 commits from fix/p1-tts-emotion-enum into develop 2026-09-15 15:08:55 +08:00
Owner

背景

之前 PR#1932 错误地将 normalize_emotion 映射到中文描述词(如"开心愉快""悲伤难过"),但对照阿里云百炼官方文档(https://help.aliyun.com/zh/model-studio/cosyvoice-voice-list)确认:

  • CosyVoice v3 instruction 格式严格为 你说话的情感是<情感值>。(结尾中文句号不可省略)
  • 情感值必须是 7 种英文枚举之一:neutral/happy/sad/angry/surprised/fearful/disgusted
  • 官方示例:"你说话的情感是neutral。"

改动

  • packages/application/cosyvoice_service.py
    • EMOTION_MAP value 改为英文枚举自身(不再是中文描述词)
    • 新增前端中文 7 标签(中立/开心/难过/生气/惊讶/恐惧/厌恶)→ 英文枚举
    • 旧英文 4 枚举归并到最接近的标准值:natural→neutral, excited→happy, calm→neutral, friendly→happy
    • 常见中文别名(自然/愉快/高兴/快乐/兴奋/悲伤/愤怒/惊奇/害怕/讨厌)也正确映射
    • normalize_emotion:空串/None/纯空白返回空(调用方不传 instruction 走默认自然);未知值默认 neutral(不返回空,保证合成不中断,打 warning 日志)
    • instruction 拼接注释更新为官方格式说明
  • apps/api/app/schemas/lipsync.py、routes/voice_clones.py:description 更新,preview 白名单加入中文 7 标签和常见别名

测试

  • tests/unit/test_cosyvoice_emotion.py(重写,89 用例)
    • 7 英文枚举参数化:映射到自身、大小写不敏感、strip 前后空白
    • 前端中文 7 标签 → 正确英文枚举
    • 中文别名、旧英文 4 枚举 → 正确归并
    • 空/None/空白 → 空串;未知值 → neutral + warning
    • instruction 格式严格断言:前缀"你说话的情感是"、结尾单中文句号、中间是纯 ASCII 英文枚举、对照官方示例格式
  • tests/unit/test_ai_avatar_emotion_tts_lipsync.py:修正旧断言为英文枚举值,新增中文标签/未知值断言
  • tests/unit/test_voice_clone_preview.py:非法 emotion 用例保留

验证

  • 本地:15333 passed, 28 skipped
  • ruff/black 全过

关联

## 背景 之前 PR#1932 错误地将 normalize_emotion 映射到中文描述词(如"开心愉快""悲伤难过"),但对照阿里云百炼官方文档(https://help.aliyun.com/zh/model-studio/cosyvoice-voice-list)确认: - CosyVoice v3 instruction 格式严格为 `你说话的情感是<情感值>。`(结尾中文句号不可省略) - **情感值必须是 7 种英文枚举之一**:`neutral`/`happy`/`sad`/`angry`/`surprised`/`fearful`/`disgusted` - 官方示例:"你说话的情感是neutral。" ## 改动 - `packages/application/cosyvoice_service.py` - EMOTION_MAP value 改为英文枚举自身(不再是中文描述词) - 新增前端中文 7 标签(中立/开心/难过/生气/惊讶/恐惧/厌恶)→ 英文枚举 - 旧英文 4 枚举归并到最接近的标准值:natural→neutral, excited→happy, calm→neutral, friendly→happy - 常见中文别名(自然/愉快/高兴/快乐/兴奋/悲伤/愤怒/惊奇/害怕/讨厌)也正确映射 - normalize_emotion:空串/None/纯空白返回空(调用方不传 instruction 走默认自然);**未知值默认 neutral**(不返回空,保证合成不中断,打 warning 日志) - instruction 拼接注释更新为官方格式说明 - `apps/api/app/schemas/lipsync.py`、`routes/voice_clones.py`:description 更新,preview 白名单加入中文 7 标签和常见别名 ## 测试 - `tests/unit/test_cosyvoice_emotion.py`(重写,89 用例) - 7 英文枚举参数化:映射到自身、大小写不敏感、strip 前后空白 - 前端中文 7 标签 → 正确英文枚举 - 中文别名、旧英文 4 枚举 → 正确归并 - 空/None/空白 → 空串;未知值 → neutral + warning - **instruction 格式严格断言**:前缀"你说话的情感是"、结尾单中文句号、中间是纯 ASCII 英文枚举、对照官方示例格式 - `tests/unit/test_ai_avatar_emotion_tts_lipsync.py`:修正旧断言为英文枚举值,新增中文标签/未知值断言 - `tests/unit/test_voice_clone_preview.py`:非法 emotion 用例保留 ## 验证 - 本地:**15333 passed, 28 skipped** - ruff/black 全过 ## 关联 - 修正 PR#1932 的映射方向错误 - 修复 #1898
xiaoxia added 1 commit 2026-09-15 14:23:41 +08:00
fix(#1898): TTS 情绪映射修正为 CosyVoice v3 官方英文枚举(P1 更正)
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 2s
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 4s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 45s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 45s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m40s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 3m12s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m10s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 3m52s
CI/CD Pipeline / Validate - Style (pull_request) Successful in 5m51s
AI Code Review / AI Code Review (pull_request) Successful in 6m48s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 10m36s
CI/CD Pipeline / Validate - Security (pull_request) Successful in 12m36s
CI/CD Pipeline / CI Gate (pull_request) Successful in 0s
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 11m6s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Successful in 18s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 39s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 24h47m16s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 24h59m6s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 24h59m50s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 24h59m52s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 24h59m12s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 24h46m40s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 24h58m27s
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Failing after 24h58m27s
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Failing after 24h58m27s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Failing after 24h58m27s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 24h59m10s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 24h59m11s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 24h59m22s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 24h58m27s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 24h46m37s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 24h46m40s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 24h46m40s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 24h58m27s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 24h59m13s
74200949b9
关键修复(对照阿里云百炼官方文档 https://help.aliyun.com/zh/model-studio/cosyvoice-voice-list):
- instruction 格式严格为 "你说话的情感是<情感值>。",结尾中文句号不可省略
- 情感值必须是 7 种英文枚举之一:neutral/happy/sad/angry/surprised/fearful/disgusted
- 之前 PR#1932 错误地映射成了中文描述词(如"开心愉快"),本次修正为英文枚举

改动:
- EMOTION_MAP value 从中文描述词改为英文枚举自身;新增前端中文 7 标签(中立/开心/难过/生气/惊讶/恐惧/厌恶)→英文枚举;旧英文 4 枚举归并到最接近的标准值(natural→neutral, excited/friendly→happy, calm→neutral)
- normalize_emotion 未知值默认 neutral(不返回空,保证合成不中断),仅空串/None/纯空白返回空(调用方不传 instruction 走默认自然)
- schemas/router 描述更新,voice_clones preview 白名单加入中文 7 标签
- 单测重写:89 个用例断言 instruction 情感值为纯英文 ASCII 枚举;修正旧测试中的中文描述词断言为英文枚举;未知值断言改为默认 neutral

验证:
- 15333 passed, 28 skipped(覆盖 7 英文枚举、中文 7 标签、中文别名、旧英文、大小写、空白、未知值、instruction 格式、白名单)
- ruff/black 全过

🚀 预览环境已部署

项目 详情
PR号 #1933
预览链接 https://pr-1933.preview.xiaoxiajianji.com
API环境 staging

💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。

🔄 每次提交新代码后预览环境会自动更新。

🗑️ PR 关闭或合并后,预览环境会自动清理。

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #1933 | | 预览链接 | [https://pr-1933.preview.xiaoxiajianji.com](https://pr-1933.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
xiaoxia reviewed 2026-09-15 15:05:41 +08:00
xiaoxia left a comment
Author
Owner

CI green, verified instruction format against CosyVoice v3 official docs (emotion values must be English enums: neutral/happy/sad/angry/surprised/fearful/disgusted)

CI green, verified instruction format against CosyVoice v3 official docs (emotion values must be English enums: neutral/happy/sad/angry/surprised/fearful/disgusted)
xiaoxia reviewed 2026-09-15 15:05:56 +08:00
xiaoxia left a comment
Author
Owner

CI green, fixes emotion mapping to official English enums

CI green, fixes emotion mapping to official English enums
xiaoxia merged commit 81180d16e5 into develop 2026-09-15 15:08:55 +08:00

🗑️ 预览环境已清理

PR #1933 已关闭或合并,对应的预览环境已被清理。

如有需要,可以重新打开 PR 来重新生成预览环境。

🗑️ **预览环境已清理** PR #1933 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Sign in to join this conversation.