add nvidia riva - fastpitch

This commit is contained in:
vipyne
2024-12-03 23:03:58 -06:00
parent d74e728332
commit 5a467a30a3
2 changed files with 106 additions and 0 deletions

View File

@@ -0,0 +1,94 @@
#
# Copyright (c) 2024, Daily
#
# SPDX-License-Identifier: BSD 2-Clause License
#
import asyncio
import os
import sys
import aiohttp
from dotenv import load_dotenv
from loguru import logger
from runner import configure
from pipecat.audio.vad.silero import SileroVADAnalyzer
from pipecat.frames.frames import LLMMessagesFrame
from pipecat.pipeline.pipeline import Pipeline
from pipecat.pipeline.runner import PipelineRunner
from pipecat.pipeline.task import PipelineParams, PipelineTask
from pipecat.processors.aggregators.openai_llm_context import OpenAILLMContext
from pipecat.services.deepgram import DeepgramSTTService
from pipecat.services.riva import FastpitchTTSService, ParakeetSTTService
from pipecat.services.openai import OpenAILLMService
from pipecat.transports.services.daily import DailyParams, DailyTransport
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,
"Respond bot",
DailyParams(
audio_out_enabled=True,
vad_enabled=True,
vad_analyzer=SileroVADAnalyzer(),
vad_audio_passthrough=True,
),
)
# stt = DeepgramSTTService(api_key=os.getenv("DEEPGRAM_API_KEY"))
stt = ParakeetSTTService(api_key=os.getenv("NVIDIA_API_KEY"))
tts = FastpitchTTSService(api_key=os.getenv("NVIDIA_API_KEY"))
llm = OpenAILLMService(api_key=os.getenv("OPENAI_API_KEY"), model="gpt-4o")
messages = [
{
"role": "system",
"content": "You are a helpful LLM in a WebRTC call. Your goal is to demonstrate your capabilities in a succinct way. Your output will be converted to audio so don't include special characters in your answers. Respond to what the user said in a creative and helpful way.",
},
]
context = OpenAILLMContext(messages)
context_aggregator = llm.create_context_aggregator(context)
pipeline = Pipeline(
[
transport.input(), # Transport user input
stt, # STT
context_aggregator.user(), # User responses
llm, # LLM
tts, # TTS
transport.output(), # Transport bot output
context_aggregator.assistant(), # Assistant spoken responses
]
)
task = PipelineTask(pipeline, PipelineParams(allow_interruptions=True))
@transport.event_handler("on_first_participant_joined")
async def on_first_participant_joined(transport, participant):
# Kick off the conversation.
messages.append({"role": "system", "content": "Please introduce yourself to the user."})
await task.queue_frames([LLMMessagesFrame(messages)])
runner = PipelineRunner()
await runner.run(task)
if __name__ == "__main__":
asyncio.run(main())

View File

@@ -5,7 +5,11 @@
#
import asyncio
<<<<<<< HEAD
from typing import AsyncGenerator, Optional
=======
from typing import AsyncGenerator, List, Optional, Union, Iterator
>>>>>>> 07e3942e (add nvidia riva - fastpitch)
from loguru import logger
from pydantic.main import BaseModel
@@ -13,6 +17,10 @@ from pydantic.main import BaseModel
from pipecat.frames.frames import (
CancelFrame,
EndFrame,
<<<<<<< HEAD
=======
ErrorFrame,
>>>>>>> 07e3942e (add nvidia riva - fastpitch)
Frame,
InterimTranscriptionFrame,
StartFrame,
@@ -38,7 +46,11 @@ except ModuleNotFoundError as e:
class FastpitchTTSService(TTSService):
class InputParams(BaseModel):
<<<<<<< HEAD
language: Optional[Language] = Language.EN_US
=======
language: Optional[str] = "en-US"
>>>>>>> 07e3942e (add nvidia riva - fastpitch)
def __init__(
self,