Skip to main content

Lokutor Python SDK

Lokutor Hero

Python Version License PyPI Version

The official Python SDK for Lokutor - High-performance, real-time AI voice and TTS. Seamlessly transcribe speech, generate intelligent responses, and synthesize natural speech—all through a unified, production-grade interface.

Features

  • 🎤 Real-time Voice Input - Automatic microphone recording with low-latency voice activity detection
  • 🔊 Natural Speech Output - High-quality text-to-speech synthesis (44.1kHz)
  • 🧠 Intelligent Conversations - LLM-powered responses with context awareness
  • ⚡ Streaming TTS - Ultra-fast synthesis with raw binary WebSocket streaming
  • 🛡️ Production-Ready - Connects directly to Lokutor's secure cloud infrastructure
  • 📚 Simple API - Go from code to conversation in 3 lines

Installation

pip install lokutor

Or from source (for development):

git clone https://github.com/lokutor-ai/lokutor-sdk
cd sdk/python
pip install -e .

Requires PyAudio and websocket-client.

Quick Start

Voice Conversation (Start Speaking!)

from lokutor import VoiceAgentClient
from lokutor.config import VoiceStyle, Language

client = VoiceAgentClient(api_key="your-api-key")
client.start_conversation()

Standalone Text-to-Speech

from lokutor import TTSClient, VoiceStyle

client = TTSClient(api_key="your-api-key")
client.synthesize(
    text="Hello world, this is a test of Lokutor streaming TTS.",
    voice=VoiceStyle.F1,
    play=True
)

Core APIs

1. VoiceAgentClient

Full conversational interface that handles VAD, STT, LLM, and TTS orchestration.

client = VoiceAgentClient(
    api_key="your-key",
    prompt="You are a helpful customer service agent",
    voice=VoiceStyle.F2,
    language=Language.ENGLISH
)
client.start_conversation()

Callbacks:

  • on_transcription(text): Called when your speech is transcribed.
  • on_response(text): Called when the agent's text response is ready.
  • on_error(error): Called when a connection or server error occurs.

2. TTSClient

For converting text to high-quality streaming audio.

client = TTSClient(api_key="your-key")
client.synthesize(
    text="Welcome to our platform",
    voice=VoiceStyle.M2,
    play=True,
    block=True
)

Configuration

Voice Styles

Female Voices Male Voices
VoiceStyle.F1 VoiceStyle.M1
VoiceStyle.F2 VoiceStyle.M2
VoiceStyle.F3 VoiceStyle.M3
VoiceStyle.F4 VoiceStyle.M4
VoiceStyle.F5 VoiceStyle.M5

Supported Languages

  • Language.ENGLISH
  • Language.SPANISH
  • Language.FRENCH
  • Language.PORTUGUESE
  • Language.KOREAN

Usage Examples

Full Conversation with Callbacks

from lokutor import VoiceAgentClient, VoiceStyle

def handle_user_text(text):
    print(f"User said: {text}")

def handle_agent_text(text):
    print(f"Agent replied: {text}")

client = VoiceAgentClient(
    api_key="demo",
    prompt="You are a friendly pirate assistant",
    on_transcription=handle_user_text,
    on_response=handle_agent_text
)

client.start_conversation()

Scripted TTS with Visemes

from lokutor import TTSClient

def handle_visemes(visemes):
    # Perfect for syncing 3D character lip-sync
    print(f"Syncing lips: {visemes}")

client = TTSClient(api_key="demo")
client.synthesize(
    text="Look at my lips moving!",
    visemes=True,
    on_visemes=handle_visemes
)

Troubleshooting

Connection Issues

The SDK connects to wss://api.lokutor.com. Ensure you have an active internet connection and a valid API key. If you encounter authentication errors, double-check your credentials in the Lokutor Dashboard.

PyAudio Installation

If you encounter issues installing pyaudio, you may need to install portaudio first:

  • macOS: brew install portaudio
  • Linux: sudo apt-get install python3-pyaudio or sudo apt-get install portaudio19-dev

License

MIT License

Metadata

Release files for lokutor 1.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lokutor 1.2.3
File Size Uploaded
lokutor-1.2.3.tar.gz 17.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lokutor 1.2.3
File Interpreter ABI Platform
lokutor-1.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 34.3 kB

Release files / lokutor-1.2.3.tar.gz

Download URL lokutor-1.2.3.tar.gz
Size 17.7 kB
Tags Source
SHA-256 checksum
How to use checksums
904e213e9ef2df96f62889a8995fc4cb83fdfd3b182ee2dbd60b60d4a9651fd9
BLAKE2b-256 checksum
How to use checksums
9cde12d70c3aeae4a9ca5ea1095f7c9f9e627e91bb0ca7ccdc2dae72c5ac5a19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.3

Release files / lokutor-1.2.3-py3-none-any.whl

Download URL lokutor-1.2.3-py3-none-any.whl
Size 16.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
868ca9fe5354160f192c30e701ee6c7fd0e6fb683a6cbb2e24da09d243c429d0
BLAKE2b-256 checksum
How to use checksums
e8367e88087c54c52ae81e907795f9baa055b6bdb6e507dbedc8574f44bf1de9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.3

Release history Release notifications | RSS feed

1.4.1

2 release files

1.4.0

2 release files

1.3.0

2 release files

This release

1.2.3 This release

2 release files

1.2.1

2 release files

1.1.42

2 release files

1.1.41

2 release files

1.1.40

2 release files

1.1.39

2 release files

1.1.37

2 release files

1.1.36

2 release files

1.1.35

2 release files

1.1.34

2 release files

1.1.19

2 release files

1.1.15

2 release files

1.1.13

2 release files

1.1.12

2 release files

1.1.11

2 release files

1.1.10

2 release files

1.1.9

2 release files

1.1.8

2 release files

1.1.7

2 release files

1.1.6

1 release file

1.1.5

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page