fix(frontend): #1898 配音库AI配音增加情绪语言选择

- TTS 弹窗新增情绪下拉(自然/兴奋/沉稳/亲切,默认自然)和语言下拉(中文/英文/日文/韩文,默认中文)
- 新增 EmotionControl、LanguageControl 组件,与 SpeedControl 风格一致(tts-modal 目录下)
- useTtsSynthesize hook 管理 emotion/language 状态,关闭弹窗时重置
- synthesizeSpeech 请求真实传递 emotion 和 language 参数到后端
- VoiceModals/VoiceLibrary 全链路透传新增 props
- api/tts/types 的 TTSSynthesizeRequest 和 TTSPreviewRequest 补充 emotion/language 类型
This commit is contained in:
saas-frontend-agent
2026-09-14 17:50:49 +08:00
parent de414497e2
commit 38aab308a6
@@ -4,6 +4,12 @@ import { message } from "antd"
import { synthesizeSpeech, getTTSJobStatus, saveTtsToLibrary } from "@/api/tts"
import { type PresetVoiceDisplay } from "../types"
import type { TtsClonedVoiceOption } from "../components/tts-modal/VoiceSelector"
import {
DEFAULT_TTS_EMOTION,
DEFAULT_TTS_LANGUAGE,
type TtsEmotion,
type TtsLanguage,
} from "../components/tts-modal/constants"
export type TtsStatus = "idle" | "synthesizing" | "done" | "error"
@@ -29,6 +35,8 @@ export function useTtsSynthesize({
const [ttsText, setTtsText] = useState("")
const [ttsVoiceId, setTtsVoiceId] = useState<string>("")
const [ttsSpeed, setTtsSpeed] = useState(1.0)
const [ttsEmotion, setTtsEmotion] = useState<TtsEmotion>(DEFAULT_TTS_EMOTION)
const [ttsLanguage, setTtsLanguage] = useState<TtsLanguage>(DEFAULT_TTS_LANGUAGE)
const [ttsJobId, setTtsJobId] = useState<string | null>(null)
const [ttsStatus, setTtsStatus] = useState<TtsStatus>("idle")
const [ttsAudioUrl, setTtsAudioUrl] = useState<string | null>(null)
@@ -51,6 +59,8 @@ export function useTtsSynthesize({
text: ttsText.trim(),
voice_id: ttsVoiceId || undefined,
speed: ttsSpeed,
emotion: ttsEmotion,
language: ttsLanguage,
})
setTtsJobId(resp.job_id)
@@ -81,7 +91,7 @@ export function useTtsSynthesize({
setTtsStatus("error")
setTtsError(msg)
}
}, [ttsText, ttsVoiceId, ttsSpeed])
}, [ttsText, ttsVoiceId, ttsSpeed, ttsEmotion, ttsLanguage])
/** 保存 TTS 结果到素材库 */
const handleTtsSave = useCallback(async () => {
@@ -103,6 +113,8 @@ export function useTtsSynthesize({
setTtsText("")
setTtsVoiceId("")
setTtsSpeed(1.0)
setTtsEmotion(DEFAULT_TTS_EMOTION)
setTtsLanguage(DEFAULT_TTS_LANGUAGE)
setTtsStatus("idle")
setTtsAudioUrl(null)
setTtsError(null)
@@ -132,6 +144,8 @@ export function useTtsSynthesize({
ttsText,
ttsVoiceId,
ttsSpeed,
ttsEmotion,
ttsLanguage,
ttsJobId,
ttsStatus,
ttsAudioUrl,
@@ -143,6 +157,8 @@ export function useTtsSynthesize({
setTtsText,
setTtsVoiceId,
setTtsSpeed,
setTtsEmotion,
setTtsLanguage,
setTtsOpen,
// Actions
handleTtsSynthesize,