项目简介pipecat是用于构建语音(和多模态)对话代理的框架。诸如私人教练、会议助理、儿童讲故事玩具、客户支持机器人、摄入流程和尖刻的社交伙伴。 
 
语音代理入门您可以开始在本地计算机上运行 Pipecat,然后在准备就绪后将代理进程移动到云中。您还可以添加?电话号码、?️图像输出、?视频输入、使用不同的 LLMs,等等。 # install the modulepip install pipecat-ai
# set up an .env file with API keyscp dot-env.template .env
默认情况下,为了最小化依赖关系,只有基本的框架功能可用。某些第三方 AI 服务需要额外的依赖项,您可以使用这些依赖项进行安装: pipinstall"pipecat-ai[option,...]" 您的项目可能需要也可能不需要这些,因此它们作为可选要求提供。下面是一个列表: AI services:anthropic,azure,fal,moondream,openai,playht,silero,whisper
Transports:local,websocket,daily
代码示例 本地运行的简单语音代理
这是一个非常基本的 Pipecat 机器人,当用户加入实时会话时,它会向他们打招呼。我们将使用 Daily 进行实时媒体传输,并使用 ElevenLabs 进行文本转语音。 #app.py
import asyncioimport aiohttp
from pipecat.frames.frames import EndFrame, TextFramefrom pipecat.pipeline.pipeline import Pipelinefrom pipecat.pipeline.task import PipelineTaskfrom pipecat.pipeline.runner import PipelineRunnerfrom pipecat.services.elevenlabs import ElevenLabsTTSServicefrom pipecat.transports.services.daily import DailyParams, DailyTransport
async def main():async with aiohttp.ClientSession() as session:# Use Daily as a real-time media transport (WebRTC)transport = DailyTransport(room_url=...,token=...,"Bot Name",DailyParams(audio_out_enabled=True))
# Use Eleven Labs for Text-to-Speechtts = ElevenLabsTTSService(aiohttp_session=session,api_key=...,voice_id=...,)
# Simple pipeline that will process text to speech and output the resultpipeline = Pipeline([tts, transport.output()])
# Create Pipecat processor that can run one or more pipelines tasksrunner = PipelineRunner()
# Assign the task callable to run the pipelinetask = PipelineTask(pipeline)
# Register an event handler to play audio when a# participant joins the transport WebRTC session@transport.event_handler("on_participant_joined")async def on_new_participant_joined(transport, participant):participant_name = participant["info"]["userName"] or ''# Queue a TextFrame that will get spoken by the TTS service (Eleven Labs)await task.queue_frames([TextFrame(f"Hello there, {participant_name}!"), EndFrame()])
# Run the pipeline taskawait runner.run(task)
if __name__ == "__main__":asyncio.run(main())
运行它: Daily 提供预构建的 WebRTC 用户界面。在应用程序运行时,您可以访问https://<yourdomain>.daily.co/<room_url>并听机器人打招呼! 用于生产的 WebRTCWebSocket 非常适合服务器到服务器的通信或初始开发。但对于生产用途,您需要客户端-服务器音频才能使用专为实时媒体传输而设计的协议。(有关 WebSockets 和 WebRTC 之间区别的解释,请参阅这篇文章。 快速启动和运行WebRTC的一种方法是注册一个Daily开发者帐户。Daily 为您提供用于音频(和视频)路由的 SDK 和全球基础设施。每个帐户每月可免费获得 10,000 分钟的音频/视频/转录时间。 在此处注册并在开发者仪表板中创建房间。 什么是VAD?语音活动检测 — 对于了解用户何时完成与机器人的通话非常重要。如果您不使用按压通话,并希望 Pipecat 检测用户何时完成通话,VAD 是自然感觉对话的重要组成部分。 Pipecast 在使用 WebRTC 传输层时默认使用 WebRTC VAD。或者,您可以使用Silero VAD来提高精度,但代价是CPU使用率更高。 pipinstallpipecat-ai[silero] 首次使用 Silero 运行机器人时,启动可能需要一段时间,同时在后台下载和缓存模型。您可以在控制台中查看此操作的进度。 黑客攻击框架本身请注意,在按照以下说明操作之前,您可能需要设置虚拟环境。例如,您可能需要从存储库的根目录运行以下命令: python3-mvenvvenvsourcevenv/bin/activate 在此存储库的根目录下,运行以下命令: pipinstall-rdev-requirements.txt-r{env}-requirements.txtpython-mbuild这将生成包。若要在本地使用包(例如运行示例文件),请运行 运行测试从根目录中,运行: pytest--doctest-modules--ignore-glob="*to_be_updated*"srctests
https://github.com/pipecat-ai/pipecat
|