export const MIN_UTTERANCE_CHARS = 3; export function isMeaningfulTranscript(text) { const value = String(text || '').trim(); if (!value || /\[no speech detected\]|\[blank_audio\]/i.test(value)) return false; if (/^\[[^\]]+\]$/.test(value)) return false; return value.replace(/[^\p{L}\p{N}]/gu, '').length >= MIN_UTTERANCE_CHARS; } export class SentenceBuffer { constructor({ onSentence } = {}) { this.onSentence = onSentence; this.pending = ''; } push(text) { this.pending += String(text || ''); const sentences = []; let match; while ((match = this.pending.match(/^(.+?[.!?](?:["')\]]+)?)(?:\s+|$)/s))) { sentences.push(match[1].trim()); this.pending = this.pending.slice(match[0].length); } for (const sentence of sentences) this.onSentence?.(sentence); return sentences; } flush() { const value = this.pending.trim(); this.pending = ''; if (value) this.onSentence?.(value); return value; } clear() { this.pending = ''; } }