async def test_text_aggregation(self):
        """Test that TTSTextFrames are properly aggregated into a single message"""
        # Create processor
        processor = AssistantTranscriptProcessor()

        # Track received updates
        received_updates: List[TranscriptionUpdateFrame] = []

        @processor.event_handler("on_transcript_update")
        async def handle_update(proc, frame: TranscriptionUpdateFrame):
            received_updates.append(frame)

        # Create test frames simulating bot speaking multiple text chunks
        frames_to_send = [
            BotStartedSpeakingFrame(),
            SleepFrame(sleep=0.1),  # Wait for StartedSpeaking to process
            TTSTextFrame(text="Hello"),
            TTSTextFrame(text="world!"),
            TTSTextFrame(text="How"),
            TTSTextFrame(text="are"),
            TTSTextFrame(text="you?"),
            SleepFrame(sleep=0.1),  # Wait for text frames to queue
            BotStoppedSpeakingFrame(),
        ]

        # Expected order:
        # 1. BotStartedSpeakingFrame (system frame, immediate)
        # 2. All queued TTSTextFrames
        # 3. BotStoppedSpeakingFrame (system frame, immediate)
        # 4. TranscriptionUpdateFrame (after aggregation)
        expected_down_frames = [
            BotStartedSpeakingFrame,
            TTSTextFrame,
            TTSTextFrame,
            TTSTextFrame,
            TTSTextFrame,
            TTSTextFrame,
            BotStoppedSpeakingFrame,
            TranscriptionUpdateFrame,
        ]

        # Run test
        received_frames, _ = await run_test(
            processor,
            frames_to_send=frames_to_send,
            expected_down_frames=expected_down_frames,
        )

        # Verify update was received
        self.assertEqual(len(received_updates), 1)

        # Get the update frame
        update_frame = received_updates[0]

        # Should have one aggregated message
        self.assertEqual(len(update_frame.messages), 1)

        message = update_frame.messages[0]
        self.assertEqual(message.role, "assistant")
        self.assertEqual(message.content, "Hello world! How are you?")

        # Verify timestamp exists
        self.assertIsNotNone(message.timestamp)

        # All frames should be passed through in order, with update at end
        downstream_update = cast(TranscriptionUpdateFrame, received_frames[-1])
        self.assertEqual(downstream_update.messages[0].content, "Hello world! How are you?")
Test that TTSTextFrames are properly aggregated into a single message
tests/test_transcript_processor.py