Skip to content

Conversation

@lanyunziyu
Copy link

Add custom sound color feature to TTS functionality, allowing users to upload reference audio files or URLs to customize voice characteristics.

Backend changes:

  • Add customize_sound_color feature flag to TTSModelFeatures
  • Add speakers parameter support in TtsRequest for multi-speaker configuration
  • Add input_state property to VoiceProperties for UI prompts

Frontend changes:

  • Add comprehensive custom voice UI with file upload and URL input modes
  • Add fetch-audio API route for CORS-free audio URL processing
  • Support dual speaker configuration (S1/S2) with audio references
  • Add dialect prompt support for voice customization

Add custom sound color feature to TTS functionality, allowing users to
upload reference audio files or URLs to customize voice characteristics.

Backend changes:
- Add customize_sound_color feature flag to TTSModelFeatures
- Add speakers parameter support in TtsRequest for multi-speaker configuration
- Add input_state property to VoiceProperties for UI prompts

Frontend changes:
- Add comprehensive custom voice UI with file upload and URL input modes
- Add fetch-audio API route for CORS-free audio URL processing
- Support dual speaker configuration (S1/S2) with audio references
- Add dialect prompt support for voice customization

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@szl97
Copy link
Collaborator

szl97 commented Feb 4, 2026

@claude 检查提交的代码,使用中文回复

@szl97
Copy link
Collaborator

szl97 commented Feb 4, 2026

Claude finished @szl97's task —— View job


代码审查进度

正在检查提交的代码,以下是审查任务列表:

  • 分析后端 Java 文件变更(TTSModelFeatures.java)
  • 审查 TtsRequest.java 的新增参数支持
  • 检查 VoiceProperties.java 的属性扩展
  • 审查新增的 fetch-audio API 路由实现
  • 检查前端 speech 页面的大量变更和新功能
  • 总结审查结果并提供改进建议

代码审查结果

1. 后端 Java 代码变更

TTSModelFeatures.java ✅ 良好

  • 新增 customize_sound_color 特性标志,实现简洁
  • 描述信息使用中文,便于理解

TtsRequest.java ✅ 良好

  • 新增 speakers 参数支持多说话人配置
  • 使用 Map<String, Object> 提供灵活性
  • 内存清理逻辑完善,性能考虑周到

VoiceProperties.java ⚠️ 需要改进

  • 新增 input_state 属性用于UI提示
  • 问题: 属性命名不一致,建议使用驼峰命名 inputState
  • 描述为"补充说明"过于简单,建议使用"输入状态提示"

2. 前端代码变更

fetch-audio API路由 (/api/fetch-audio/route.ts) ⚠️ 存在安全隐患

  • 安全问题: 未验证URL白名单,可能被滥用进行SSRF攻击
  • 建议: 添加URL域名白名单验证,例如:
const allowedDomains = ['trusted-domain.com', 'cdn.example.com'];
const urlObj = new URL(url);
if (!allowedDomains.includes(urlObj.hostname)) {
  return NextResponse.json({ success: false, error: 'Domain not allowed' }, { status: 403 });
}
  • 建议: 添加文件大小限制检查(当前可能下载任意大小文件)
  • 建议: 添加请求频率限制防止滥用

speech页面 (page.tsx) ⚠️ 复杂度较高,需优化

  • UI功能丰富,支持双音色配置(S1/S2)
  • 文件上传和URL输入双模式支持良好
  • 问题: 组件过于庞大(853行),建议拆分为多个子组件:
    • CustomVoiceSection: 自定义音色配置
    • AudioInputForm: 音频输入表单
    • SpeakerManager: 音色管理器
  • 问题: 状态管理复杂(多个useState),可考虑使用useReducer统一管理
  • 性能问题: base64音频处理可能占用大量内存,建议:
    • 添加文件大小检查(已有10MB限制,但可考虑更小)
    • 考虑使用Blob URL而非base64减少内存占用

3. 具体代码问题

前端逻辑问题:

  • page.tsx:356-378: base64处理逻辑重复,建议提取为工具函数
  • page.tsx:439-444: 播放状态检查可能存在内存泄漏,建议在组件卸载时清理定时器
  • page.tsx:275-279: 自动切换到S2可能导致用户体验混乱

类型安全:

  • TtsRequest.java:26: speakers 字段使用 Map<String, Object> 缺乏类型约束,建议创建专门的Speaker DTO类

改进建议总结

  1. 安全性: fetch-audio API需要添加URL白名单和速率限制
  2. 代码结构: 前端组件过大,建议模块化拆分
  3. 命名规范: Java属性命名保持一致性
  4. 性能优化: 减少base64使用,优化内存占用
  5. 类型安全: 增强类型定义,减少运行时错误

总体而言,功能实现完整,但在安全性和代码组织方面需要改进。


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants