Metadata-Version: 2.5
Name: livekit-plugins-assemblyai
Version: 1.9.0
Summary: Agent Framework plugin for AssemblyAI
Project-URL: Documentation, https://docs.livekit.io
Project-URL: Website, https://livekit.io/
Project-URL: Source, https://github.com/livekit/agents
Author-email: LiveKit <hello@livekit.io>
License-Expression: Apache-2.0
Keywords: ai,audio,livekit,realtime,video,voice,webrtc
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Topic :: Multimedia :: Sound/Audio
Classifier: Topic :: Multimedia :: Video
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10.0
Requires-Dist: livekit-agents>=1.9.0
Description-Content-Type: text/markdown

# AssemblyAI plugin for LiveKit Agents

Support for Streaming Speech-to-Text and Streaming Text-to-Speech from AssemblyAI.

More information is available in the docs for the [STT](https://docs.livekit.io/agents/integrations/stt/assemblyai/) integration and for AssemblyAI's [Streaming TTS](https://www.assemblyai.com/docs/tts/getting-started/quickstart).

## Installation

```bash
pip install livekit-plugins-assemblyai
```

## Pre-requisites

You'll need to specify an AssemblyAI API Key. It can be set as environment variable: `ASSEMBLYAI_API_KEY`.

## Usage

```python
from livekit.agents import AgentSession, TurnHandlingOptions
from livekit.plugins import assemblyai

session = AgentSession(
    stt=assemblyai.STT(model="assemblyai-stt-3-7-realtime-agent", mode="balanced"),
    tts=assemblyai.TTS(
        model="assemblyai-tts-1",
        voice="49c443a4-8a1d-5f7e-b70b-98bdbd9823c3",  # Audrey
    ),
    # let AssemblyAI decide when the user has finished speaking
    turn_handling=TurnHandlingOptions(turn_detection="stt"),
    # use the TTS word timings for the transcript and for what an interrupted reply said
    use_tts_aligned_transcript=True,
    # ... llm, vad, etc.
)
```

### Speech-to-text

`assemblyai.STT` streams AssemblyAI-STT-3.7-Realtime-Agent by default (`model`). Useful options:

- `mode`: `"min_latency"`, `"balanced"`, `"max_accuracy"` or `"manual"` (see below).
- `language_codes`: steer transcription toward one or more expected languages (`"es"` or
  `["en", "es"]`).
- `prompt`: context about the audio, such as its domain or scenario, to help recognize likely
  vocabulary (up to 1,750 characters).
- `keyterms_prompt`: names and terms the model should get right.

#### Manual mode

To let a LiveKit turn detector decide when the user is done, set `mode="manual"`. AssemblyAI then
doesn't end turns on short pauses. When LiveKit ends the turn, the plugin sends AssemblyAI a
`ForceEndpoint` and gets that turn's final transcript back right away.

```python
from livekit.agents import AgentSession, TurnHandlingOptions, inference
from livekit.plugins import assemblyai

session = AgentSession(
    stt=assemblyai.STT(model="assemblyai-stt-3-7-realtime-agent", mode="manual"),
    vad=inference.VAD(),
    turn_handling=TurnHandlingOptions(turn_detection=inference.TurnDetector()),
    # ... llm, tts, etc.
)
```

Manual mode needs `assemblyai-stt-3-7-realtime-agent` and a LiveKit turn detector or VAD turn
detection, and doesn't support `speaker_labels` yet. Leave `min_turn_silence` unset. `max_turn_silence` (10 s by default) only ends a turn
when LiveKit never does. See
[manual mode](https://www.assemblyai.com/docs/streaming/turn-detection#manual-mode).

### Text-to-speech

`assemblyai.TTS` streams speech over a pooled WebSocket and cancels in-flight audio when the user
interrupts. Useful options:

- `voice`: a voice's id, from the [voice library](https://www.assemblyai.com/docs/tts/voices)
  or a custom (cloned) voice; defaults to Audrey. Slugs such as `"aai-linda-3"` also work, but
  can change, while ids don't.
- `language`: a code such as `"es"`, set independently of the voice.
- `model`: defaults to `assemblyai-tts-1`.
- `base_url`: the US data zone by default; `wss://tts.eu.assemblyai.com` keeps data in the EU.
- `word_timestamps`: per-word timings (default `True`). With
  `AgentSession(use_tts_aligned_transcript=True)`, LiveKit uses them to sync the transcript and to
  record an interrupted reply up to the word the user heard.

Call `tts.prewarm()` to open the session before the first reply.
