Merge pull request #2181 from pipecat-ai/pk/fix-aws-nova-sonic-pipeline-freeze

Fix a pipeline freeze when using AWS Nova Sonic. The freeze occurs if…
This commit is contained in:
kompfner
2025-07-10 16:30:55 -04:00
committed by GitHub
2 changed files with 52 additions and 41 deletions

View File

@@ -5,6 +5,14 @@ All notable changes to **Pipecat** will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Fixed
- Fix a pipeline freeze when using AWS Nova Sonic, which would occur if the
user started early, while the bot was still working through
`trigger_assistant_response()`.
## [0.0.75] - 2025-07-08 ## [0.0.75] - 2025-07-08
### Added ### Added

View File

@@ -474,7 +474,6 @@ class AWSNovaSonicLLMService(LLMService):
# If we need to, send assistant response trigger (depends on self._connected_time) # If we need to, send assistant response trigger (depends on self._connected_time)
if self._triggering_assistant_response: if self._triggering_assistant_response:
await self._send_assistant_response_trigger() await self._send_assistant_response_trigger()
self._triggering_assistant_response = False
async def _disconnect(self): async def _disconnect(self):
try: try:
@@ -1105,7 +1104,6 @@ class AWSNovaSonicLLMService(LLMService):
# Send the trigger audio, if we're fully connected and set up # Send the trigger audio, if we're fully connected and set up
if self._connected_time is not None: if self._connected_time is not None:
await self._send_assistant_response_trigger() await self._send_assistant_response_trigger()
self._triggering_assistant_response = False
async def _send_assistant_response_trigger(self): async def _send_assistant_response_trigger(self):
if ( if (
@@ -1113,6 +1111,7 @@ class AWSNovaSonicLLMService(LLMService):
): # should never happen ): # should never happen
return return
try:
logger.debug("Sending assistant response trigger...") logger.debug("Sending assistant response trigger...")
chunk_duration = 0.02 # what we might get from InputAudioRawFrame chunk_duration = 0.02 # what we might get from InputAudioRawFrame
@@ -1156,3 +1155,7 @@ class AWSNovaSonicLLMService(LLMService):
for chunk in audio_chunks: for chunk in audio_chunks:
await self._send_user_audio_event(chunk) await self._send_user_audio_event(chunk)
await asyncio.sleep(chunk_duration) await asyncio.sleep(chunk_duration)
finally:
# We need to clean up in case sending the trigger was cancelled, e.g. in the case of a user interruption.
# (An asyncio.CancelledError would be raised in that case.)
self._triggering_assistant_response = False