"""Rewrite transcripts before anything downstream reads them. Sits between the recogniser and the turn aggregator so the substitutions apply whichever speech engine is in use, and so the corrected text is what reaches Claude, the logs, and any future meeting-notes writer alike. """ from loguru import logger from pipecat.frames.frames import Frame, TranscriptionFrame from pipecat.processors.frame_processor import FrameDirection, FrameProcessor from vocabulary import Vocabulary class TranscriptRepair(FrameProcessor): """Apply the vocabulary's repair rules to every transcription.""" def __init__(self, vocabulary: Vocabulary, **kwargs): super().__init__(**kwargs) self._vocabulary = vocabulary async def process_frame(self, frame: Frame, direction: FrameDirection): await super().process_frame(frame, direction) if isinstance(frame, TranscriptionFrame): repaired = self._vocabulary.repair(frame.text) if repaired != frame.text: logger.debug(f"Repaired transcript: {frame.text!r} -> {repaired!r}") frame.text = repaired await self.push_frame(frame, direction)