DeepgramSTTService pushes user started/stopped speaking and interruption frames
This commit is contained in:
committed by
Aleix Conchillo Flaqué
parent
30e6a33930
commit
c28ed2206c
1
changelog/xxx.changed.md
Normal file
1
changelog/xxx.changed.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
- Updated `DeepgramSTTService` to push user started/stopped speaking and interruption frames when `vad_enabled` is set to true. This centralizes the frames into the service, removing the need to have your application code handle Deepgram's events and push these frames.
|
||||||
@@ -11,12 +11,7 @@ from deepgram import LiveOptions
|
|||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from pipecat.frames.frames import (
|
from pipecat.frames.frames import LLMRunFrame
|
||||||
InterruptionFrame,
|
|
||||||
LLMRunFrame,
|
|
||||||
UserStartedSpeakingFrame,
|
|
||||||
UserStoppedSpeakingFrame,
|
|
||||||
)
|
|
||||||
from pipecat.pipeline.pipeline import Pipeline
|
from pipecat.pipeline.pipeline import Pipeline
|
||||||
from pipecat.pipeline.runner import PipelineRunner
|
from pipecat.pipeline.runner import PipelineRunner
|
||||||
from pipecat.pipeline.task import PipelineParams, PipelineTask
|
from pipecat.pipeline.task import PipelineParams, PipelineTask
|
||||||
@@ -103,14 +98,6 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
|
|||||||
idle_timeout_secs=runner_args.pipeline_idle_timeout_secs,
|
idle_timeout_secs=runner_args.pipeline_idle_timeout_secs,
|
||||||
)
|
)
|
||||||
|
|
||||||
@stt.event_handler("on_speech_started")
|
|
||||||
async def on_speech_started(stt, *args, **kwargs):
|
|
||||||
await task.queue_frames([UserStartedSpeakingFrame(), InterruptionFrame()])
|
|
||||||
|
|
||||||
@stt.event_handler("on_utterance_end")
|
|
||||||
async def on_utterance_end(stt, *args, **kwargs):
|
|
||||||
await task.queue_frames([UserStoppedSpeakingFrame()])
|
|
||||||
|
|
||||||
@transport.event_handler("on_client_connected")
|
@transport.event_handler("on_client_connected")
|
||||||
async def on_client_connected(transport, client):
|
async def on_client_connected(transport, client):
|
||||||
logger.info(f"Client connected")
|
logger.info(f"Client connected")
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ from pipecat.frames.frames import (
|
|||||||
InterimTranscriptionFrame,
|
InterimTranscriptionFrame,
|
||||||
StartFrame,
|
StartFrame,
|
||||||
TranscriptionFrame,
|
TranscriptionFrame,
|
||||||
|
UserStartedSpeakingFrame,
|
||||||
|
UserStoppedSpeakingFrame,
|
||||||
VADUserStartedSpeakingFrame,
|
VADUserStartedSpeakingFrame,
|
||||||
VADUserStoppedSpeakingFrame,
|
VADUserStoppedSpeakingFrame,
|
||||||
)
|
)
|
||||||
@@ -271,9 +273,12 @@ class DeepgramSTTService(STTService):
|
|||||||
async def _on_speech_started(self, *args, **kwargs):
|
async def _on_speech_started(self, *args, **kwargs):
|
||||||
await self.start_metrics()
|
await self.start_metrics()
|
||||||
await self._call_event_handler("on_speech_started", *args, **kwargs)
|
await self._call_event_handler("on_speech_started", *args, **kwargs)
|
||||||
|
await self.broadcast_frame(UserStartedSpeakingFrame)
|
||||||
|
await self.push_interruption_task_frame_and_wait()
|
||||||
|
|
||||||
async def _on_utterance_end(self, *args, **kwargs):
|
async def _on_utterance_end(self, *args, **kwargs):
|
||||||
await self._call_event_handler("on_utterance_end", *args, **kwargs)
|
await self._call_event_handler("on_utterance_end", *args, **kwargs)
|
||||||
|
await self.broadcast_frame(UserStoppedSpeakingFrame)
|
||||||
|
|
||||||
@traced_stt
|
@traced_stt
|
||||||
async def _handle_transcription(
|
async def _handle_transcription(
|
||||||
|
|||||||
Reference in New Issue
Block a user