fix: 统一预计文案,TTS预计积分恢复±1积分范围
This commit is contained in:
@@ -47,7 +47,7 @@ export function usePointsCheck() {
|
||||
await fetchBalance();
|
||||
const balance = usePointStore.getState().balance;
|
||||
if (balance < points) {
|
||||
setModalDescription(`预估消耗 ${points} 积分,当前余额 ${balance} 积分`);
|
||||
setModalDescription(`预计消耗 ${points} 积分,当前余额 ${balance} 积分`);
|
||||
setShowPointsModal(true);
|
||||
return false;
|
||||
}
|
||||
@@ -67,7 +67,7 @@ export function usePointsCheck() {
|
||||
(error: unknown, _bizName: string, _requiredPoints?: number): boolean => {
|
||||
const msg = error instanceof Error ? error.message : String(error);
|
||||
if (msg.includes('402') || msg.includes('积分不足')) {
|
||||
setModalDescription(`预估消耗 ${_requiredPoints || '?'} 积分`);
|
||||
setModalDescription(`预计消耗 ${_requiredPoints || '?'} 积分`);
|
||||
setShowPointsModal(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ export default function VoiceSynthesis() {
|
||||
// 加上镜头切换停顿(segment↔empty_shot: 0.5s,同类型: 0.3s),每 5 秒 1 积分,最低 1 积分
|
||||
const estimatedTtsPoints = useMemo(() => {
|
||||
const validSegments = segments.filter(s => s.voiceover?.trim());
|
||||
if (validSegments.length === 0) return 0;
|
||||
if (validSegments.length === 0) return { min: 0, max: 0 };
|
||||
|
||||
// 纯朗读时间
|
||||
const totalChars = validSegments.reduce((sum, s) => sum + s.voiceover!.trim().length, 0);
|
||||
@@ -98,7 +98,11 @@ export default function VoiceSynthesis() {
|
||||
}
|
||||
|
||||
const totalSeconds = speechSeconds + pauseSeconds;
|
||||
return Math.max(1, Math.ceil(totalSeconds / 5));
|
||||
const base = Math.max(1, Math.ceil(totalSeconds / 5));
|
||||
// 范围:±1 积分,覆盖取整误差和语速波动
|
||||
const min = Math.max(1, base - 1);
|
||||
const max = base + 1;
|
||||
return { min, max };
|
||||
}, [segments, speed]);
|
||||
|
||||
const handlePlayPause = useCallback((voiceId: string, url: string | null, e: React.MouseEvent) => {
|
||||
@@ -299,7 +303,7 @@ export default function VoiceSynthesis() {
|
||||
if (!currentVoiceId) { toast.warning('请先选择音色'); setIsGenerating(false); return; }
|
||||
|
||||
// 前置积分检查
|
||||
const ok = await checkBalance(estimatedTtsPoints, '配音合成');
|
||||
const ok = await checkBalance(estimatedTtsPoints.max, '配音合成');
|
||||
if (!ok) return;
|
||||
|
||||
const progress = useProgressStore.getState();
|
||||
@@ -353,9 +357,9 @@ export default function VoiceSynthesis() {
|
||||
// 生成完成后自动执行打轴+截取
|
||||
await handleAlignAndClip(qiniuUrl, meta.filePath);
|
||||
|
||||
progress.success('配音合成完成', result.consumedPoints || estimatedTtsPoints);
|
||||
progress.success('配音合成完成', result.consumedPoints);
|
||||
} catch (err) {
|
||||
if (handleError(err, '配音合成', estimatedTtsPoints)) {
|
||||
if (handleError(err, '配音合成', estimatedTtsPoints.max)) {
|
||||
progress.hide();
|
||||
return;
|
||||
}
|
||||
@@ -526,12 +530,12 @@ export default function VoiceSynthesis() {
|
||||
<div className="voice-generate-wrap">
|
||||
{!hasGeneratedAudio ? (
|
||||
<button className="btn btn-primary generate-btn" onClick={handleGenerate} disabled={isGenerating || !mergedText.trim()}>
|
||||
{isGenerating ? '合成中...' : `合成配音(预计消耗 ${estimatedTtsPoints} 积分)`}
|
||||
{isGenerating ? '合成中...' : `合成配音(预计消耗 ${estimatedTtsPoints.min}~${estimatedTtsPoints.max} 积分)`}
|
||||
</button>
|
||||
) : (
|
||||
<div className="voice-generate-btns">
|
||||
<button className="btn btn-secondary generate-btn" onClick={handleGenerate} disabled={isGenerating || !mergedText.trim()}>
|
||||
{isGenerating ? '合成中...' : `重新生成(预计消耗 ${estimatedTtsPoints} 积分)`}
|
||||
{isGenerating ? '合成中...' : `重新生成(预计消耗 ${estimatedTtsPoints.min}~${estimatedTtsPoints.max} 积分)`}
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-primary generate-btn"
|
||||
|
||||
Reference in New Issue
Block a user