feat: Enhance CustomVoiceForm and VoiceDesignForm with user preferences integration

This commit is contained in:
2026-02-04 19:09:42 +08:00
parent 73aacd174a
commit d0b2cb29c4
2 changed files with 42 additions and 15 deletions

View File

@@ -58,6 +58,13 @@ const CustomVoiceForm = forwardRef<CustomVoiceFormHandle>((_props, ref) => {
const { refresh } = useHistoryContext()
const { preferences } = useUserPreferences()
const selectedSpeaker = useMemo(() =>
unifiedSpeakers.find(s => s.id === selectedSpeakerId),
[unifiedSpeakers, selectedSpeakerId]
)
const isInstructDisabled = selectedSpeaker?.source === 'saved-design'
const {
register,
handleSubmit,
@@ -139,6 +146,12 @@ const CustomVoiceForm = forwardRef<CustomVoiceFormHandle>((_props, ref) => {
fetchData()
}, [preferences?.default_backend])
useEffect(() => {
if (selectedSpeaker?.source === 'saved-design' && selectedSpeaker.instruct) {
setValue('instruct', selectedSpeaker.instruct)
}
}, [selectedSpeakerId, selectedSpeaker, setValue])
const onSubmit = async (data: FormData) => {
setIsLoading(true)
@@ -208,10 +221,16 @@ const CustomVoiceForm = forwardRef<CustomVoiceFormHandle>((_props, ref) => {
<Select
value={selectedSpeakerId}
onValueChange={(value: string) => {
const newSpeaker = unifiedSpeakers.find(s => s.id === value)
const previousSource = selectedSpeaker?.source
if (newSpeaker) {
setSelectedSpeakerId(value)
const item = unifiedSpeakers.find(s => s.id === value)
if (item) {
setValue('speaker', item.id)
setValue('speaker', newSpeaker.id)
if (newSpeaker.source === 'builtin' && previousSource === 'saved-design') {
setValue('instruct', '')
}
}
}}
>
@@ -277,9 +296,14 @@ const CustomVoiceForm = forwardRef<CustomVoiceFormHandle>((_props, ref) => {
<IconLabel icon={Sparkles} tooltip="情绪指导(可选)" />
<Textarea
{...register('instruct')}
placeholder="例如:温柔体贴,语速平缓,充满关怀"
placeholder={isInstructDisabled
? "已使用音色设计的预设指导"
: "例如:温柔体贴,语速平缓,充满关怀"
}
className="min-h-[40px] md:min-h-[60px]"
disabled={isInstructDisabled}
/>
{!isInstructDisabled && (
<PresetSelector
presets={PRESET_INSTRUCTS}
onSelect={(preset) => {
@@ -289,6 +313,7 @@ const CustomVoiceForm = forwardRef<CustomVoiceFormHandle>((_props, ref) => {
}
}}
/>
)}
{errors.instruct && (
<p className="text-sm text-destructive">{errors.instruct.message}</p>
)}

View File

@@ -15,6 +15,7 @@ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/comp
import { ttsApi, jobApi, voiceDesignApi } from '@/lib/api'
import { useJobPolling } from '@/hooks/useJobPolling'
import { useHistoryContext } from '@/contexts/HistoryContext'
import { useUserPreferences } from '@/contexts/UserPreferencesContext'
import { LoadingState } from '@/components/LoadingState'
import { AudioPlayer } from '@/components/AudioPlayer'
import { PresetSelector } from '@/components/PresetSelector'
@@ -54,6 +55,7 @@ const VoiceDesignForm = forwardRef<VoiceDesignFormHandle>((_props, ref) => {
const { currentJob, isPolling, isCompleted, startPolling, elapsedTime } = useJobPolling()
const { refresh } = useHistoryContext()
const { preferences } = useUserPreferences()
const {
register,
@@ -130,7 +132,7 @@ const VoiceDesignForm = forwardRef<VoiceDesignFormHandle>((_props, ref) => {
await voiceDesignApi.create({
name: saveDesignName,
instruct: instruct,
backend_type: 'local'
backend_type: preferences?.default_backend || 'local'
})
toast.success('音色设计已保存')
setShowSaveDialog(false)