feat(meeting): correct transcripts with vocabulary learned from typing

Meeting and caption transcription never used what the app had already
learned: speech recognition ran with a fixed Korean prompt, the refine
prompt had no glossary, refined lines stopped inside the caption service,
and the saved transcript was a raw join of segments. Names and jargon the
user types every day were therefore re-mangled on every recording.

The learned corpus (user dictionary plus personal phrases) now feeds one
glossary that biases recognition, fixes mistyped words deterministically
right after each line is finalized, and is handed to the local model when
it polishes a line. Refined lines also reach the meeting transcript and
screen through a new segment-updated event.

Corrections never touch words the user actually wrote, refuse ties between
equally likely candidates, and keep particles intact.
This commit is contained in:
Yun Chan 2026-11-05 21:58:28 +09:00
parent d631042836
commit 9c2b6a9782
21 changed files with 1134 additions and 61 deletions

View file

@ -0,0 +1,160 @@
// packages/core/__tests__/transcript-correction.test.ts
// 학습 어휘(사전 + 개인 문구)가 STT 힌트·결정적 교정·LLM 교열 참고로 바뀌는 규칙.
import { describe, expect, it } from 'vitest'
import {
appendGlossaryHint,
buildGlossaryPromptSection,
buildTranscriptGlossary,
correctLearnedTerms,
replaceDictionaryTerms,
splitGlossaryVariants,
type GlossaryPhrase,
} from '../src/transcript-correction'
function phrases(...items: Array<[string, number]>): GlossaryPhrase[] {
return items.map(([text, count]) => ({ text, count }))
}
describe('buildTranscriptGlossary', () => {
it('사전 용어와 학습 어절을 STT 힌트로 만든다', () => {
const glossary = buildTranscriptGlossary({
dictionary: [{ word: 'D3RO', pronunciation: '디에로' }],
phrases: phrases(['회의록 정리해줘', 5]),
})
expect(glossary.promptHint).toContain('D3RO')
expect(glossary.promptHint).toContain('회의록')
expect(glossary.dictionary[0]).toEqual({ word: 'D3RO', variants: ['디에로'] })
})
it('한 번 쓴 어절은 교정 후보로 쓰지 않는다', () => {
const glossary = buildTranscriptGlossary({ phrases: phrases(['회의록 정리해줘', 1]) })
expect(glossary.vocabulary.has('회의록')).toBe(false)
expect(glossary.vocabulary.has('정리해줘')).toBe(false)
})
it('기능어는 힌트와 교정 후보에서 뺀다', () => {
const glossary = buildTranscriptGlossary({ phrases: phrases(['그래서 회의록 정리', 9]) })
expect(glossary.vocabulary.has('그래서')).toBe(false)
expect(glossary.promptHint).not.toContain('그래서')
})
it('힌트는 길이 한도 안에서 만든다', () => {
const longWords = Array.from({ length: 80 }, (_, i) => `용어${String(i).padStart(2, '0')}`)
const glossary = buildTranscriptGlossary({
dictionary: longWords.map((word) => ({ word, pronunciation: null })),
})
expect(glossary.promptHint.length).toBeLessThanOrEqual(250)
expect(glossary.promptHint.endsWith('.')).toBe(true)
})
it('아무 정보도 없으면 빈 힌트를 돌려준다', () => {
const glossary = buildTranscriptGlossary({})
expect(glossary.promptHint).toBe('')
expect(glossary.vocabulary.size).toBe(0)
expect(buildGlossaryPromptSection(glossary)).toBe('')
})
})
describe('splitGlossaryVariants', () => {
it('발음 문자열을 변형 목록으로 나누고 정본 표기는 뺀다', () => {
expect(splitGlossaryVariants('디에로, 디로 / D3RO', 'D3RO')).toEqual(['디에로', '디로'])
expect(splitGlossaryVariants(null, 'D3RO')).toEqual([])
})
})
describe('replaceDictionaryTerms', () => {
it('발음 변형을 정본 표기로 바꾸고 치환 내역을 남긴다', () => {
const result = replaceDictionaryTerms('디에로 보이스 좋네요', [
{ word: 'D3RO', pronunciation: '디에로' },
])
expect(result.text).toBe('D3RO 보이스 좋네요')
expect(result.changes).toEqual([{ from: '디에로', to: 'D3RO', source: 'dictionary' }])
expect(result.matched).toEqual(['D3RO'])
})
it('영단어 정본은 다른 단어 안쪽을 건드리지 않는다', () => {
const result = replaceDictionaryTerms('D3ROVoice 와 디에로', [
{ word: 'D3RO', pronunciation: '디에로' },
])
expect(result.text).toBe('D3ROVoice 와 D3RO')
})
})
describe('correctLearnedTerms', () => {
const glossary = buildTranscriptGlossary({
phrases: phrases(['회의록 정리해줘', 6], ['전사 교정', 4]),
})
it('1자모 차이 나는 전사 어절을 학습 어절로 되돌린다', () => {
const result = correctLearnedTerms('회이록 정리해줘', glossary)
expect(result.text).toBe('회의록 정리해줘')
expect(result.corrections).toEqual([{ from: '회이록', to: '회의록', source: 'learned' }])
})
it('조사는 붙인 채로 어절만 고친다', () => {
expect(correctLearnedTerms('회이록은 좋다', glossary).text).toBe('회의록은 좋다')
})
it('사용자가 실제로 쓴 어절은 건드리지 않는다', () => {
const result = correctLearnedTerms('회의록 정리해줘', glossary)
expect(result.text).toBe('회의록 정리해줘')
expect(result.corrections).toEqual([])
})
it('후보가 둘 이상이면(동률) 고치지 않는다', () => {
const tied = buildTranscriptGlossary({
phrases: phrases(['정리해', 4], ['정리히', 4]),
})
expect(correctLearnedTerms('정리하', tied).text).toBe('정리하')
})
it('어휘가 없으면 원문을 그대로 돌려준다', () => {
const result = correctLearnedTerms('아무 말이나 적는다', buildTranscriptGlossary({}))
expect(result).toEqual({ text: '아무 말이나 적는다', corrections: [] })
})
it('사전 정본 표기가 학습 어절보다 우선한다', () => {
const withDictionary = buildTranscriptGlossary({
dictionary: [{ word: '회의록', pronunciation: null }],
phrases: phrases(['회의녹 정리', 9]),
})
expect(correctLearnedTerms('회이록 정리', withDictionary).text).toBe('회의록 정리')
})
})
describe('LLM 교열 참고 블록', () => {
it('사전 용어와 사용자 표현을 지시와 함께 넣는다', () => {
const glossary = buildTranscriptGlossary({
dictionary: [{ word: 'D3RO', pronunciation: '디에로' }],
phrases: phrases(['오늘 회의는 세 시에 시작합니다', 3]),
})
const section = buildGlossaryPromptSection(glossary)
expect(section).toContain('[사용자 용어')
expect(section).toContain('D3RO (다르게 들리면: 디에로)')
expect(section).toContain('[사용자가 실제로 쓰는 표현')
expect(section).toContain('오늘 회의는 세 시에 시작합니다')
})
it('STT 힌트는 기존 문맥 뒤에 붙는다', () => {
const glossary = buildTranscriptGlossary({ dictionary: [{ word: 'Whisper' }] })
expect(appendGlossaryHint('다음은 한국어 대화입니다.', glossary)).toBe(
'다음은 한국어 대화입니다. 용어: Whisper.',
)
expect(appendGlossaryHint('', buildTranscriptGlossary({}))).toBe('')
})
})