Skip to content

Commit

Permalink
Merge pull request #315 from pipecat-ai/aleix/stop-transcription-error
Browse files Browse the repository at this point in the history
transports(daily): wait until start|stop_transcription are finished
  • Loading branch information
aconchillo authored Jul 23, 2024
2 parents 1676693 + ad5b920 commit 33f0865
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 20 additions & 5 deletions src/pipecat/transports/services/daily.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,7 @@ async def join(self):
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:
Expand All @@ -284,6 +281,17 @@ async def join(self):
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()

Expand Down Expand Up @@ -343,7 +351,7 @@ async def leave(self):
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()
Expand All @@ -360,6 +368,13 @@ async def leave(self):
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()

Expand Down

0 comments on commit 33f0865

Please sign in to comment.