feat: ship Wave 5-6 multi-surface hygiene, optimization, and bug fixes
This commit is contained in:
parent
01ef3293cf
commit
66b6b45ba9
399 changed files with 17828 additions and 11330 deletions
|
|
@ -3,6 +3,7 @@
|
|||
// 데스크톱은 전사를 `[MM:SS] [화자] 내용` 줄로 저장하고, Supabase `transcripts` 는 구간 행으로 저장한다
|
||||
// (모바일은 구간이 있으면 구간을 우선 표시한다). 두 표현을 이 한 곳에서만 바꾼다.
|
||||
|
||||
import { formatDurationClockFromMs } from './format'
|
||||
import { splitTextToFit } from './text-chunking'
|
||||
|
||||
export interface TranscriptLine {
|
||||
|
|
@ -38,10 +39,7 @@ export function parseTranscriptLines(text: string | null | undefined): Transcrip
|
|||
}
|
||||
|
||||
export function formatTranscriptTimestamp(ms: number): string {
|
||||
const totalSeconds = Math.max(0, Math.floor(ms / 1000))
|
||||
const minutes = Math.floor(totalSeconds / 60)
|
||||
const seconds = totalSeconds % 60
|
||||
return `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`
|
||||
return formatDurationClockFromMs(ms, { padMinutes: true })
|
||||
}
|
||||
|
||||
/** parseTranscriptLines 의 역변환(시각 표기가 없던 줄은 그대로). */
|
||||
|
|
@ -74,11 +72,15 @@ export function buildTranscriptFromSegments(
|
|||
sessionStartedAt: number,
|
||||
): string {
|
||||
const lines: TranscriptLine[] = []
|
||||
const safeStartedAt = Number.isFinite(sessionStartedAt) ? sessionStartedAt : 0
|
||||
for (const segment of segments) {
|
||||
const text = segment.text.trim()
|
||||
if (!text) continue
|
||||
const timestampMs = Number.isFinite(segment.timestamp) && Number.isFinite(sessionStartedAt)
|
||||
? Math.max(0, segment.timestamp - safeStartedAt)
|
||||
: 0
|
||||
lines.push({
|
||||
timestampMs: Math.max(0, segment.timestamp - sessionStartedAt),
|
||||
timestampMs,
|
||||
timed: true,
|
||||
speaker: null,
|
||||
text,
|
||||
|
|
@ -181,3 +183,67 @@ export function looksTruncatedRewrite(input: string, output: string): boolean {
|
|||
}
|
||||
return trimmed.length < input.trim().length * 0.5
|
||||
}
|
||||
|
||||
const PYANNOTE_SPEAKER_PATTERN = /^SPEAKER_(\d+)$/iu
|
||||
const TRAILING_SPEAKER_NUMBER_PATTERN = /(\d+)$/u
|
||||
|
||||
/**
|
||||
* pyannote 원시 화자 ID(`SPEAKER_00`, `SPEAKER_01`)를 1 기반 표시 라벨(`화자 1`, `화자 2`)로 바꾼다.
|
||||
* 이미 사용자 정의 이름이나 표시 라벨인 경우 공백만 정리해 그대로 돌려준다.
|
||||
*/
|
||||
export function formatPyannoteSpeakerLabel(rawSpeaker: string, prefix = '화자'): string {
|
||||
const trimmed = rawSpeaker.trim()
|
||||
const match = PYANNOTE_SPEAKER_PATTERN.exec(trimmed)
|
||||
if (!match) return trimmed
|
||||
const zeroBased = Number.parseInt(match[1], 10)
|
||||
return `${prefix} ${zeroBased + 1}`
|
||||
}
|
||||
|
||||
/**
|
||||
* 화자 라벨(`화자 1`, `Speaker 2`, `SPEAKER_00`, `김민수`)을 팔레트 길이 내 결정적 색상 인덱스로 매핑한다.
|
||||
*/
|
||||
export function resolveSpeakerColorIndex(speaker: string, paletteSize = 5): number {
|
||||
const size = Math.max(1, Math.floor(paletteSize))
|
||||
const normalized = speaker.trim()
|
||||
if (!normalized || size === 1) return 0
|
||||
|
||||
const pyannoteMatch = PYANNOTE_SPEAKER_PATTERN.exec(normalized)
|
||||
if (pyannoteMatch) {
|
||||
return Number.parseInt(pyannoteMatch[1], 10) % size
|
||||
}
|
||||
|
||||
const trailingMatch = TRAILING_SPEAKER_NUMBER_PATTERN.exec(normalized)
|
||||
if (trailingMatch) {
|
||||
const rawDigits = trailingMatch[1]
|
||||
const parsed = Number.parseInt(rawDigits, 10)
|
||||
if (rawDigits.startsWith('0') || parsed === 0) {
|
||||
return parsed % size
|
||||
}
|
||||
return (parsed - 1) % size
|
||||
}
|
||||
|
||||
let hash = 2166136261
|
||||
const lower = normalized.toLowerCase()
|
||||
for (let i = 0; i < lower.length; i += 1) {
|
||||
hash ^= lower.charCodeAt(i)
|
||||
hash = Math.imul(hash, 16777619)
|
||||
}
|
||||
return (hash >>> 0) % size
|
||||
}
|
||||
|
||||
/**
|
||||
* 세그먼트 목록에서 화자 라벨을 첫 등장 순서대로 중복 없이 추출한다.
|
||||
*/
|
||||
export function extractDistinctSpeakers(
|
||||
segments: readonly { readonly speaker?: string | null }[],
|
||||
): string[] {
|
||||
const seen = new Set<string>()
|
||||
const speakers: string[] = []
|
||||
for (const segment of segments) {
|
||||
const label = segment.speaker?.trim()
|
||||
if (!label || seen.has(label)) continue
|
||||
seen.add(label)
|
||||
speakers.push(label)
|
||||
}
|
||||
return speakers
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue