66 lines
1.6 KiB
Python
66 lines
1.6 KiB
Python
#
|
|
# Copyright (c) 2024, Daily
|
|
#
|
|
# SPDX-License-Identifier: BSD 2-Clause License
|
|
#
|
|
|
|
import aiohttp
|
|
import asyncio
|
|
import os
|
|
import sys
|
|
|
|
from pipecat.frames.frames import Frame, TranscriptionFrame
|
|
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.services.deepgram import DeepgramSTTService, LiveOptions, Language
|
|
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")
|
|
|
|
|
|
class TranscriptionLogger(FrameProcessor):
|
|
async def process_frame(self, frame: Frame, direction: FrameDirection):
|
|
await super().process_frame(frame, direction)
|
|
|
|
if isinstance(frame, TranscriptionFrame):
|
|
print(f"Transcription: {frame.text}")
|
|
|
|
|
|
async def main():
|
|
async with aiohttp.ClientSession() as session:
|
|
(room_url, _) = await configure(session)
|
|
|
|
transport = DailyTransport(
|
|
room_url, None, "Transcription bot", DailyParams(audio_in_enabled=True)
|
|
)
|
|
|
|
stt = DeepgramSTTService(
|
|
api_key=os.getenv("DEEPGRAM_API_KEY"),
|
|
# live_options=LiveOptions(language=Language.FR),
|
|
)
|
|
|
|
tl = TranscriptionLogger()
|
|
|
|
pipeline = Pipeline([transport.input(), stt, tl])
|
|
|
|
task = PipelineTask(pipeline)
|
|
|
|
runner = PipelineRunner()
|
|
|
|
await runner.run(task)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|