Merge pull request #315 from pipecat-ai/aleix/stop-transcription-error

transports(daily): wait until start|stop_transcription are finished
This commit is contained in:
Aleix Conchillo Flaqué
2024-07-23 11:18:59 -07:00
committed by GitHub
2 changed files with 23 additions and 5 deletions

View File

@@ -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

View File

@@ -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()