Fixing an issue where the BotOutputTransport was discarding the UninterruptibleFrames.
This commit is contained in:
@@ -46,7 +46,11 @@ from pipecat.frames.frames import (
|
|||||||
TTSAudioRawFrame,
|
TTSAudioRawFrame,
|
||||||
TTSStoppedFrame,
|
TTSStoppedFrame,
|
||||||
)
|
)
|
||||||
from pipecat.processors.frame_processor import FrameDirection, FrameProcessor
|
from pipecat.processors.frame_processor import (
|
||||||
|
FrameDirection,
|
||||||
|
FrameProcessor,
|
||||||
|
UninterruptibleProcessQueue,
|
||||||
|
)
|
||||||
from pipecat.transports.base_transport import TransportParams
|
from pipecat.transports.base_transport import TransportParams
|
||||||
from pipecat.utils.time import nanoseconds_to_seconds
|
from pipecat.utils.time import nanoseconds_to_seconds
|
||||||
|
|
||||||
@@ -520,15 +524,21 @@ class BaseOutputTransport(FrameProcessor):
|
|||||||
if not self._transport._allow_interruptions:
|
if not self._transport._allow_interruptions:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Cancel tasks.
|
# Cancel all tasks.
|
||||||
await self._cancel_audio_task()
|
|
||||||
await self._cancel_clock_task()
|
await self._cancel_clock_task()
|
||||||
await self._cancel_video_task()
|
await self._cancel_video_task()
|
||||||
|
|
||||||
|
if self._audio_queue.has_uninterruptible:
|
||||||
|
# Keep the audio task running but drain all interruptible frames
|
||||||
|
# so the pending UninterruptibleFrames are still delivered.
|
||||||
|
self._audio_queue.reset()
|
||||||
|
else:
|
||||||
|
await self._cancel_audio_task()
|
||||||
|
self._create_audio_task()
|
||||||
|
|
||||||
# Create tasks.
|
# Create tasks.
|
||||||
self._create_video_task()
|
self._create_video_task()
|
||||||
self._create_clock_task()
|
self._create_clock_task()
|
||||||
self._create_audio_task()
|
|
||||||
|
|
||||||
# Let's send a bot stopped speaking if we have to.
|
# Let's send a bot stopped speaking if we have to.
|
||||||
await self._bot_stopped_speaking()
|
await self._bot_stopped_speaking()
|
||||||
@@ -612,7 +622,7 @@ class BaseOutputTransport(FrameProcessor):
|
|||||||
def _create_audio_task(self):
|
def _create_audio_task(self):
|
||||||
"""Create the audio processing task."""
|
"""Create the audio processing task."""
|
||||||
if not self._audio_task:
|
if not self._audio_task:
|
||||||
self._audio_queue = asyncio.Queue()
|
self._audio_queue = UninterruptibleProcessQueue()
|
||||||
self._audio_task = self._transport.create_task(self._audio_task_handler())
|
self._audio_task = self._transport.create_task(self._audio_task_handler())
|
||||||
|
|
||||||
async def _cancel_audio_task(self):
|
async def _cancel_audio_task(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user