Skip to content

Commit 101f671

Browse files
committed
fix(transcription): only drop standalone music/applause tags, not real lines
1 parent 519c1a5 commit 101f671

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

src/domain/transcription/services/HallucinationFilter.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,21 @@ const BLOCKLIST = [
2222
'applause',
2323
].map(normalize);
2424

25+
const matchesHallucination = (normalizedLine: string): boolean =>
26+
BLOCKLIST.some((b) =>
27+
b.includes(' ') ? normalizedLine === b || normalizedLine.includes(b) : normalizedLine === b,
28+
);
29+
2530
export class HallucinationFilter {
2631
clean(text: string): string {
27-
const kept = text
32+
return text
2833
.split('\n')
2934
.filter((line) => {
3035
const n = normalize(line);
3136
if (n.length === 0) return false;
32-
return !BLOCKLIST.some((b) => n === b || n.includes(b));
33-
});
34-
return kept.join('\n').trim();
37+
return !matchesHallucination(n);
38+
})
39+
.join('\n')
40+
.trim();
3541
}
3642
}

test/domain/transcription/HallucinationFilter.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,13 @@ describe('HallucinationFilter', () => {
1818
it('returns the text unchanged when there is no hallucination', () => {
1919
expect(filter.clean('Let us start the meeting.')).toBe('Let us start the meeting.');
2020
});
21+
22+
it('keeps real speech that merely mentions a blocklisted common word', () => {
23+
expect(filter.clean('The background music was too loud.')).toBe('The background music was too loud.');
24+
});
25+
26+
it('still drops standalone music/applause tags', () => {
27+
expect(filter.clean('[Music]')).toBe('');
28+
expect(filter.clean('Aplausos')).toBe('');
29+
});
2130
});

0 commit comments

Comments
 (0)