fix(voice): restore failed transcription recovery
This commit is contained in:
39
pages/feedback/voice-state.ts
Normal file
39
pages/feedback/voice-state.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import type { FeedbackSession, VoiceAudioSegment } from '../../utils/types'
|
||||
|
||||
export type VoicePrimaryAction = 'save' | 'retry' | 'processing' | 'generate'
|
||||
|
||||
export function getVoicePrimaryAction(session: FeedbackSession | null): VoicePrimaryAction {
|
||||
if (!session || session.lessonCount === 0) return 'save'
|
||||
if (session.failedSegmentCount > 0) return 'retry'
|
||||
if (session.processingSegmentCount > 0) return 'processing'
|
||||
return session.needsGeneration ? 'generate' : 'save'
|
||||
}
|
||||
|
||||
export function getVoicePrimaryActionText(
|
||||
action: VoicePrimaryAction,
|
||||
failedSegmentCount = 0
|
||||
): string {
|
||||
if (action === 'retry') return `重试转录(${failedSegmentCount})`
|
||||
if (action === 'processing') return '转录中'
|
||||
if (action === 'generate') return '生成反馈'
|
||||
return '保存反馈'
|
||||
}
|
||||
|
||||
export function getFailedVoiceSegments(session: FeedbackSession): VoiceAudioSegment[] {
|
||||
return session.lessons.flatMap((lesson) =>
|
||||
lesson.segments.filter((segment) => segment.status === 'failed')
|
||||
)
|
||||
}
|
||||
|
||||
export function getVoiceFailureHint(session: FeedbackSession): string {
|
||||
const failedSegments = getFailedVoiceSegments(session)
|
||||
const hasNoClearSpeech = failedSegments.some((segment) => {
|
||||
const message = segment.errorMessage?.toLowerCase() || ''
|
||||
return message.includes('no clear speech') || message.includes('未识别到清晰语音')
|
||||
})
|
||||
const count = session.failedSegmentCount
|
||||
if (hasNoClearSpeech) {
|
||||
return `${count}段录音未识别到清晰语音,可能是录音过短、静音或环境噪声较大。可重试,或放弃后重新录制。`
|
||||
}
|
||||
return `${count}段录音转录失败,可重试,或放弃后重新录制。`
|
||||
}
|
||||
Reference in New Issue
Block a user