50 lines
2.1 KiB
TypeScript
50 lines
2.1 KiB
TypeScript
import type { FeedbackSession, VoiceAudioSegment, VoiceLesson } 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 getVoiceLessonStatusText(lesson: VoiceLesson, isInDraft = false): string {
|
||
if (lesson.status === 'failed') return '转录失败'
|
||
if (lesson.status === 'recording') return '录音中'
|
||
if (lesson.status === 'processing') return '处理中'
|
||
if (isInDraft) return '已在输入框'
|
||
if (lesson.includedInGeneration) return '已生成反馈'
|
||
if (lesson.appliedDirectly) return '可重新加入'
|
||
return '可加入输入框'
|
||
}
|
||
|
||
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}段录音转录失败,可重试,或放弃该失败录音。`
|
||
}
|