examples: update 10-wake-work.py to use WakeCheckFilter
This commit is contained in:
@@ -12,14 +12,7 @@ import sys
|
|||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from pipecat.frames.frames import (
|
from pipecat.frames.frames import Frame, ImageRawFrame, SpriteFrame
|
||||||
Frame,
|
|
||||||
SystemFrame,
|
|
||||||
TextFrame,
|
|
||||||
ImageRawFrame,
|
|
||||||
SpriteFrame,
|
|
||||||
TranscriptionFrame,
|
|
||||||
)
|
|
||||||
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 PipelineTask
|
from pipecat.pipeline.task import PipelineTask
|
||||||
@@ -27,6 +20,7 @@ from pipecat.processors.aggregators.llm_context import (
|
|||||||
LLMUserContextAggregator,
|
LLMUserContextAggregator,
|
||||||
LLMAssistantContextAggregator,
|
LLMAssistantContextAggregator,
|
||||||
)
|
)
|
||||||
|
from pipecat.processors.filters.wake_check_filter import WakeCheckFilter
|
||||||
from pipecat.processors.frame_processor import FrameDirection, FrameProcessor
|
from pipecat.processors.frame_processor import FrameDirection, FrameProcessor
|
||||||
from pipecat.services.openai import OpenAILLMService
|
from pipecat.services.openai import OpenAILLMService
|
||||||
from pipecat.services.elevenlabs import ElevenLabsTTSService
|
from pipecat.services.elevenlabs import ElevenLabsTTSService
|
||||||
@@ -84,33 +78,6 @@ thinking_list = [
|
|||||||
thinking_frame = SpriteFrame(thinking_list)
|
thinking_frame = SpriteFrame(thinking_list)
|
||||||
|
|
||||||
|
|
||||||
class NameCheckFilter(FrameProcessor):
|
|
||||||
def __init__(self, names: list[str]):
|
|
||||||
super().__init__()
|
|
||||||
self._names = names
|
|
||||||
self._sentence = ""
|
|
||||||
|
|
||||||
async def process_frame(self, frame: Frame, direction: FrameDirection):
|
|
||||||
if isinstance(frame, SystemFrame):
|
|
||||||
await self.push_frame(frame, direction)
|
|
||||||
return
|
|
||||||
|
|
||||||
content: str = ""
|
|
||||||
|
|
||||||
# TODO: split up transcription by participant
|
|
||||||
if isinstance(frame, TranscriptionFrame):
|
|
||||||
content = frame.text
|
|
||||||
self._sentence += content
|
|
||||||
if self._sentence.endswith((".", "?", "!")):
|
|
||||||
if any(name in self._sentence for name in self._names):
|
|
||||||
await self.push_frame(TextFrame(self._sentence))
|
|
||||||
self._sentence = ""
|
|
||||||
else:
|
|
||||||
self._sentence = ""
|
|
||||||
else:
|
|
||||||
await self.push_frame(frame, direction)
|
|
||||||
|
|
||||||
|
|
||||||
class ImageSyncAggregator(FrameProcessor):
|
class ImageSyncAggregator(FrameProcessor):
|
||||||
|
|
||||||
async def process_frame(self, frame: Frame, direction: FrameDirection):
|
async def process_frame(self, frame: Frame, direction: FrameDirection):
|
||||||
@@ -155,17 +122,17 @@ async def main(room_url: str, token):
|
|||||||
|
|
||||||
tma_in = LLMUserContextAggregator(messages)
|
tma_in = LLMUserContextAggregator(messages)
|
||||||
tma_out = LLMAssistantContextAggregator(messages)
|
tma_out = LLMAssistantContextAggregator(messages)
|
||||||
ncf = NameCheckFilter(["Santa Cat", "Santa"])
|
wcf = WakeCheckFilter(["Santa Cat", "Santa"])
|
||||||
|
|
||||||
pipeline = Pipeline([
|
pipeline = Pipeline([
|
||||||
transport.input(),
|
transport.input(), # Transport user input
|
||||||
isa,
|
isa, # Cat talking/quiet images
|
||||||
ncf,
|
wcf, # Filter out speech not directed at Santa Cat
|
||||||
tma_in,
|
tma_in, # User responses
|
||||||
llm,
|
llm, # LLM
|
||||||
tts,
|
tts, # TTS
|
||||||
transport.output(),
|
transport.output(), # Transport bot output
|
||||||
tma_out
|
tma_out # Santa Cat spoken responses
|
||||||
])
|
])
|
||||||
|
|
||||||
@transport.event_handler("on_first_participant_joined")
|
@transport.event_handler("on_first_participant_joined")
|
||||||
|
|||||||
Reference in New Issue
Block a user