Skip to content

Commit ca48933

Browse files
committed
Creating a foundational example which uses the piper service.
1 parent c1f6a4e commit ca48933

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#
2+
# Copyright (c) 2024–2025, Daily
3+
#
4+
# SPDX-License-Identifier: BSD 2-Clause License
5+
#
6+
7+
import asyncio
8+
import os
9+
import sys
10+
11+
import aiohttp
12+
from dotenv import load_dotenv
13+
from loguru import logger
14+
from runner import configure
15+
16+
from pipecat.frames.frames import EndFrame, TTSSpeakFrame
17+
from pipecat.pipeline.pipeline import Pipeline
18+
from pipecat.pipeline.runner import PipelineRunner
19+
from pipecat.pipeline.task import PipelineTask
20+
from pipecat.services.piper import PiperTTSService
21+
from pipecat.transports.services.daily import DailyParams, DailyTransport
22+
23+
load_dotenv(override=True)
24+
25+
logger.remove(0)
26+
logger.add(sys.stderr, level="DEBUG")
27+
28+
29+
async def main():
30+
async with aiohttp.ClientSession() as session:
31+
(room_url, _) = await configure(session)
32+
33+
transport = DailyTransport(
34+
room_url, None, "Say One Thing", DailyParams(audio_out_enabled=True)
35+
)
36+
37+
tts = PiperTTSService(
38+
base_url=os.getenv("PIPER_BASE_URL"), aiohttp_session=session, sample_rate=24000
39+
)
40+
41+
runner = PipelineRunner()
42+
43+
task = PipelineTask(Pipeline([tts, transport.output()]))
44+
45+
# Register an event handler so we can play the audio when the
46+
# participant joins.
47+
@transport.event_handler("on_first_participant_joined")
48+
async def on_first_participant_joined(transport, participant):
49+
await task.queue_frames(
50+
[TTSSpeakFrame(f"Hello there, how are you today ?"), EndFrame()]
51+
)
52+
53+
await runner.run(task)
54+
55+
56+
if __name__ == "__main__":
57+
asyncio.run(main())

0 commit comments

Comments
 (0)