refactor(desktop): session-scoped voice runtime, STT/LLM ports, caption ownership and meeting export fixes
This commit is contained in:
parent
0adedf5e7b
commit
83cf9133ac
39 changed files with 4787 additions and 1061 deletions
|
|
@ -52,3 +52,110 @@ export function formatTranscriptLines(lines: readonly TranscriptLine[]): string
|
|||
})
|
||||
.join('\n')
|
||||
}
|
||||
|
||||
/** 캡처 세그먼트(절대 epoch 타임스탬프)를 회의 시작 기준 전사 줄로 조립한다. */
|
||||
export interface TimedSegmentInput {
|
||||
text: string
|
||||
/** 절대 시각(epoch ms). CaptionService 가 Date.now() 로 찍는다. */
|
||||
timestamp: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 회의 세그먼트로 전사 텍스트를 만든다.
|
||||
*
|
||||
* 세그먼트 시각은 epoch 이므로 반드시 회의 시작 시각을 빼서 상대 시각으로 바꾼다
|
||||
* (예전엔 epoch 을 그대로 써 `[29841999:45]` 가 저장되어 파싱·화자 구분·동기화가 모두 깨졌다).
|
||||
* 시작 전 시각은 0 으로 자르고, 빈 텍스트 세그먼트는 버린다.
|
||||
*/
|
||||
export function buildTranscriptFromSegments(
|
||||
segments: readonly TimedSegmentInput[],
|
||||
sessionStartedAt: number,
|
||||
): string {
|
||||
const lines: TranscriptLine[] = []
|
||||
for (const segment of segments) {
|
||||
const text = segment.text.trim()
|
||||
if (!text) continue
|
||||
lines.push({
|
||||
timestampMs: Math.max(0, segment.timestamp - sessionStartedAt),
|
||||
timed: true,
|
||||
speaker: null,
|
||||
text,
|
||||
})
|
||||
}
|
||||
return formatTranscriptLines(lines)
|
||||
}
|
||||
|
||||
/** 화자 구분 결과 구간. start/end 는 초 단위(pyannote 응답 형식). */
|
||||
export interface SpeakerSegment {
|
||||
speaker: string
|
||||
start: number
|
||||
end: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 전사 줄에 화자 구분 결과를 적용한다. 시각이 있는 줄의 시각이 속한 구간의 화자로
|
||||
* speaker 필드를 **교체**한다(앞에 덧붙이지 않으므로 다시 돌려도 라벨이 쌓이지 않는다).
|
||||
* 구간에 속하지 않거나 시각이 없는 줄은 그대로 둔다.
|
||||
*
|
||||
* @param labelFor 원시 화자 id(예: SPEAKER_01)를 표시 라벨로 바꾸는 함수 — 표시 문구는 호출자 소관
|
||||
*/
|
||||
export function applySpeakerLabels(
|
||||
lines: readonly TranscriptLine[],
|
||||
segments: readonly SpeakerSegment[],
|
||||
labelFor: (rawSpeaker: string) => string = (raw) => raw,
|
||||
): TranscriptLine[] {
|
||||
return lines.map((line) => {
|
||||
if (!line.timed) return line
|
||||
const seconds = line.timestampMs / 1000
|
||||
const match = segments.find((s) => seconds >= s.start && seconds <= s.end)
|
||||
if (!match) return line
|
||||
return { ...line, speaker: labelFor(match.speaker) }
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 전사를 줄 경계에서 끊어 LLM 한 번에 보낼 크기의 조각들로 나눈다.
|
||||
* 한 줄이 maxChars 보다 길면 그 줄 하나로 한 조각을 만든다(줄 중간은 자르지 않는다).
|
||||
* 빈 줄은 버린다.
|
||||
*/
|
||||
export function chunkTranscriptByLines(text: string | null | undefined, maxChars: number): string[] {
|
||||
if (!text) return []
|
||||
const chunks: string[] = []
|
||||
let current: string[] = []
|
||||
let size = 0
|
||||
for (const raw of text.split('\n')) {
|
||||
const line = raw.trimEnd()
|
||||
if (!line.trim()) continue
|
||||
if (current.length > 0 && size + line.length + 1 > maxChars) {
|
||||
chunks.push(current.join('\n'))
|
||||
current = []
|
||||
size = 0
|
||||
}
|
||||
current.push(line)
|
||||
size += line.length + 1
|
||||
}
|
||||
if (current.length > 0) chunks.push(current.join('\n'))
|
||||
return chunks
|
||||
}
|
||||
|
||||
const TIMED_LINE = /^\s*\[\d{1,3}:\d{2}\]/
|
||||
|
||||
function countTimedLines(text: string): number {
|
||||
return text.split('\n').filter((l) => TIMED_LINE.test(l)).length
|
||||
}
|
||||
|
||||
/**
|
||||
* LLM 이 전사 조각을 다시 쓴 결과가 잘렸는지(출력 토큰 한도 등) 추정한다.
|
||||
* - 입력에 시각 줄이 있으면: 출력의 시각 줄이 입력의 80% 미만이면 잘린 것으로 본다.
|
||||
* - 없으면: 출력 길이가 입력의 50% 미만이면 잘린 것으로 본다.
|
||||
* 잘린 결과로 전사를 덮어쓰면 회의 뒷부분이 문서·채팅·동기화에서 조용히 사라진다.
|
||||
*/
|
||||
export function looksTruncatedRewrite(input: string, output: string): boolean {
|
||||
const trimmed = output.trim()
|
||||
if (!trimmed) return true
|
||||
const inputTimed = countTimedLines(input)
|
||||
if (inputTimed > 0) {
|
||||
return countTimedLines(trimmed) < Math.ceil(inputTimed * 0.8)
|
||||
}
|
||||
return trimmed.length < input.trim().length * 0.5
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue