> ## Documentation Index
> Fetch the complete documentation index at: https://daily-main.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Mirai Text-to-Speech

> MiraiTTSService streams natural Hindi, Hinglish and Gujarati speech from Mirai's TTS API.

export const CommunityMaintained = ({maintainer, maintainerUrl, repo}) => <Note>
    <strong>Community-maintained integration.</strong> This service is built and
    maintained by{" "}
    <a href={maintainerUrl} target="_blank" rel="noreferrer">
      {maintainer}
    </a>
    . Pipecat does not test or officially support it. Please report issues and
    request changes on the{" "}
    <a href={repo} target="_blank" rel="noreferrer">
      source repository
    </a>
    . Learn more about{" "}
    <a href="/api-reference/server/services/community-integrations">
      community integrations
    </a>
    .
  </Note>;

<CommunityMaintained maintainer="snehmehta" maintainerUrl="https://github.com/snehmehta" repo="https://github.com/MiraiMinds/pipecat-mirai" />

## Overview

`MiraiTTSService` converts text into speech using [Mirai's](https://miraiminds.co)
streaming text-to-speech API, built for Indian languages: Hindi, Hinglish (Devanagari
with English words in Latin script) and Gujarati. Audio streams over HTTP with about
100 ms to first audio, and is resampled from Mirai's 48 kHz to your pipeline's output
rate, including 8 kHz for phone calls.

The package also includes `apply_output_lead()`. It stops audio breaking up on phone
calls over Pipecat's websocket transports when the bot's server is busy, and works
with any TTS service.

<CardGroup cols={2}>
  <Card title="Source Repository" icon="github" href="https://github.com/MiraiMinds/pipecat-mirai">
    Source code, examples, benchmark and issues for the Mirai integration
  </Card>

  <Card title="Mirai" icon="book" href="https://docs.miraiminds.co">
    Learn more about Mirai's text-to-speech API
  </Card>
</CardGroup>

## Installation

This is a community-maintained package distributed separately from `pipecat-ai`:

```bash theme={null}
uv add pipecat-mirai
```

## Prerequisites

### Mirai Account Setup

Before using the Mirai text-to-speech service, you need:

1. **Mirai Account**: Sign up in the [Mirai console](https://sandbox.voice.miraiminds.co)
2. **API Key**: Create an API key (`sk_live_...`) in the console
3. **Voice Selection**: Choose `ashu`, `neha`, `shruti` or `sameer`

### Required Environment Variables

* `MIRAI_API_KEY`: Your Mirai API key for authentication

## Configuration

<ParamField path="api_key" type="str" default="None">
  Mirai API key. Defaults to the `MIRAI_API_KEY` environment variable.
</ParamField>

<ParamField path="settings" type="MiraiTTSService.Settings" default="None">
  Runtime-configurable settings: `voice` (default `"neha"`) and `model` (default `"mira-tts"`).
</ParamField>

<ParamField path="sample_rate" type="int" default="None">
  Output sample rate. Defaults to the pipeline's `audio_out_sample_rate`.
</ParamField>

<ParamField path="base_url" type="str" default="https://sandbox.voice.miraiminds.co/v1">
  API base URL.
</ParamField>

## Usage

```python theme={null}
from pipecat_mirai import MiraiTTSService

tts = MiraiTTSService(
    api_key=os.getenv("MIRAI_API_KEY"),
    settings=MiraiTTSService.Settings(voice="shruti"),
)

pipeline = Pipeline([
    transport.input(),
    stt,
    context_aggregator.user(),
    llm,
    tts,
    transport.output(),
    context_aggregator.assistant(),
])
```

### Phone calls

Pipecat's websocket transports send audio at exactly real time, so a stalled event
loop starves the phone provider and the caller hears the voice break. Let the
transport run slightly ahead:

```python theme={null}
from pipecat_mirai import apply_output_lead

transport = FastAPIWebsocketTransport(websocket, FastAPIWebsocketParams(serializer=serializer, ...))
apply_output_lead(transport)  # up to 0.4 s ahead of real time
```

On 8 kHz Twilio-protocol calls with event-loop stalls, measured speech stretched by
breaks dropped from 6.6% to 0.08% at 3 concurrent calls and from 29.1% to 0.01% at 10.

## Compatibility

Tested with Pipecat v1.8.1 and v1.12.0.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.