> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.bakbak.si/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.bakbak.si/_mcp/server.

# LiveKit

`livekit-plugins-bakbak` is the official [LiveKit Agents](https://docs.livekit.io/agents/)
plugin for Bakbak TTS. It streams each sentence of your agent's reply over one
WebSocket as soon as the LLM finishes writing it, so speech starts while the
rest of the reply is still being generated.

#### [PyPI](https://pypi.org/project/livekit-plugins-bakbak/)

`pip install livekit-plugins-bakbak`

#### [Source and examples](https://github.com/raya-voice-ai/livekit-plugins-bakbak)

raya-voice-ai/livekit-plugins-bakbak

## Install

```bash
pip install --pre livekit-plugins-bakbak   # 1.0 is in release candidates
export BAKBAK_API_KEY="raya_..."
```

Requires `livekit-agents` 1.8.7 or newer (below 2.0) and Python 3.10+.

## Use it in an agent

```python
from livekit.agents import AgentSession
from livekit.plugins import bakbak

session = AgentSession(
    tts=bakbak.TTS(
        voice_id="009ae8b5-4a03-492d-af1c-3055989ac734",  # Anika M1
        language="hi",
        model="m1",
    ),
    # stt=..., llm=..., vad=...
)
```

LiveKit calls `prewarm()` when the session starts, which opens the WebSocket
before the first turn.

## Options

| Option        | Default                      |                                                                   |
| ------------- | ---------------------------- | ----------------------------------------------------------------- |
| `api_key`     | `BAKBAK_API_KEY`             | Your API key.                                                     |
| `voice_id`    | Anika M1 (Hindi)             | A voice belongs to one model; see `list_voices()`.                |
| `language`    | `"hi"`                       | Codes, BCP-47 tags and names all work (`hi`, `hi-IN`, `"hindi"`). |
| `model`       | `"m1"`                       | `"m1"` or `"standard"`; must match the voice's model.             |
| `speed`       | not sent (1.0)               | 0.5 to 1.5. Changes `standard` voices only; `m1` ignores it.      |
| `sample_rate` | `24000`                      | `8000`, `16000`, `22050` or `24000` Hz, 16-bit mono PCM.          |
| `transport`   | `"websocket"`                | `"websocket"`, or `"http"` for one SSE request per sentence.      |
| `tokenizer`   | `bakbak.SentenceTokenizer()` | How text is split into requests.                                  |
| `text_pacing` | `False`                      | Batch sentences by how much audio is still queued.                |

Change voice settings at any time; they apply from the next utterance:

```python
tts.update_options(voice_id="...", language="mr", model="standard", speed=1.1)  # a standard Marathi voice
```

## Voices

```python
for voice in await tts.list_voices(model="m1", language="hi"):
    print(voice.id, voice.name)
```

## Sentences

The default `SentenceTokenizer` is built for Indian text. It splits on the danda
(`।`, `॥`) and Latin punctuation, never inside decimals, domains, titles such as
`Dr.` and `डॉ.`, or list markers, and never inside an Indic conjunct. The first
sentence of a reply is sent as soon as it ends. It splits text exactly as the
[Python](/sdks/python) and [JavaScript](/sdks/javascript)
SDKs do.

```python
tts = bakbak.TTS(tokenizer=bakbak.SentenceTokenizer(min_chars=20, eager_first_clause=True))
```

`eager_first_clause=True` also sends the first clause of a long first sentence
on its own, for an earlier start.

## Interruptions and errors

When the user interrupts, the plugin cancels the rest of the reply on the
server and keeps the connection open for the next turn. Errors carry the API's
`error_code` and `request_id` (see [Errors](/text-to-speech/errors)). LiveKit
retries failures before any audio; a failure after audio has started is never
retried, so nothing is spoken twice.

## Migrating from livekit-plugins-raya

`livekit-plugins-bakbak` replaces `livekit-plugins-raya`.

```diff
-pip install livekit-plugins-raya
+pip install livekit-plugins-bakbak
```

```diff
-from livekit.plugins import raya
-tts = raya.TTS(language="hi")
+from livekit.plugins import bakbak
+tts = bakbak.TTS(language="hi")
```

* `BAKBAK_API_KEY` replaces `RAYA_API_KEY` (the old name still works, with a warning).
* One WebSocket replaces one HTTP request per sentence, and audio arrives as
  16-bit PCM, so numpy is no longer needed. The `encoding` and `codec` options are gone.
* The default voice is now Anika M1; pass `voice_id` to keep yours.
* `IndicSentenceTokenizer` is now `SentenceTokenizer` (the old name still works).

The [README](https://github.com/raya-voice-ai/livekit-plugins-bakbak#readme)
covers transports, latency measurements and the plugin's few deliberate
differences from the SDKs.