Each 30-second chunk received the previous chunk's text as initial_prompt, so once one chunk looped on a word the loop became the next chunk's hint and the rest of the file was the same word. A looping chunk is now re-transcribed without the hint, looped text is never carried forward, and runs of 4+ identical phrases or segments are collapsed to one.
103 lines
4.5 KiB
TypeScript
103 lines
4.5 KiB
TypeScript
// 파일 전사: 한 조각이 반복 루프에 빠져도 그 반복이 다음 조각으로 번지지 않는다.
|
|
// (앞 조각 결과를 다음 조각 initial_prompt 로 넘겨, 초반 뒤로는 같은 단어만 되풀이되던 버그)
|
|
|
|
import { EventEmitter } from 'events'
|
|
import fs from 'fs'
|
|
import os from 'os'
|
|
import path from 'path'
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
const LOOP = Array(20).fill('감사합니다').join(' ')
|
|
|
|
const hoisted = vi.hoisted(() => ({
|
|
spawn: vi.fn(),
|
|
transcribe: vi.fn(),
|
|
}))
|
|
vi.mock('child_process', () => ({ spawn: hoisted.spawn }))
|
|
vi.mock('../../../src/main/utils/paths', () => ({ getFfmpegPath: () => '/bundled/ffmpeg.exe' }))
|
|
vi.mock('../../../src/main/services/RuntimeProvisioner', () => ({ getRuntimeProvisioner: () => ({ ensure: vi.fn() }) }))
|
|
vi.mock('../../../src/main/services/LoggerService', () => ({
|
|
getLogger: () => ({ info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() }),
|
|
}))
|
|
vi.mock('../../../src/main/services/ConfigService', () => ({ configGet: vi.fn(() => undefined) }))
|
|
vi.mock('../../../src/main/services/stt/STTManager', () => ({
|
|
getSTTManager: () => ({ transcribe: hoisted.transcribe }),
|
|
}))
|
|
vi.mock('../../../src/main/services/HistoryService', () => ({ getHistoryService: () => ({ create: vi.fn() }) }))
|
|
vi.mock('../../../src/main/services/LicenseService', () => ({
|
|
getLicenseService: () => ({ canUse: () => ({ allowed: true }), promptUpgrade: vi.fn() }),
|
|
}))
|
|
vi.mock('../../../src/main/windows/WindowManager', () => ({ getMainWindow: () => null }))
|
|
|
|
function fakeSpawn(_command: string, args: string[]): EventEmitter {
|
|
const proc = Object.assign(new EventEmitter(), {
|
|
stdout: new EventEmitter(),
|
|
stderr: new EventEmitter(),
|
|
exitCode: null as number | null,
|
|
killed: false,
|
|
kill: () => true,
|
|
})
|
|
queueMicrotask(() => {
|
|
// 90초 = 30초 조각 3개
|
|
if (args.includes('null')) proc.stderr.emit('data', Buffer.from('Duration: 00:01:30.00'))
|
|
if (args.includes('pipe:1')) proc.stdout.emit('data', Buffer.from('pcm'))
|
|
proc.exitCode = 0
|
|
proc.emit('close', 0)
|
|
})
|
|
return proc
|
|
}
|
|
|
|
describe('FileTranscriptionService 반복 루프', () => {
|
|
let inputFile: string
|
|
|
|
beforeEach(() => {
|
|
vi.resetModules()
|
|
vi.clearAllMocks()
|
|
hoisted.spawn.mockImplementation(fakeSpawn)
|
|
inputFile = path.join(os.tmpdir(), `d3ro-ft-loop-${Date.now()}.mp3`)
|
|
fs.writeFileSync(inputFile, 'x')
|
|
})
|
|
|
|
afterEach(() => {
|
|
fs.rmSync(inputFile, { force: true })
|
|
})
|
|
|
|
it('힌트 때문에 반복하면 힌트 없이 다시 전사하고, 반복은 다음 조각 힌트로 넘기지 않는다', async () => {
|
|
const prompts: Array<string | undefined> = []
|
|
const replies = [
|
|
'첫 번째 내용입니다.', // 조각 1
|
|
LOOP, // 조각 2 — 앞 문맥 힌트 때문에 루프
|
|
'두 번째 내용입니다.', // 조각 2 재시도(힌트 없음)
|
|
'세 번째 내용입니다.', // 조각 3
|
|
]
|
|
hoisted.transcribe.mockImplementation(async (_buf: Buffer, opts: { initialPrompt?: string }) => {
|
|
prompts.push(opts.initialPrompt)
|
|
const text = replies[prompts.length - 1]
|
|
return { text, segments: [{ text, start: 0, end: 3 }] }
|
|
})
|
|
|
|
const mod = await import('../../../src/main/services/FileTranscriptionService')
|
|
mod.resetFileTranscriptionServiceForTests()
|
|
const result = await mod.getFileTranscriptionService().startTranscription(inputFile, 'ko')
|
|
|
|
expect(result.fullText).toBe('첫 번째 내용입니다. 두 번째 내용입니다. 세 번째 내용입니다.')
|
|
expect(result.fullText).not.toContain('감사합니다')
|
|
// 재시도는 힌트 없이, 다음 조각은 정상 결과를 힌트로 받는다
|
|
expect(prompts).toEqual([undefined, '첫 번째 내용입니다.', undefined, '두 번째 내용입니다.'])
|
|
})
|
|
|
|
it('다시 들어도 반복이면 한 번으로 줄이고, 다음 조각에는 힌트를 주지 않는다', async () => {
|
|
const prompts: Array<string | undefined> = []
|
|
hoisted.transcribe.mockImplementation(async (_buf: Buffer, opts: { initialPrompt?: string }) => {
|
|
prompts.push(opts.initialPrompt)
|
|
return { text: `회의 시작 ${LOOP}`, segments: [] }
|
|
})
|
|
|
|
const mod = await import('../../../src/main/services/FileTranscriptionService')
|
|
mod.resetFileTranscriptionServiceForTests()
|
|
const result = await mod.getFileTranscriptionService().startTranscription(inputFile, 'ko')
|
|
|
|
expect(result.fullText).toBe('회의 시작 감사합니다 회의 시작 감사합니다 회의 시작 감사합니다')
|
|
expect(prompts.every((p) => p === undefined)).toBe(true)
|
|
})
|
|
})
|