We now distinguish between input and output audio and image frames. We introduce `InputAudioRawFrame`, `OutputAudioRawFrame`, `InputImageRawFrame` and `OutputImageRawFrame` (and other subclasses of those). The input frames usually come from an input transport and are meant to be processed inside the pipeline to generate new frames. However, the input frames will not be sent through an output transport. The output frames can also be processed by any frame processor in the pipeline and they are allowed to be sent by the output transport.
81 lines
2.3 KiB
Python
81 lines
2.3 KiB
Python
#
|
|
# Copyright (c) 2024, Daily
|
|
#
|
|
# SPDX-License-Identifier: BSD 2-Clause License
|
|
#
|
|
|
|
import aiohttp
|
|
import asyncio
|
|
import sys
|
|
|
|
from pipecat.frames.frames import Frame, InputAudioRawFrame, InputImageRawFrame, OutputAudioRawFrame, OutputImageRawFrame
|
|
from pipecat.pipeline.pipeline import Pipeline
|
|
from pipecat.pipeline.runner import PipelineRunner
|
|
from pipecat.pipeline.task import PipelineTask
|
|
from pipecat.processors.frame_processor import FrameDirection, FrameProcessor
|
|
from pipecat.transports.services.daily import DailyTransport, DailyParams
|
|
|
|
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")
|
|
|
|
|
|
class MirrorProcessor(FrameProcessor):
|
|
|
|
async def process_frame(self, frame: Frame, direction: FrameDirection):
|
|
await super().process_frame(frame, direction)
|
|
|
|
if isinstance(frame, InputAudioRawFrame):
|
|
await self.push_frame(OutputAudioRawFrame(
|
|
audio=frame.audio,
|
|
sample_rate=frame.sample_rate,
|
|
num_channels=frame.num_channels)
|
|
)
|
|
elif isinstance(frame, InputImageRawFrame):
|
|
await self.push_frame(OutputImageRawFrame(
|
|
image=frame.image,
|
|
size=frame.size,
|
|
format=frame.format)
|
|
)
|
|
else:
|
|
await self.push_frame(frame, direction)
|
|
|
|
|
|
async def main():
|
|
async with aiohttp.ClientSession() as session:
|
|
(room_url, token) = await configure(session)
|
|
|
|
transport = DailyTransport(
|
|
room_url, token, "Test",
|
|
DailyParams(
|
|
audio_in_enabled=True,
|
|
audio_out_enabled=True,
|
|
camera_out_enabled=True,
|
|
camera_out_is_live=True,
|
|
camera_out_width=1280,
|
|
camera_out_height=720
|
|
)
|
|
)
|
|
|
|
@transport.event_handler("on_first_participant_joined")
|
|
async def on_first_participant_joined(transport, participant):
|
|
transport.capture_participant_video(participant["id"])
|
|
|
|
pipeline = Pipeline([transport.input(), MirrorProcessor(), transport.output()])
|
|
|
|
runner = PipelineRunner()
|
|
|
|
task = PipelineTask(pipeline)
|
|
|
|
await runner.run(task)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|