diff --git a/src/pipecat/services/aws_nova_sonic/aws.py b/src/pipecat/services/aws_nova_sonic/aws.py index 1ef171750..e8da485a8 100644 --- a/src/pipecat/services/aws_nova_sonic/aws.py +++ b/src/pipecat/services/aws_nova_sonic/aws.py @@ -145,6 +145,8 @@ class AWSNovaSonicLLMService(LLMService): self._assistant_is_responding = False self._context_available = False self._ready_to_send_context = False + self._handling_bot_stopped_speaking = False + # # standard AIService frame handling @@ -211,6 +213,11 @@ class AWSNovaSonicLLMService(LLMService): await self._finish_connecting_if_context_available() async def _handle_bot_stopped_speaking(self): + # Protect against back-to-back BotStoppedSpeaking calls, which I've observed + if self._handling_bot_stopped_speaking: + return + self._handling_bot_stopped_speaking = True + if self._assistant_is_responding: # Consider the assistant finished with their response (after a short delay, to allow for # any FINAL text block to come in). @@ -229,6 +236,9 @@ class AWSNovaSonicLLMService(LLMService): await asyncio.sleep(0.25) self._assistant_is_responding = False await self._report_assistant_response_ended() + self._handling_bot_stopped_speaking = False + + self._handling_bot_stopped_speaking = False async def _handle_function_call_result(self, frame: AWSNovaSonicFunctionCallResultFrame): result = frame.result_frame