Skip to main content

Microsoft AI TTS plugin guide

How to use the Microsoft AI TTS plugin for LiveKit Agents.

Available inPython

Overview

This plugin allows you to use MAI voices  from Microsoft AI as a TTS provider for your voice agents. The plugin synthesizes speech with the Azure Speech REST API.

Installation

Install the plugin from PyPI:

uv add "livekit-agents[microsoft-ai]~=1.8"

Authentication

The plugin requires an Azure Speech  resource key and region. Set the following environment variables in your .env file:

MICROSOFT_AI_TTS_API_KEY=<your-speech-resource-key>
MICROSOFT_AI_TTS_REGION=<your-speech-region>

Usage

Use Microsoft AI TTS in an AgentSession or as a standalone speech generator. For example, you can use this TTS in the Voice AI quickstart.

from livekit.agents import AgentSession
from livekit.plugins import microsoft_ai
session = AgentSession(
tts=microsoft_ai.TTS(
voice="en-US-Harper",
model="MAI-Voice-2-Flash",
sample_rate=24000,
),
# ... llm, stt, etc.
)
Default values

The plugin has no default model, voice, or sample rate. Set each one in the constructor or with its environment variable.

Parameters

This section describes some of the available parameters. See the plugin reference for a complete list of all available parameters.

voice
Required
stringEnv: MICROSOFT_AI_TTS_VOICE

Voice name, for example en-US-Harper. The plugin appends model to form the voice ID. You can also pass a full voice ID such as en-US-Harper:MAI-Voice-2-Flash.

model
Required
stringEnv: MICROSOFT_AI_TTS_MODEL

MAI voice model, for example MAI-Voice-2-Flash. Optional when voice is a full voice ID. If you set both, the model must match the suffix of voice (case-insensitive).

sample_rate
Required
integerEnv: MICROSOFT_AI_TTS_SAMPLE_RATE

Output sample rate in Hz. Valid values are 8000, 22050, 24000, 44100, and 48000.

languagestringDefault: en-US

Language tag for the SSML request.

regionstringEnv: MICROSOFT_AI_TTS_REGION

Azure Speech region, for example eastus. Required unless you set url.

urlstringEnv: MICROSOFT_AI_TTS_URL

Full synthesis endpoint URL. Use this parameter for sovereign clouds or custom endpoints. This value overrides region.

Additional resources

The following resources provide more information about using Microsoft AI with LiveKit Agents.