PipeCat是用于构建语音和多模式对话代理的开源Python框架。它处理了AI服务,网络运输,音频处理和多模式交互的复杂编排,使您专注于创造引人入胜的体验。
想要构建结构化对话?查看管道流以管理复杂的对话状态和过渡。
您可以开始在本地计算机上运行的管道运行,然后在准备就绪时将代理进程移至云中。您还可以添加一个吗?电话号码,?️图像输出,视频输入,使用不同的llms等。
# Install the module
pip install pipecat-ai
# Set up your environment
cp dot-env.template .env为了保持轻量级,默认情况下仅包含核心框架。如果您需要支持第三方AI服务,则可以添加必要的依赖项:
pip install " pipecat-ai[option,...] "可用选项包括:
| 类别 | 服务 | 安装命令示例 |
|---|---|---|
| 语音到文本 | 汇编,天蓝色,深色,格拉德亚,耳语 | pip install "pipecat-ai[deepgram]" |
| LLMS | 人类,天蓝色,烟花,双子座,ollama,openai,一起 | pip install "pipecat-ai[openai]" |
| 文本到语音 | AWS,Azure,Cartesia,Deepgram,Elevenlabs,Google,LMNT,Openai,Playht,Rime,XTTS | pip install "pipecat-ai[cartesia]" |
| 语音到语音 | Openai实时 | pip install "pipecat-ai[openai]" |
| 运输 | 每日(WEBRTC),Websocket,本地 | pip install "pipecat-ai[daily]" |
| 视频 | 塔夫斯 | pip install "pipecat-ai[tavus]" |
| 视觉和图像 | Moondream,Fal | pip install "pipecat-ai[moondream]" |
| 音频处理 | Silero VAD,KRISP,NOISEREDUCE | pip install "pipecat-ai[silero]" |
| 分析与指标 | 规范AI,哨兵 | pip install "pipecat-ai[canonical]" |
查看完整的服务文档→
这是一个非常基本的管道机器人,当用户加入实时会话时,它们会向用户致意。我们将每天用于实时媒体运输,而Cartesia进行文字到语音。
import asyncio
from pipecat . frames . frames import EndFrame , TextFrame
from pipecat . pipeline . pipeline import Pipeline
from pipecat . pipeline . task import PipelineTask
from pipecat . pipeline . runner import PipelineRunner
from pipecat . services . cartesia import CartesiaTTSService
from pipecat . transports . services . daily import DailyParams , DailyTransport
async def main ():
# Use Daily as a real-time media transport (WebRTC)
transport = DailyTransport (
room_url = ...,
token = "" , # leave empty. Note: token is _not_ your api key
bot_name = "Bot Name" ,
params = DailyParams ( audio_out_enabled = True ))
# Use Cartesia for Text-to-Speech
tts = CartesiaTTSService (
api_key = ...,
voice_id = ...
)
# Simple pipeline that will process text to speech and output the result
pipeline = Pipeline ([ tts , transport . output ()])
# Create Pipecat processor that can run one or more pipelines tasks
runner = PipelineRunner ()
# Assign the task callable to run the pipeline
task = PipelineTask ( pipeline )
# Register an event handler to play audio when a
# participant joins the transport WebRTC session
@ transport . event_handler ( "on_first_participant_joined" )
async def on_first_participant_joined ( transport , participant ):
participant_name = participant . get ( "info" , {}). get ( "userName" , "" )
# Queue a TextFrame that will get spoken by the TTS service (Cartesia)
await task . queue_frame ( TextFrame ( f"Hello there, { participant_name } !" ))
# Register an event handler to exit the application when the user leaves.
@ transport . event_handler ( "on_participant_left" )
async def on_participant_left ( transport , participant , reason ):
await task . queue_frame ( EndFrame ())
# Run the pipeline task
await runner . run ( task )
if __name__ == "__main__" :
asyncio . run ( main ())运行它:
python app.py每日提供预构建的WEBRTC用户界面。该应用程序正在运行时,您可以在https://<yourdomain>.daily.co/<room_url>上访问,然后收听bot说话!
Websocket适用于服务器到服务器通信或初始开发。但是对于生产使用,您将需要客户服务器音频来使用设计用于实时媒体运输的协议。 (有关Websockets和Webrtc之间差异的说明,请参阅此帖子。)
快速与WEBRTC快速运行的一种方法是注册每日开发人员帐户。每日为您提供SDK和全球基础架构,以进行音频(和视频)路由。每个帐户每月免费获得10,000个音频/视频/转录分钟。
在此处注册并在开发人员仪表板上创建一个房间。
请注意,在遵循以下说明之前,您可能需要设置虚拟环境。例如,您可能需要从回购的根部运行以下内容:
python3 -m venv venv
source venv/bin/activate从此存储库的根部运行以下内容:
pip install -r dev-requirements.txt
python -m build这构建包裹。要在本地使用软件包(例如运行示例文件),请运行
pip install --editable " .[option,...] "如果要从另一个目录中使用此软件包,则可以运行:
pip install " path_to_this_repo[option,...] "从根目录中,运行:
pytest --doctest-modules --ignore-glob= " *to_be_updated* " --ignore-glob= * pipeline_source * src tests该项目使用严格的PEP 8格式通过ruff格式。
您可以使用use-ackage安装emacs-lazy-ruff包并配置ruff参数:
( use-package lazy-ruff
:ensure t
:hook (( python-mode . lazy-ruff-mode))
:config
( setq lazy-ruff-format-command " ruff format " )
( setq lazy-ruff-only-format-block t )
( setq lazy-ruff-only-format-region t )
( setq lazy-ruff-only-format-buffer t )) ruff已安装在前面描述的venv环境中,因此您应该能够使用PYVENV-AUTO自动加载该环境在EMAC中。
( use-package pyvenv-auto
:ensure t
:defer t
:hook (( python-mode . pyvenv-auto-run)))
安装ruff扩展。然后编辑用户设置( CTRL-SHIFT-P Open User Settings (JSON) )并将其设置为默认的Python Formatter,并在保存上启用格式:
"[python]" : {
"editor.defaultFormatter" : " charliermarsh.ruff " ,
"editor.formatOnSave" : true
}我们欢迎社区的捐款!无论您是修复错误,改进文档还是添加新功能,这都是您可以提供帮助的方法:
在提交拉动请求之前,请检查现有问题和PR,以避免重复。
我们的目标是及时审查所有贡献,并提供建设性的反馈,以帮助您合并更改。
➡️加入我们的不和谐
➡️阅读文档
➡️在x上接触我们