57 lines
1.5 KiB
Python
57 lines
1.5 KiB
Python
#
|
|
# Copyright (c) 2024, Daily
|
|
#
|
|
# SPDX-License-Identifier: BSD 2-Clause License
|
|
#
|
|
|
|
import asyncio
|
|
import aiohttp
|
|
import os
|
|
import sys
|
|
|
|
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.riva import FastPitchTTSService
|
|
from pipecat.transports.services.daily import DailyParams, DailyTransport
|
|
|
|
from runner import configure
|
|
|
|
from loguru import logger
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv(override=True)
|
|
|
|
logger.remove(0)
|
|
logger.add(sys.stderr, level="DEBUG")
|
|
|
|
|
|
async def main():
|
|
async with aiohttp.ClientSession() as session:
|
|
(room_url, _) = await configure(session)
|
|
|
|
transport = DailyTransport(
|
|
room_url, None, "Say One Thing", DailyParams(audio_out_enabled=True)
|
|
)
|
|
|
|
tts = FastPitchTTSService(api_key=os.getenv("NVIDIA_API_KEY"))
|
|
|
|
runner = PipelineRunner()
|
|
|
|
task = PipelineTask(Pipeline([tts, transport.output()]))
|
|
|
|
# Register an event handler so we can play the audio when the
|
|
# participant joins.
|
|
@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_frames([TTSSpeakFrame(f"Aloha, {participant_name}!"), EndFrame()])
|
|
|
|
await runner.run(task)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|