> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cartesia.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# LiveKit

<Frame>
  <img src="https://mintcdn.com/cartesia-2650f86a/GOsvXpql8JfAlgjy/assets/images/livekit-agents.png?fit=max&auto=format&n=GOsvXpql8JfAlgjy&q=85&s=40fda2b78d535c4400f96caba840ce88" alt="LiveKit Agents ロゴ" width="1200" height="630" data-path="assets/images/livekit-agents.png" />
</Frame>

LiveKit は、リアルタイムのビデオ・音声・データをプロダクトに組み込むための WebRTC ファーストなプラットフォームです。LiveKit Agents は会話型エージェント向けのフレームワークです。

Cartesia は 2 つの方法で統合できます: [LiveKit Inference](https://docs.livekit.io/agents/models/inference/) とオープンソースのプラグインです。

## LiveKit Inference

LiveKit のインフラ上で Cartesia のモデルを利用できます。API キーと料金は Cartesia ではなく LiveKit によって管理されます。

1. [Cartesia STT に関する LiveKit ドキュメント](https://docs.livekit.io/agents/models/stt/cartesia/)
2. [Cartesia TTS に関する LiveKit ドキュメント](https://docs.livekit.io/agents/models/tts/cartesia/)

## オープンソースプラグイン

オープンソースの LiveKit Agents パッケージとともに利用できるプラグインです。

### Python

`livekit-plugins-cartesia` パッケージをインストールすることで、Python 版 LiveKit Agents で Cartesia を利用できます。
必要に応じて、`livekit/agents` リポジトリの [/livekit-plugins/livekit-plugins-cartesia](https://github.com/livekit/agents/tree/main/livekit-plugins/livekit-plugins-cartesia) ディレクトリでプラグインのソースコードを参照できます。

<Note>
  Ink 2 には `livekit-plugins-cartesia>=1.5.15` が必要です。それより古いバージョンでは、ランタイムエラーは出ずに品質の悪い結果が生成されます。
</Note>

#### 自分のエージェントに Python プラグインをセットアップする

まず、メインの [livekit-agents](https://pypi.org/project/livekit-agents) パッケージと [livekit-plugins-cartesia](https://pypi.org/project/livekit-plugins-cartesia/) をインストールします:

```bash theme={null}
pip install livekit-agents livekit-plugins-cartesia
```

次に、エージェント作成時に Cartesia の STT と TTS プラグインを利用します。

```python theme={null}
from livekit.plugins import cartesia

# using cartesia STT and TTS in a LiveKit agent
session = AgentSession(
    stt=cartesia.STT(
        api_key=os.environ.get("CARTESIA_API_KEY"),
    ),
    tts=cartesia.TTS(
        api_key=os.environ.get("CARTESIA_API_KEY"),
    ),
)
```

#### Python の例を実行する

完全に動作する会話型エージェントについては、`livekit/agents` リポジトリの [/examples/other/cartesia.py](https://github.com/livekit/agents/blob/99d81a1dd3a026ee3e708dcde74ee8c224fc2a57/examples/other/cartesia.py) を参照してください。

```bash theme={null}
# clone and setup livekit/agents
git clone git@github.com:livekit/agents.git
cd agents
uv sync

# run with required API keys:
# - CARTESIA_API_KEY
# - LIVEKIT_URL, LIVEKIT_API_KEY, LIVEKIT_API_SECRET
# -  some LLM provider's API key
uv run examples/other/cartesia.py console
```

### Node.js

`@livekit/agents-plugins-cartesia` パッケージをインストールすることで、Node.js 版 LiveKit Agents で Cartesia を利用できます。
必要に応じて、`livekit/agents-js` リポジトリの [/plugins/cartesia](https://github.com/livekit/agents-js/tree/main/plugins/cartesia) ディレクトリでプラグインのソースコードを参照できます。

<Note>
  LiveKit Agents の Node.js 版はまだ機能が揃っていません。本格的な音声エージェントには Python を使うことをおすすめします。
</Note>

#### 自分のエージェントに Node.js プラグインをセットアップする

まず、メインの [@livekit/agents](https://www.npmjs.com/package/@livekit/agents) パッケージと [@livekit/agents-plugins-cartesia](https://www.npmjs.com/package/@livekit/agents-plugin-cartesia) をインストールします:

```bash theme={null}
npm i @livekit/agents @livekit/agents-plugin-cartesia
```

次に、エージェント作成時に Cartesia の STT と TTS プラグインを利用します。

```typescript theme={null}
import * as cartesia from "@livekit/agents-plugin-cartesia";

// using cartesia STT and TTS in a LiveKit agent
const session = new voice.AgentSession({
  stt: new cartesia.STT({
    apiKey: process.env.CARTESIA_API_KEY,
  }),
  tts: new cartesia.TTS({
    apiKey: process.env.CARTESIA_API_KEY,
  }),
});
```

#### Node.js の例を実行する

完全に動作する会話型エージェントについては、`livekit/agents-js` リポジトリの [/examples/src/cartesia.ts](https://github.com/livekit/agents-js/blob/ee078ec394e697a989bd0faf53aa043392fa7ae4/examples/src/cartesia.ts) を参照してください。

```bash theme={null}
# clone and setup livekit/agents-js
git clone git@github.com:livekit/agents-js.git
cd agents-js
pnpm i && pnpm run build

# run with required API keys:
# - CARTESIA_API_KEY
# - LIVEKIT_URL, LIVEKIT_API_KEY, LIVEKIT_API_SECRET
# -  some LLM provider's API key
node ./examples/src/cartesia.ts dev

# go to https://agents-playground.livekit.io/
# find your agent (make sure you're in the right org)
# then connect to it with WebRTC transport
```

## デモ

<Card title="LiveKit Cartesia デモ" icon="solid link" href="https://cartesia-assistant.vercel.app/">
  LiveKit Agents と Cartesia を使って構築されたシンプルな音声アシスタントを試してみてください。
</Card>

デモの簡易版ソースコードは GitHub の [cartesia-ai/livekit-agents-example](https://github.com/cartesia-ai/livekit-agents-example) リポジトリで公開しています。
