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 .

Local microphone/speakers need sounddevice (pip install lokutor[sounddevice], no compiler needed, works on Windows) or PyAudio (lokutor[audio]); the SDK uses whichever works. Without any, pass your own audio stream (see below).

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.

No local audio device / your own audio stream

from lokutor import VoiceAgentClient, QueueAudioIO

io = QueueAudioIO(on_audio=lambda pcm: play(pcm),   # agent speech, 16-bit mono PCM
                  on_clear=lambda: flush_playback())  # the caller interrupted
client = VoiceAgentClient(api_key="...", prompt="...", audio_io=io)
# from your own capture thread (16-bit mono PCM, 16 kHz):
client.send_audio(pcm_bytes)
client.start_conversation()

TTSClient(api_key, audio_io=...) and SpeechToTextClient(..., audio_io=...) take the same. Set LOKUTOR_AUDIO_BACKEND=sounddevice (or pyaudio) to force a backend.

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.7.0

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.7.0
File Size Uploaded Provenance Actions
lokutor-1.7.0.tar.gz 23.1 kB Without provenance Details for lokutor-1.7.0.tar.gz

Built distribution (wheel)

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

Total release size: 44.8 kB

Release files / lokutor-1.7.0.tar.gz

Download URL lokutor-1.7.0.tar.gz
Size 23.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6c08104acf7bd44e7e5cf6e6e52780b8f4a6069da30b1c6311bc6243228fe47f
BLAKE2b-256 checksum
How to use checksums
1f1002e85711af6873de776898bb2a534f9351be256b6c371f694489f7876527
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.11

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

Download URL lokutor-1.7.0-py3-none-any.whl
Size 21.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6041379d759efcb1ac7737493e4e9f29db8b11d639e7b6ffc09a5c076806c619
BLAKE2b-256 checksum
How to use checksums
5fee1ff4ee215d549f81063d3c128f4ecbefa9c853d06feb33fc7aa6c9e6cc86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.11

Security for lokutor 1.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.7.0 This release

2 release files No provenance

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