feat: update emotion handling and adjust alpha levels in TTS and LLM services
This commit is contained in:
@@ -1416,7 +1416,12 @@ function CharactersPanel({
|
||||
)
|
||||
}
|
||||
|
||||
const EMOTION_OPTIONS = ['开心', '愤怒', '悲伤', '恐惧', '厌恶', '低沉', '惊讶', '中性']
|
||||
const EMOTION_OPTIONS = ['开心', '愤怒', '悲伤', '恐惧', '厌恶', '低沉', '惊讶']
|
||||
|
||||
const EMO_LEVEL_MAX: Record<string, number> = {
|
||||
'开心': 0.75, '愤怒': 0.08, '悲伤': 0.90,
|
||||
'恐惧': 0.10, '厌恶': 0.50, '低沉': 0.35, '惊讶': 0.35,
|
||||
}
|
||||
|
||||
|
||||
function ChaptersPanel({
|
||||
@@ -1517,7 +1522,7 @@ function ChaptersPanel({
|
||||
setEditingSegId(seg.id)
|
||||
setEditText(seg.text)
|
||||
const rawEmo = seg.emo_text || ''
|
||||
const alpha = seg.emo_alpha ?? 0.5
|
||||
const alpha = seg.emo_alpha ?? 5
|
||||
if (!rawEmo) {
|
||||
setEditEmoSelections([])
|
||||
setEditEmoWeights({})
|
||||
@@ -1528,14 +1533,17 @@ function ChaptersPanel({
|
||||
const weights: Record<string, number> = {}
|
||||
if (tokens.length === 1) {
|
||||
const [name] = tokens[0].split(':')
|
||||
selections.push(name.trim())
|
||||
weights[name.trim()] = alpha
|
||||
const emoName = name.trim()
|
||||
selections.push(emoName)
|
||||
// Convert old float alpha to level if needed
|
||||
weights[emoName] = alpha > 1 ? Math.round(alpha) : Math.round(alpha / (EMO_LEVEL_MAX[emoName] || 0.35) * 10)
|
||||
} else {
|
||||
for (const tok of tokens) {
|
||||
const [name, w] = tok.split(':')
|
||||
const emo = name.trim()
|
||||
selections.push(emo)
|
||||
weights[emo] = w ? parseFloat(w) : parseFloat((0.5 * alpha).toFixed(2))
|
||||
const rawW = w ? parseFloat(w) : (EMO_LEVEL_MAX[emo] || 0.35) * 0.5
|
||||
weights[emo] = Math.round(rawW / (EMO_LEVEL_MAX[emo] || 0.35) * 10)
|
||||
}
|
||||
}
|
||||
setEditEmoSelections(selections)
|
||||
@@ -1551,9 +1559,13 @@ function ChaptersPanel({
|
||||
let emo_alpha: number | null = null
|
||||
if (editEmoSelections.length === 1) {
|
||||
emo_text = editEmoSelections[0]
|
||||
emo_alpha = editEmoWeights[editEmoSelections[0]] ?? 0.5
|
||||
emo_alpha = editEmoWeights[editEmoSelections[0]] ?? 5
|
||||
} else if (editEmoSelections.length > 1) {
|
||||
emo_text = editEmoSelections.map(e => `${e}:${(editEmoWeights[e] ?? 0.5).toFixed(2)}`).join('+')
|
||||
emo_text = editEmoSelections.map(e => {
|
||||
const level = editEmoWeights[e] ?? 5
|
||||
const weight = parseFloat((level / 10 * (EMO_LEVEL_MAX[e] || 0.35)).toFixed(4))
|
||||
return `${e}:${weight}`
|
||||
}).join('+')
|
||||
emo_alpha = 1.0
|
||||
}
|
||||
await onUpdateSegment(segId, { text: editText, emo_text, emo_alpha })
|
||||
@@ -1778,7 +1790,7 @@ function ChaptersPanel({
|
||||
const [name, w] = tok.split(':')
|
||||
return <span key={tok}>{i > 0 ? ' ' : ''}{name.trim()}{w ? `:${parseFloat(w).toFixed(2)}` : ''}</span>
|
||||
})}
|
||||
{seg.emo_alpha != null && seg.emo_alpha !== 1 && ` :${seg.emo_alpha.toFixed(2)}`}
|
||||
{seg.emo_alpha != null && seg.emo_alpha !== 1 && ` Lv.${seg.emo_alpha > 1 ? Math.round(seg.emo_alpha) : seg.emo_alpha}`}
|
||||
</>
|
||||
)}
|
||||
</span>
|
||||
@@ -1834,7 +1846,7 @@ function ChaptersPanel({
|
||||
setEditEmoSelections(prev => prev.filter(e => e !== emo))
|
||||
} else {
|
||||
setEditEmoSelections(prev => [...prev, emo])
|
||||
setEditEmoWeights(prev => ({ ...prev, [emo]: prev[emo] ?? 0.5 }))
|
||||
setEditEmoWeights(prev => ({ ...prev, [emo]: prev[emo] ?? 5 }))
|
||||
}
|
||||
}}
|
||||
>
|
||||
@@ -1848,14 +1860,14 @@ function ChaptersPanel({
|
||||
<span className="text-xs text-muted-foreground w-8 shrink-0">{emo}:</span>
|
||||
<input
|
||||
type="range"
|
||||
min={0.05}
|
||||
max={0.9}
|
||||
step={0.05}
|
||||
value={editEmoWeights[emo] ?? 0.5}
|
||||
min={1}
|
||||
max={10}
|
||||
step={1}
|
||||
value={editEmoWeights[emo] ?? 5}
|
||||
onChange={e => setEditEmoWeights(prev => ({ ...prev, [emo]: Number(e.target.value) }))}
|
||||
className="flex-1 h-1.5 accent-primary"
|
||||
/>
|
||||
<span className="text-xs text-muted-foreground w-8 text-right">{(editEmoWeights[emo] ?? 0.5).toFixed(2)}</span>
|
||||
<span className="text-xs text-muted-foreground w-6 text-right">{editEmoWeights[emo] ?? 5}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user