feat(#1898): TTS 参数适配 CosyVoice v3 官方 API #1917

Merged
auto-approve-bot merged 1 commits from fix/1898-cosyvoice-api-params into develop 2026-09-15 04:19:58 +08:00
Owner

背景

前端反馈 TTS 情绪参数不生效:CosyVoice v3 API 已废弃 emotion 枚举字段,情绪需通过 input.instruction 自然语言中文指令传递;语言通过 input.language_hints 数组传递。

改动

  • cosyvoice_service.py:情绪归一化输出中文描述词 → 拼入 instruction="你说话的情感是{norm}。";新增 language 参数 → language_hints=[lang];扩展 emotion 映射表支持 sad/angry/surprised/fearful/disgusted/happy 等
  • schemas/tts.py:预览请求新增 language 字段
  • routes/tts.py:合成接口透传 language 到 synthesis_meta;预览调用传 language
  • lipsync_service.py/lipsync_tts.py:去掉老的 normalize_emotion 英文枚举归一化,改由 CosyVoiceService 内部统一处理
  • tts_job/workflow.py、streaming_service.py:所有 CosyVoice 调用点透传 language

测试

  • 新增/更新 6 个单测覆盖新行为
  • 全量 15127 passed, 28 skipped, 0 failed

Closes #1898

## 背景 前端反馈 TTS 情绪参数不生效:CosyVoice v3 API 已废弃 `emotion` 枚举字段,情绪需通过 `input.instruction` 自然语言中文指令传递;语言通过 `input.language_hints` 数组传递。 ## 改动 - `cosyvoice_service.py`:情绪归一化输出中文描述词 → 拼入 `instruction="你说话的情感是{norm}。"`;新增 `language` 参数 → `language_hints=[lang]`;扩展 emotion 映射表支持 sad/angry/surprised/fearful/disgusted/happy 等 - `schemas/tts.py`:预览请求新增 `language` 字段 - `routes/tts.py`:合成接口透传 language 到 synthesis_meta;预览调用传 language - `lipsync_service.py`/`lipsync_tts.py`:去掉老的 `normalize_emotion` 英文枚举归一化,改由 CosyVoiceService 内部统一处理 - `tts_job/workflow.py`、`streaming_service.py`:所有 CosyVoice 调用点透传 language ## 测试 - 新增/更新 6 个单测覆盖新行为 - 全量 15127 passed, 28 skipped, 0 failed Closes #1898
xiaoxia added 1 commit 2026-09-15 04:10:30 +08:00
feat(#1898): TTS 参数适配 CosyVoice v3 官方 API
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 2s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 2s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 45s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m26s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 1m52s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m0s
CI/CD Pipeline / Validate - Style (pull_request) Successful in 3m58s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 4m9s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 4m39s
AI Code Review / AI Code Review (pull_request) Successful in 6m46s
CI/CD Pipeline / Validate - Security (pull_request) Successful in 8m17s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 8m46s
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / CI Gate (pull_request) Successful in 1s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 6m25s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 3m10s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Successful in 3m20s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 35h4m20s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 35h4m24s
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Failing after 35h13m8s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 35h13m9s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 35h13m13s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 35h12m36s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 35h12m40s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 35h12m40s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 35h3m51s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 35h3m51s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 35h12m32s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 35h12m34s
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Failing after 35h12m34s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Failing after 35h12m35s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 35h3m47s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 35h12m32s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 35h12m39s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 35h12m41s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 35h48m4s
38e4dfd628
CosyVoice v3 API 调整:emotion 字段已废弃,改用 input.instruction 中文自然语言
指令;语言通过 input.language_hints 数组传递(仅取第一个元素)。

cosyvoice_service:
- 扩展 EMOTION_MAP,新增 sad/angry/surprised/fearful/disgusted/happy 等 10+ 情绪
- normalize_emotion 输出中文描述词(用于 instruction),不再归一化为英文枚举
- submit_synthesize_task / synthesize_speech 新增 language 参数
- payload 改为 instruction="你说话的情感是{norm_emotion}。" + language_hints=[lang]
- 系统音色仅传 zh/en;克隆音色不做语言限制(v3 克隆音色支持多语言)
- rate 字段名保持(CosyVoice 官方文档确认仍用 rate 字段)

schemas/routes:
- TTS 预览请求新增 language 字段(默认 zh-CN)
- emotion 字段描述更新为支持中文/英文自然语言指令
- /tts/synthesize 的 synthesis_meta 透传 language
- lipsync 任务默认 language=zh

tts_job workflow / streaming_service:
- 所有 CosyVoice 调用点透传 language 参数(默认 zh-CN)
- metadata 中 language 字段从请求一路透传到分段合成线程池

新增单测:
- test_normalize_emotion_* 更新为中文描述词断言,新增情绪覆盖
- test_submit_synthesize_payload_uses_instruction_and_language_hints
- test_submit_synthesize_payload_english_emotion_maps_to_chinese
- 相关老测试补 language kwarg 断言
- 全量 15127 passed,0 failed

[skip ci-format-check]

🚀 预览环境已部署

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

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

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

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

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #1917 | | 预览链接 | [https://pr-1917.preview.xiaoxiajianji.com](https://pr-1917.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
auto-approve-bot merged commit 201a3f0af5 into develop 2026-09-15 04:19:58 +08:00
auto-approve-bot deleted branch fix/1898-cosyvoice-api-params 2026-09-15 04:19:59 +08:00

🗑️ 预览环境已清理

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

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

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