# Pipecat Integration

[Async](https://async.com/async-voice-api) delivers low‑latency, high‑fidelity text‑to‑speech (TTS) that plugs into Pipecat through our [official integration](https://github.com/pipecat-ai/pipecat/tree/main/src/pipecat/services/asyncai).

Pipecat exposes two Async service classes:

| Service class           | Transport              | Streaming        |
| ----------------------- | ---------------------- | ------------------- | 
| `AsyncAITTSService`     | WebSocket (persistent) | Low-latency chunks  |
| `AsyncAIHttpTTSService` | HTTP (per‑request)     | Response streaming |

> `AsyncAITTSService` is recommended for interactive use because it streams audio chunks as soon as they are ready, minimising time‑to‑first‑byte (TTFB).

---

## Prerequisites

* **Python 3.10 +**
* **Pipecat 0.0.77** or later
* **Async voice API account & API key**
* (Optional) preferred **Async voice ID**

---

## Installation

```bash
pip install "pipecat-ai[asyncai]"
```

Set your API key once:

```bash
export ASYNCAI_API_KEY="sk_************************"
```

---

## Quick‑start (WebSocket)

```python
from pipecat.services.asyncai.tts import AsyncAITTSService
from pipecat import Pipeline
from pipecat.transcriptions.language import Language
import os

# Create the Async WebSocket TTS service
tts = AsyncAITTSService(
    api_key=os.getenv("ASYNCAI_API_KEY"),
    voice_id=os.getenv("ASYNCAI_VOICE_ID"),
    model="async_flash_v1.0",
    params=AsyncAITTSService.InputParams(
        language=Language.EN
    )
)

# Typical Pipecat pipeline
pipeline = Pipeline([
    transport.input(),            # your STT / input transport
    stt,                          # speech‑to‑text
    context_aggregator.user(),
    llm,                          # your LLM responder
    tts,                          # <- Async TTS here!
    transport.output(),           # audio back to the user
    context_aggregator.assistant()
])

await pipeline.run()
```

### Handling interruptions

`AsyncAITTSService` automatically stops synthesis on user interruption or when it receives a `TTSUpdateSettingsFrame`, enabling natural, back‑and‑forth voice experiences.

---

## Troubleshooting

| Symptom                               | Likely cause                    | Fix                                        |
| ------------------------------------- | ------------------------------- | ------------------------------------------ |
| ValueError: Missing ASYNCAI_API_KEY | Env var not exported            | `export ASYNCAI_API_KEY=...`               |
| Long TTFB (>1 s)                      | Using HTTP service / cold start | Switch to WebSocket & keep connection warm |
| ErrorFrame quota exceeded           | Character quota exhausted       | Upgrade plan         |

---

## Next steps

[📖 Read the Pipecat reference](https://docs.pipecat.ai/server/services/tts/asyncai)

[🛠 Browse example code](https://github.com/pipecat-ai/pipecat/blob/main/examples/foundational/07zc-interruptible-asyncai.py)

---

