diff --git a/changelog/3604.fixed.md b/changelog/3604.fixed.md new file mode 100644 index 000000000..257e1c630 --- /dev/null +++ b/changelog/3604.fixed.md @@ -0,0 +1 @@ +- Fixed an issue in the `IVRNavigator` where the `TextFrame`s pushed had incorrect spacing. Now, the internal `IVRProcessor` pushes `AggregatedTextFrame`s when in conversation mode. This allows for controlling spacing of the outputted, aggregated text. \ No newline at end of file diff --git a/src/pipecat/extensions/ivr/ivr_navigator.py b/src/pipecat/extensions/ivr/ivr_navigator.py index 0c299d634..64a6d0942 100644 --- a/src/pipecat/extensions/ivr/ivr_navigator.py +++ b/src/pipecat/extensions/ivr/ivr_navigator.py @@ -18,6 +18,7 @@ from loguru import logger from pipecat.audio.dtmf.types import KeypadEntry from pipecat.audio.vad.vad_analyzer import VADParams from pipecat.frames.frames import ( + AggregatedTextFrame, EndFrame, Frame, LLMContextFrame, @@ -153,13 +154,19 @@ class IVRProcessor(FrameProcessor): # Process text through the pattern aggregator async for result in self._aggregator.aggregate(frame.text): # Push aggregated text that doesn't contain XML patterns - await self.push_frame(LLMTextFrame(result.text), direction) + await self.push_frame( + AggregatedTextFrame(text=result.text, aggregated_by=result.type), + direction, + ) elif isinstance(frame, (LLMFullResponseEndFrame, EndFrame)): # Flush any remaining text from the aggregator remaining = await self._aggregator.flush() if remaining: - await self.push_frame(LLMTextFrame(remaining.text), direction) + await self.push_frame( + AggregatedTextFrame(text=remaining.text, aggregated_by=remaining.type), + direction, + ) # Push the end frame await self.push_frame(frame, direction) diff --git a/tests/test_ivr_navigation.py b/tests/test_ivr_navigation.py index ee43bdf62..e1737437a 100644 --- a/tests/test_ivr_navigation.py +++ b/tests/test_ivr_navigation.py @@ -10,6 +10,7 @@ from unittest.mock import AsyncMock from pipecat.audio.vad.vad_analyzer import VADParams from pipecat.extensions.ivr.ivr_navigator import IVRProcessor from pipecat.frames.frames import ( + AggregatedTextFrame, LLMFullResponseEndFrame, LLMMessagesUpdateFrame, LLMTextFrame, @@ -339,7 +340,7 @@ class TestIVRNavigation(unittest.IsolatedAsyncioTestCase): ] expected_down_frames = [ - LLMTextFrame, # Should pass through unchanged + AggregatedTextFrame, # LLMTextFrames aggregrated and converted to AggregatedTextFrame LLMFullResponseEndFrame, ]