feat: Enhance CustomVoiceForm and VoiceDesignForm with user preferences integration
This commit is contained in:
@@ -58,6 +58,13 @@ const CustomVoiceForm = forwardRef<CustomVoiceFormHandle>((_props, ref) => {
|
|||||||
const { refresh } = useHistoryContext()
|
const { refresh } = useHistoryContext()
|
||||||
const { preferences } = useUserPreferences()
|
const { preferences } = useUserPreferences()
|
||||||
|
|
||||||
|
const selectedSpeaker = useMemo(() =>
|
||||||
|
unifiedSpeakers.find(s => s.id === selectedSpeakerId),
|
||||||
|
[unifiedSpeakers, selectedSpeakerId]
|
||||||
|
)
|
||||||
|
|
||||||
|
const isInstructDisabled = selectedSpeaker?.source === 'saved-design'
|
||||||
|
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
@@ -139,6 +146,12 @@ const CustomVoiceForm = forwardRef<CustomVoiceFormHandle>((_props, ref) => {
|
|||||||
fetchData()
|
fetchData()
|
||||||
}, [preferences?.default_backend])
|
}, [preferences?.default_backend])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (selectedSpeaker?.source === 'saved-design' && selectedSpeaker.instruct) {
|
||||||
|
setValue('instruct', selectedSpeaker.instruct)
|
||||||
|
}
|
||||||
|
}, [selectedSpeakerId, selectedSpeaker, setValue])
|
||||||
|
|
||||||
|
|
||||||
const onSubmit = async (data: FormData) => {
|
const onSubmit = async (data: FormData) => {
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
@@ -208,10 +221,16 @@ const CustomVoiceForm = forwardRef<CustomVoiceFormHandle>((_props, ref) => {
|
|||||||
<Select
|
<Select
|
||||||
value={selectedSpeakerId}
|
value={selectedSpeakerId}
|
||||||
onValueChange={(value: string) => {
|
onValueChange={(value: string) => {
|
||||||
|
const newSpeaker = unifiedSpeakers.find(s => s.id === value)
|
||||||
|
const previousSource = selectedSpeaker?.source
|
||||||
|
|
||||||
|
if (newSpeaker) {
|
||||||
setSelectedSpeakerId(value)
|
setSelectedSpeakerId(value)
|
||||||
const item = unifiedSpeakers.find(s => s.id === value)
|
setValue('speaker', newSpeaker.id)
|
||||||
if (item) {
|
|
||||||
setValue('speaker', item.id)
|
if (newSpeaker.source === 'builtin' && previousSource === 'saved-design') {
|
||||||
|
setValue('instruct', '')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -277,9 +296,14 @@ const CustomVoiceForm = forwardRef<CustomVoiceFormHandle>((_props, ref) => {
|
|||||||
<IconLabel icon={Sparkles} tooltip="情绪指导(可选)" />
|
<IconLabel icon={Sparkles} tooltip="情绪指导(可选)" />
|
||||||
<Textarea
|
<Textarea
|
||||||
{...register('instruct')}
|
{...register('instruct')}
|
||||||
placeholder="例如:温柔体贴,语速平缓,充满关怀"
|
placeholder={isInstructDisabled
|
||||||
|
? "已使用音色设计的预设指导"
|
||||||
|
: "例如:温柔体贴,语速平缓,充满关怀"
|
||||||
|
}
|
||||||
className="min-h-[40px] md:min-h-[60px]"
|
className="min-h-[40px] md:min-h-[60px]"
|
||||||
|
disabled={isInstructDisabled}
|
||||||
/>
|
/>
|
||||||
|
{!isInstructDisabled && (
|
||||||
<PresetSelector
|
<PresetSelector
|
||||||
presets={PRESET_INSTRUCTS}
|
presets={PRESET_INSTRUCTS}
|
||||||
onSelect={(preset) => {
|
onSelect={(preset) => {
|
||||||
@@ -289,6 +313,7 @@ const CustomVoiceForm = forwardRef<CustomVoiceFormHandle>((_props, ref) => {
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
{errors.instruct && (
|
{errors.instruct && (
|
||||||
<p className="text-sm text-destructive">{errors.instruct.message}</p>
|
<p className="text-sm text-destructive">{errors.instruct.message}</p>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/comp
|
|||||||
import { ttsApi, jobApi, voiceDesignApi } from '@/lib/api'
|
import { ttsApi, jobApi, voiceDesignApi } from '@/lib/api'
|
||||||
import { useJobPolling } from '@/hooks/useJobPolling'
|
import { useJobPolling } from '@/hooks/useJobPolling'
|
||||||
import { useHistoryContext } from '@/contexts/HistoryContext'
|
import { useHistoryContext } from '@/contexts/HistoryContext'
|
||||||
|
import { useUserPreferences } from '@/contexts/UserPreferencesContext'
|
||||||
import { LoadingState } from '@/components/LoadingState'
|
import { LoadingState } from '@/components/LoadingState'
|
||||||
import { AudioPlayer } from '@/components/AudioPlayer'
|
import { AudioPlayer } from '@/components/AudioPlayer'
|
||||||
import { PresetSelector } from '@/components/PresetSelector'
|
import { PresetSelector } from '@/components/PresetSelector'
|
||||||
@@ -54,6 +55,7 @@ const VoiceDesignForm = forwardRef<VoiceDesignFormHandle>((_props, ref) => {
|
|||||||
|
|
||||||
const { currentJob, isPolling, isCompleted, startPolling, elapsedTime } = useJobPolling()
|
const { currentJob, isPolling, isCompleted, startPolling, elapsedTime } = useJobPolling()
|
||||||
const { refresh } = useHistoryContext()
|
const { refresh } = useHistoryContext()
|
||||||
|
const { preferences } = useUserPreferences()
|
||||||
|
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
@@ -130,7 +132,7 @@ const VoiceDesignForm = forwardRef<VoiceDesignFormHandle>((_props, ref) => {
|
|||||||
await voiceDesignApi.create({
|
await voiceDesignApi.create({
|
||||||
name: saveDesignName,
|
name: saveDesignName,
|
||||||
instruct: instruct,
|
instruct: instruct,
|
||||||
backend_type: 'local'
|
backend_type: preferences?.default_backend || 'local'
|
||||||
})
|
})
|
||||||
toast.success('音色设计已保存')
|
toast.success('音色设计已保存')
|
||||||
setShowSaveDialog(false)
|
setShowSaveDialog(false)
|
||||||
|
|||||||
Reference in New Issue
Block a user