From 94823ab95258924e01e6b60a887efe692f0249b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Mon, 24 Jun 2024 14:56:24 -0700 Subject: [PATCH] transports(daily): always check size of read audio frames --- CHANGELOG.md | 7 +++++++ pyproject.toml | 2 +- src/pipecat/transports/base_input.py | 2 +- src/pipecat/transports/services/daily.py | 17 ++++++++--------- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ab6d2b55..c85d9685a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ 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/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Fixed + +- Fixed a Daily transport blocking situation that occurred while reading audio + frames after a participant left the room. Needs daily-python >= 0.10.1. + ## [0.0.32] - 2024-06-22 ### Added diff --git a/pyproject.toml b/pyproject.toml index d5b28e3ad..4b5a85319 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,7 +37,7 @@ Website = "https://pipecat.ai" anthropic = [ "anthropic~=0.25.7" ] azure = [ "azure-cognitiveservices-speech~=1.37.0" ] cartesia = [ "numpy~=1.26.0", "sounddevice", "cartesia" ] -daily = [ "daily-python~=0.10.0" ] +daily = [ "daily-python~=0.10.1" ] deepgram = [ "deepgram-sdk~=3.2.7" ] examples = [ "python-dotenv~=1.0.0", "flask~=3.0.3", "flask_cors~=4.0.1" ] fal = [ "fal-client~=0.4.0" ] diff --git a/src/pipecat/transports/base_input.py b/src/pipecat/transports/base_input.py index cb7be5d55..4f906149d 100644 --- a/src/pipecat/transports/base_input.py +++ b/src/pipecat/transports/base_input.py @@ -55,7 +55,7 @@ class BaseInputTransport(FrameProcessor): async def push_audio_frame(self, frame: AudioRawFrame): if self._params.audio_in_enabled or self._params.vad_enabled: - self._audio_in_queue.put_nowait(frame) + await self._audio_in_queue.put(frame) # # Frame processor diff --git a/src/pipecat/transports/services/daily.py b/src/pipecat/transports/services/daily.py index 9fdf9dab1..13c8dbce6 100644 --- a/src/pipecat/transports/services/daily.py +++ b/src/pipecat/transports/services/daily.py @@ -209,19 +209,18 @@ class DailyTransportClient(EventHandler): async def read_next_audio_frame(self) -> AudioRawFrame | None: sample_rate = self._params.audio_in_sample_rate num_channels = self._params.audio_in_channels + num_frames = int(sample_rate / 100) * 2 # 20ms of audio - if self._other_participant_has_joined: - num_frames = int(sample_rate / 100) * 2 # 20ms of audio - - future = self._loop.create_future() - self._speaker.read_frames(num_frames, completion=completion_callback(future)) - audio = await future + future = self._loop.create_future() + self._speaker.read_frames(num_frames, completion=completion_callback(future)) + audio = await future + if len(audio) > 0: return AudioRawFrame(audio=audio, sample_rate=sample_rate, num_channels=num_channels) else: - # If no one has ever joined the meeting `read_frames()` would block, - # instead we just wait a bit. daily-python should probably return - # silence instead. + # If we don't read any audio it could be there's no participant + # connected. daily-python will return immediately if that's the + # case, so let's sleep for a little bit (i.e. busy wait). await asyncio.sleep(0.01) return None