diff --git a/apps/web/src/pages/voices/hooks/useTtsSynthesize.ts b/apps/web/src/pages/voices/hooks/useTtsSynthesize.ts index 19c777e44..f5c2e841e 100644 --- a/apps/web/src/pages/voices/hooks/useTtsSynthesize.ts +++ b/apps/web/src/pages/voices/hooks/useTtsSynthesize.ts @@ -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("") const [ttsSpeed, setTtsSpeed] = useState(1.0) + const [ttsEmotion, setTtsEmotion] = useState(DEFAULT_TTS_EMOTION) + const [ttsLanguage, setTtsLanguage] = useState(DEFAULT_TTS_LANGUAGE) const [ttsJobId, setTtsJobId] = useState(null) const [ttsStatus, setTtsStatus] = useState("idle") const [ttsAudioUrl, setTtsAudioUrl] = useState(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,