From ad5b9202ab096bc849af418664f2792441e5e933 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Mon, 22 Jul 2024 22:56:12 -0700 Subject: [PATCH] transports(daily): wait until start|stop_transcription are finished Fixes #305 --- CHANGELOG.md | 3 +++ src/pipecat/transports/services/daily.py | 25 +++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2e3fac34..0f5bac054 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - STT services should be using ISO 8601 time format for transcription frames. +- Fix an issue that would cause Daily transport to show a stop transcription + error when actually none occurred. + ## [0.0.37] - 2024-07-22 ### Added diff --git a/src/pipecat/transports/services/daily.py b/src/pipecat/transports/services/daily.py index b1939269b..142a38c02 100644 --- a/src/pipecat/transports/services/daily.py +++ b/src/pipecat/transports/services/daily.py @@ -269,10 +269,7 @@ class DailyTransportClient(EventHandler): logger.info(f"Joined {self._room_url}") if self._token and self._params.transcription_enabled: - logger.info( - f"Enabling transcription with settings {self._params.transcription_settings}") - self._client.start_transcription( - self._params.transcription_settings.model_dump(exclude_none=True)) + await self._start_transcription() await self._callbacks.on_joined(data["participants"]["local"]) else: @@ -284,6 +281,17 @@ class DailyTransportClient(EventHandler): logger.error(error_msg) await self._callbacks.on_error(error_msg) + async def _start_transcription(self): + future = self._loop.create_future() + logger.info(f"Enabling transcription with settings {self._params.transcription_settings}") + self._client.start_transcription( + settings=self._params.transcription_settings.model_dump(exclude_none=True), + completion=lambda error: future.set_result(error) + ) + error = await future + if error: + logger.error(f"Unable to start transcription: {error}") + async def _join(self): future = self._loop.create_future() @@ -343,7 +351,7 @@ class DailyTransportClient(EventHandler): logger.info(f"Leaving {self._room_url}") if self._params.transcription_enabled: - self._client.stop_transcription() + await self._stop_transcription() try: error = await self._leave() @@ -360,6 +368,13 @@ class DailyTransportClient(EventHandler): logger.error(error_msg) await self._callbacks.on_error(error_msg) + async def _stop_transcription(self): + future = self._loop.create_future() + self._client.stop_transcription(completion=lambda error: future.set_result(error)) + error = await future + if error: + logger.error(f"Unable to stop transcription: {error}") + async def _leave(self): future = self._loop.create_future()