task: allow specifying heartbeat period

This commit is contained in:
Aleix Conchillo Flaqué
2025-01-21 11:43:21 -08:00
parent dd21b424d6
commit bd6f82cf94
2 changed files with 8 additions and 2 deletions

View File

@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- It is now possible to specify the period of the `PipelineTask` heartbeat
frames with `heartbeats_period_secs`.
### Fixed
- Fixed a type error when using `voice_settings` in `ElevenLabsHttpTTSService`.

View File

@@ -45,6 +45,7 @@ class PipelineParams(BaseModel):
send_initial_empty_metrics: bool = True
report_only_initial_ttfb: bool = False
observers: List[BaseObserver] = []
heartbeats_period_secs: float = HEARTBEAT_SECONDS
class Source(FrameProcessor):
@@ -315,7 +316,7 @@ class PipelineTask:
async def _heartbeat_push_handler(self):
"""
This tasks pushes a heartbeat frame every HEARTBEAT_SECONDS.
This tasks pushes a heartbeat frame every heartbeat period.
"""
while True:
try:
@@ -323,7 +324,7 @@ class PipelineTask:
# task will just stop waiting for the pipeline to finish not
# allowing more frames to be pushed.
await self._source.queue_frame(HeartbeatFrame(timestamp=self._clock.get_time()))
await asyncio.sleep(HEARTBEAT_SECONDS)
await asyncio.sleep(self._params.heartbeats_period_secs)
except asyncio.CancelledError:
break