Getting started on interruptible transport pipeline runner

This commit is contained in:
Moishe Lettvin
2024-03-04 07:51:22 -05:00
parent 763a50f8ec
commit 18e7626b9f
5 changed files with 47 additions and 9 deletions

View File

@@ -21,6 +21,7 @@ from dailyai.pipeline.frames import (
UserStartedSpeakingFrame,
UserStoppedSpeakingFrame
)
from dailyai.pipeline.pipeline import Pipeline
torch.set_num_threads(1)
@@ -166,6 +167,21 @@ class BaseTransportService():
if self._vad_enabled:
self._vad_thread.join()
async def run_pipeline(self, pipeline:Pipeline, allow_interruptions=True):
pipeline.set_sink(self.send_queue)
if not allow_interruptions:
pipeline.set_source(self.receive_queue)
await pipeline.run_pipeline()
else:
source_queue = asyncio.Queue()
pipeline.set_source(source_queue)
pipeline.set_sink(self.send_queue)
pipeline_task = asyncio.create_task(pipeline.run_pipeline())
async for frame in self.get_receive_frames():
await source_queue.put(frame)
def _post_run(self):
# Note that this function must be idempotent! It can be called multiple times