future-stone-69754
08/04/2025, 6:12 AMopenai plugin.
Install the plugin from PyPI:
pip install "livekit-agents[openai]~=1.0"
Authentication
The Azure OpenAI TTS requires authentication
using an API key or a managed identity.
Set the following environment variables in your .env file:
AZURE_OPENAI_API_KEY=<azure-openai-api-key>
AZURE_OPENAI_AD_TOKEN=<azure-openai-ad-token>
AZURE_OPENAI_ENDPOINT=<azure-openai-endpoint>
Usage
Use Azure OpenAI TTS within an AgentSession or as a standalone speech generator. For example, you can use this TTS in the Voice AI quickstart.
from livekit.plugins import openai
session = AgentSession(
tts=openai.TTS.with_azure(
model="gpt-4o-mini-tts",
voice="coral",
)
# ... llm, stt, etc.
)tall-airline-16756
08/04/2025, 6:12 AMtall-airline-16756
08/04/2025, 6:13 AMAZURE_OPENAI_AD_TOKEN with the obtained token.
Ensure the token has the necessary permissions and is securely handled. For more details, refer to Azure's official documentation on obtaining an AD token.future-stone-69754
08/04/2025, 6:30 AMtall-airline-16756
08/04/2025, 6:31 AMAZURE_OPENAI_AD_TOKEN. You can use either the API key or the Active Directory token to sign in—no need for both. Hope that helps!
Sources: Azure OpenAI STT integration guide | LiveKit Docs