LiveKit Azure Plugins
livekit-plugins-azure is a Python plugin for the LiveKit Agents framework, providing seamless integration with Azure AI Speech services for Speech-to-Text (STT) and Text-to-Speech (TTS). It is currently at version 1.5.4 and receives frequent updates as part of the broader LiveKit Agents ecosystem.
Common errors
-
azure.core.exceptions.ClientAuthenticationError: Authentication failed.
cause The provided Azure Speech Key (AZURE_SPEECH_KEY) is missing, invalid, or expired.fixVerify that the `AZURE_SPEECH_KEY` environment variable is set correctly and that the key is valid and active in your Azure portal. Also, ensure the key matches the specified region. -
ValueError: Missing one of: speech_host, (speech_key and speech_region), or (speech_auth_token and speech_region)
cause The `azure.STT` or `azure.TTS` constructor did not receive sufficient authentication or endpoint information.fixEnsure that either `speech_host` is provided, or both `speech_key` and `speech_region` are provided (via environment variables or directly as arguments), or both `speech_auth_token` and `speech_region` are provided. -
AttributeError: module 'livekit.plugins.azure' has no attribute 'LLM'
cause Attempting to instantiate an LLM (or use OpenAI-specific STT/TTS) through the `livekit.plugins.azure` package, which only supports Azure Speech services.fixFor Azure OpenAI services (including LLMs or OpenAI-powered STT/TTS endpoints on Azure), you must import from `livekit.plugins.openai` and use its Azure-specific methods (e.g., `openai.responses.LLM.with_azure()`, `openai.STT.with_azure()`, `openai.TTS.with_azure()`).
Warnings
- breaking LiveKit Agents v1.5.0 introduced 'preemptive generation' enabled by default for LLMs and TTS. This can impact latency expectations and resource usage across all agents, including those using Azure plugins. If not desired, it needs to be explicitly disabled during AgentSession initialization.
- gotcha There is a common confusion between `livekit-plugins-azure` and `livekit-plugins-openai`. `livekit-plugins-azure` is for native Azure Speech STT/TTS services. Azure OpenAI (for LLM interactions, or OpenAI-powered STT/TTS endpoints hosted on Azure) requires `livekit-plugins-openai` configured with Azure-specific parameters.
- gotcha Azure Speech authentication primarily relies on `AZURE_SPEECH_KEY` and `AZURE_SPEECH_REGION` environment variables. While `speech_auth_token` can be used, it's typically ephemeral and must be passed programmatically as an argument, not via environment variables.
Install
-
pip install livekit-plugins-azure
Imports
- STT
from livekit.plugins.azure import STT
from livekit.plugins import azure # ... then use azure.STT(...)
- TTS
from livekit.plugins.azure import TTS
from livekit.plugins import azure # ... then use azure.TTS(...)
- LLM
from livekit.plugins import azure # ... then use azure.LLM()
from livekit.plugins import openai # ... then use openai.responses.LLM.with_azure(...)
Quickstart
import os
from livekit.agents import AgentSession, JobContext
from livekit.plugins import azure
async def my_azure_agent(ctx: JobContext):
# Ensure AZURE_SPEECH_KEY and AZURE_SPEECH_REGION are set in your environment
# e.g., via a .env file or directly as environment variables.
speech_key = os.environ.get('AZURE_SPEECH_KEY', '')
speech_region = os.environ.get('AZURE_SPEECH_REGION', '')
if not speech_key or not speech_region:
print("Error: AZURE_SPEECH_KEY and AZURE_SPEECH_REGION environment variables must be set.")
return
session = AgentSession(
ctx,
stt=azure.STT(
speech_key=speech_key,
speech_region=speech_region
),
tts=azure.TTS(
speech_key=speech_key,
speech_region=speech_region,
voice="en-US-JennyNeural" # Specify a voice for TTS
)
# You would typically add an LLM (e.g., from livekit.plugins.openai) here
# llm=openai.responses.LLM.with_azure(...)
)
print("LiveKit Agent session initialized with Azure Speech STT and TTS.")
# Example: Make the agent say something immediately
# await session.easy_reply("Hello, I am an AI agent powered by Azure Speech.")
# This is where your agent's main logic would run
# await session.run()