fix(backend): #1897 声音克隆preview接口支持情绪语速参数 #1907

Merged
auto-approve-bot merged 1 commits from fix/1897-voice-clone-preview-emotion-speed-backend into develop 2026-09-14 18:56:53 +08:00
Owner

背景

Issue #1897:声音克隆页增加情绪/语速设置。前端加控件后会传 emotion 和 speed 到 preview 接口,后端需接收并透传。

参考已有 TTS preview 接口(POST /tts/preview)的实现:apps/api/app/api/routes/tts.py 已正确接收 speed/emotion 并透传到 cosyvoice.synthesize_speech。CosyVoice 服务层 synthesize_speech 已原生支持 speed/emotion 参数,无需修改。

改动

  • apps/api/app/api/routes/voice_clones.py:GET /voice-clones/{clone_id}/preview 新增两个 query 参数
    • speed: float = 1.0,ge=0.5, le=2.0(FastAPI 自动校验越界返回 422)
    • emotion: str = "",白名单校验 natural/excited/calm/friendly/空字符串,非法返回 400
    • 透传至 cosyvoice.synthesize_speech(text=..., voice_id=..., format="mp3", speed=speed, emotion=emotion)
    • 缓存策略:仅默认参数(默认试听文本 + speed=1.0 + emotion 空)走缓存;自定义 speed/emotion 实时合成不缓存
    • 新增 except ValueError 返回 400(与 TTS preview 一致,speed 越界等参数错误 cosyvoice 抛 ValueError)
  • language 参数不接受(克隆音色语言由训练时确定,合成时不切换,按工单要求不加)
  • 其他逻辑(音频格式 mp3、返回方式、就绪态检查、权限校验)保持不变

测试

  • tests/unit/test_voice_clone_preview.py:_call_preview helper 扩展支持 speed/emotion 参数
  • 新增 4 个测试用例:
    • test_preview_custom_speed_emotion_passed_through:speed/emotion 正确透传到 cosyvoice
    • test_preview_invalid_emotion_rejected:非法 emotion 返回 400
    • test_preview_non_default_speed_no_cache:自定义 speed/emotion 不走缓存
    • test_preview_valueerror_from_cosyvoice_returns_400:cosyvoice 抛 ValueError 返回 400
  • 现有 10 个测试保持通过;voice_clone + cosyvoice 相关共 293 个测试全通过

Refs: #1897

## 背景 Issue #1897:声音克隆页增加情绪/语速设置。前端加控件后会传 emotion 和 speed 到 preview 接口,后端需接收并透传。 参考已有 TTS preview 接口(POST /tts/preview)的实现:apps/api/app/api/routes/tts.py 已正确接收 speed/emotion 并透传到 cosyvoice.synthesize_speech。CosyVoice 服务层 synthesize_speech 已原生支持 speed/emotion 参数,无需修改。 ## 改动 - `apps/api/app/api/routes/voice_clones.py`:GET /voice-clones/{clone_id}/preview 新增两个 query 参数 - `speed: float = 1.0`,ge=0.5, le=2.0(FastAPI 自动校验越界返回 422) - `emotion: str = ""`,白名单校验 natural/excited/calm/friendly/空字符串,非法返回 400 - 透传至 `cosyvoice.synthesize_speech(text=..., voice_id=..., format="mp3", speed=speed, emotion=emotion)` - 缓存策略:仅默认参数(默认试听文本 + speed=1.0 + emotion 空)走缓存;自定义 speed/emotion 实时合成不缓存 - 新增 `except ValueError` 返回 400(与 TTS preview 一致,speed 越界等参数错误 cosyvoice 抛 ValueError) - language 参数不接受(克隆音色语言由训练时确定,合成时不切换,按工单要求不加) - 其他逻辑(音频格式 mp3、返回方式、就绪态检查、权限校验)保持不变 ## 测试 - tests/unit/test_voice_clone_preview.py:_call_preview helper 扩展支持 speed/emotion 参数 - 新增 4 个测试用例: - test_preview_custom_speed_emotion_passed_through:speed/emotion 正确透传到 cosyvoice - test_preview_invalid_emotion_rejected:非法 emotion 返回 400 - test_preview_non_default_speed_no_cache:自定义 speed/emotion 不走缓存 - test_preview_valueerror_from_cosyvoice_returns_400:cosyvoice 抛 ValueError 返回 400 - 现有 10 个测试保持通过;voice_clone + cosyvoice 相关共 293 个测试全通过 Refs: #1897
xiaoxia added 1 commit 2026-09-14 18:49:26 +08:00
fix(backend): #1897 声音克隆preview接口支持情绪语速参数
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 0s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 1s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 40s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m5s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 1m29s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m30s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m40s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 2m50s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 2m50s
CI/CD Pipeline / Validate - Style (pull_request) Successful in 3m5s
AI Code Review / AI Code Review (pull_request) Successful in 6m15s
CI/CD Pipeline / Validate - Security (pull_request) Successful in 6m41s
CI/CD Pipeline / CI Gate (pull_request) Successful in 1s
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 4m33s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Successful in 11s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 20s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 44h27m33s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 44h34m15s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 44h34m17s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 44h33m48s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 44h27m5s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 44h33m29s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 44h33m48s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 44h33m52s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 44h27m4s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 44h27m5s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 44h27m5s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 44h33m29s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 44h33m32s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 44h33m38s
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Failing after 44h33m41s
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Failing after 44h33m41s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Failing after 44h33m43s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 44h33m49s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 44h33m49s
ef54a1ce9c
- apps/api/app/api/routes/voice_clones.py: GET /voice-clones/{clone_id}/preview 新增 speed(float, 0.5-2.0, 默认1.0) 和 emotion(str, 默认空, 枚举 natural/excited/calm/friendly) query 参数
- 参数透传到 cosyvoice.synthesize_speech(speed=..., emotion=...),CosyVoice 服务层已原生支持无需改动
- emotion 白名单校验:不在 natural/excited/calm/friendly/空 范围返回 400
- 缓存仅在默认参数(默认试听文本+speed=1.0+emotion空)时生效,自定义 speed/emotion 不缓存
- 新增 ValueError 异常处理(speed 越界等参数问题 cosyvoice 抛 ValueError),返回 400(与 TTS preview 接口一致)
- 参考 TTS preview 接口(apps/api/app/api/routes/tts.py)的参数接收与透传方式
- 单测:4 个新用例覆盖 speed/emotion 透传、非法 emotion 400、非默认参数不缓存、ValueError→400,293个voice clone/cosyvoice相关测试全通过

🚀 预览环境已部署

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

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

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

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

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #1907 | | 预览链接 | [https://pr-1907.preview.xiaoxiajianji.com](https://pr-1907.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
auto-approve-bot merged commit 8ad44ad045 into develop 2026-09-14 18:56:53 +08:00
auto-approve-bot deleted branch fix/1897-voice-clone-preview-emotion-speed-backend 2026-09-14 18:56:53 +08:00

🗑️ 预览环境已清理

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

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

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