From b6f0c16591959d1625e7920dc71c22f0454dfa10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Wed, 6 Nov 2024 12:02:35 -0800 Subject: [PATCH] examples: restore EndFrame() on 01 and 02 foundational --- examples/foundational/01-say-one-thing.py | 15 +++++------ examples/foundational/01a-local-audio.py | 27 +++++++++---------- examples/foundational/02-llm-say-one-thing.py | 10 +++---- 3 files changed, 22 insertions(+), 30 deletions(-) diff --git a/examples/foundational/01-say-one-thing.py b/examples/foundational/01-say-one-thing.py index 50ae1bad2..f0fec28d8 100644 --- a/examples/foundational/01-say-one-thing.py +++ b/examples/foundational/01-say-one-thing.py @@ -9,11 +9,11 @@ import aiohttp import os import sys -from pipecat.frames.frames import EndFrame, TextFrame +from pipecat.frames.frames import EndFrame, TTSSpeakFrame from pipecat.pipeline.pipeline import Pipeline from pipecat.pipeline.task import PipelineTask from pipecat.pipeline.runner import PipelineRunner -from pipecat.services.cartesia import CartesiaHttpTTSService +from pipecat.services.cartesia import CartesiaTTSService from pipecat.transports.services.daily import DailyParams, DailyTransport from runner import configure @@ -36,7 +36,7 @@ async def main(): room_url, None, "Say One Thing", DailyParams(audio_out_enabled=True) ) - tts = CartesiaHttpTTSService( + tts = CartesiaTTSService( api_key=os.getenv("CARTESIA_API_KEY"), voice_id="79a125e8-cd45-4c13-8a67-188112f4dd22", # British Lady ) @@ -50,12 +50,9 @@ async def main(): @transport.event_handler("on_first_participant_joined") async def on_first_participant_joined(transport, participant): participant_name = participant.get("info", {}).get("userName", "") - await task.queue_frame(TextFrame(f"Hello there, {participant_name}!")) - - # Register an event handler to exit the application when the user leaves. - @transport.event_handler("on_participant_left") - async def on_participant_left(transport, participant, reason): - await task.queue_frame(EndFrame()) + await task.queue_frames( + [TTSSpeakFrame(f"Hello there, {participant_name}!"), EndFrame()] + ) await runner.run(task) diff --git a/examples/foundational/01a-local-audio.py b/examples/foundational/01a-local-audio.py index d39e922d7..e62ab1020 100644 --- a/examples/foundational/01a-local-audio.py +++ b/examples/foundational/01a-local-audio.py @@ -9,7 +9,7 @@ import aiohttp import os import sys -from pipecat.frames.frames import TextFrame +from pipecat.frames.frames import EndFrame, TTSSpeakFrame from pipecat.pipeline.pipeline import Pipeline from pipecat.pipeline.runner import PipelineRunner from pipecat.pipeline.task import PipelineTask @@ -28,25 +28,24 @@ logger.add(sys.stderr, level="DEBUG") async def main(): - async with aiohttp.ClientSession() as session: - transport = LocalAudioTransport(TransportParams(audio_out_enabled=True)) + transport = LocalAudioTransport(TransportParams(audio_out_enabled=True)) - tts = CartesiaTTSService( - api_key=os.getenv("CARTESIA_API_KEY"), - voice_id="79a125e8-cd45-4c13-8a67-188112f4dd22", # British Lady - ) + tts = CartesiaTTSService( + api_key=os.getenv("CARTESIA_API_KEY"), + voice_id="79a125e8-cd45-4c13-8a67-188112f4dd22", # British Lady + ) - pipeline = Pipeline([tts, transport.output()]) + pipeline = Pipeline([tts, transport.output()]) - task = PipelineTask(pipeline) + task = PipelineTask(pipeline) - async def say_something(): - await asyncio.sleep(1) - await task.queue_frame(TextFrame("Hello there!")) + async def say_something(): + await asyncio.sleep(1) + await task.queue_frames([TTSSpeakFrame("Hello there, how is it going!"), EndFrame()]) - runner = PipelineRunner() + runner = PipelineRunner() - await asyncio.gather(runner.run(task), say_something()) + await asyncio.gather(runner.run(task), say_something()) if __name__ == "__main__": diff --git a/examples/foundational/02-llm-say-one-thing.py b/examples/foundational/02-llm-say-one-thing.py index 891628415..ba2be607c 100644 --- a/examples/foundational/02-llm-say-one-thing.py +++ b/examples/foundational/02-llm-say-one-thing.py @@ -13,7 +13,7 @@ from pipecat.frames.frames import EndFrame, LLMMessagesFrame from pipecat.pipeline.pipeline import Pipeline from pipecat.pipeline.runner import PipelineRunner from pipecat.pipeline.task import PipelineTask -from pipecat.services.cartesia import CartesiaHttpTTSService +from pipecat.services.cartesia import CartesiaTTSService from pipecat.services.openai import OpenAILLMService from pipecat.transports.services.daily import DailyParams, DailyTransport @@ -37,7 +37,7 @@ async def main(): room_url, None, "Say One Thing From an LLM", DailyParams(audio_out_enabled=True) ) - tts = CartesiaHttpTTSService( + tts = CartesiaTTSService( api_key=os.getenv("CARTESIA_API_KEY"), voice_id="79a125e8-cd45-4c13-8a67-188112f4dd22", # British Lady ) @@ -57,11 +57,7 @@ async def main(): @transport.event_handler("on_first_participant_joined") async def on_first_participant_joined(transport, participant): - await task.queue_frame(LLMMessagesFrame(messages)) - - @transport.event_handler("on_participant_left") - async def on_participant_left(transport, participant, reason): - await task.queue_frame(EndFrame()) + await task.queue_frames([LLMMessagesFrame(messages), EndFrame()]) await runner.run(task)