LiveKit Azure Plugins

1.5.4 · active · verified Thu Apr 16

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

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a LiveKit Agent session using Azure Speech for both Speech-to-Text (STT) and Text-to-Speech (TTS). It requires setting `AZURE_SPEECH_KEY` and `AZURE_SPEECH_REGION` environment variables for authentication.

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()

view raw JSON →