Skip to content

LiveKit SDK · livekit-plugins-pyai v0.1.2

Keep LiveKit. Add the PyAI voice layer.

Add Hear and Speak to an existing LiveKit Agents session.

Use pyai.STT() and pyai.TTS() in AgentSession.
Receive audio frames as Speak generates them.
Keep your existing room, LLM, tools, and turn-taking configuration.

From download to working audio

Python 3.10–3.13. Only a PyAI key for the included speech.wav smoke test. A complete room agent also needs LiveKit credentials and your chosen LLM; the linked guide covers that setup.

Terminal · macOS / Linux
curl -fSL https://pyai.com/starters/pyai-livekit.tar.gz -o pyai-livekit.tar.gz
tar -xzf pyai-livekit.tar.gz
cd pyai-livekit
python3 -m venv .venv
. .venv/bin/activate
python -m pip install -r requirements.txt
cp .env.example .env
# Fill in .env, then export its values in this shell:
set -a
. ./.env
set +a
python main.py

Edit the downloaded .env before running. Keep it out of Git. On Windows, use WSL for these shell commands.

What happens when you run it?

This starter tests the TTS adapter without opening a room. LiveKit continues to own your agent loop; the adapter does not create an Omni session.

Take it into your application

Choose a voice from the API catalog and check its language coverage. Reuse clients, consume streaming audio immediately, and cancel interrupted responses. PCM, WAV and G.711 stream; MP3 and Opus are buffered.

The complete entry point

This is the same file included in the download. Copy it here, or get the full project with its dependency and environment files.

main.py
"""Exercise the LiveKit TTS adapter without a room or LLM account."""
import asyncio
import aiohttp
import os
import time
import wave
from livekit.plugins import pyai


async def main():
    session = aiohttp.ClientSession()
    tts = pyai.TTS(voice=os.getenv("PYAI_VOICE", "stock_emma_en_gb"), http_session=session)
    received = 0
    started = time.perf_counter()
    try:
        with wave.open("speech.wav", "wb") as output:
            output.setparams((1, 2, 24000, 0, "NONE", "not compressed"))
            async with tts.synthesize("Hello from PyAI and LiveKit.") as stream:
                async for event in stream:
                    if not received:
                        print(f"First audio frame: {(time.perf_counter() - started) * 1000:.0f} ms")
                    output.writeframesraw(bytes(event.frame.data))
                    received += len(event.frame.data)
        if not received:
            raise RuntimeError("No audio frames received")
        print("Saved speech.wav")
    finally:
        await tts.aclose()
        await session.close()


if __name__ == "__main__":
    asyncio.run(main())

Build with LiveKit in your coding agent

Install Node.js 22+ and your coding agent first. Connect PyAI’s MCP server, then ask it to call get_started. For a sandbox test, ask it to call create_sandbox_key once. Keep live credentials in your environment.

Codex · terminal
codex mcp add pyai -- npx -y @pyai/mcp@0.2.0
Claude Code · terminal
claude mcp add --transport stdio --scope project pyai -- npx -y @pyai/mcp@0.2.0
Cursor · .cursor/mcp.json
{
  "mcpServers": {
    "pyai": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "@pyai/mcp@0.2.0"
      ]
    }
  }
}

Merge the pyai entry into your existing mcpServers configuration. Enable it in Cursor’s MCP settings.

Paste into your coding agent
Read https://pyai.com/skill.md and https://pyai.com/sdks/livekit.md.
Use the matching starter to add PyAI voice to this project.
Keep credentials in environment variables. Run a short synthetic
audio test and report the result and any missing credentials.
Do not place a phone call or send a message unless I ask.

Want a reusable local skill? Copy the Codex and Claude Code skill install commands. Any tool that reads Markdown can use skill.md.

LiveKit SDK questions

What is included in the download?

The LiveKit starter includes its complete entry point, pinned PyAI package version, dependency manifest, environment template, and run instructions.

What do I need before running it?

Only a PyAI key for the included speech.wav smoke test. A complete room agent also needs LiveKit credentials and your chosen LLM; the linked guide covers that setup.

Can I use this with Cursor, Codex or Claude Code?

Yes. Connect the PyAI MCP server and give your agent the LiveKit Markdown guide. It includes the complete starter source and setup commands.

How do I test streaming performance?

Measure first received audio and playback readiness separately in your application. Network location, load, text, and voice affect timing. Playing the saved file does not measure streaming latency.

← Explore all SDKs