Skip to main content

Official Python SDK for Lokutor - Real-time AI voice and TTS

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lokutor-1.1.37.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lokutor-1.1.37-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file lokutor-1.1.37.tar.gz.

File metadata

  • Download URL: lokutor-1.1.37.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for lokutor-1.1.37.tar.gz
Algorithm Hash digest
SHA256 6318d68a5162a7004907f4022e056cc1eff5d6cbdcffe706c00361a201959f80
MD5 7d06c3753cb0d5c699ce3cb30586318f
BLAKE2b-256 1218b0fab0f3a39495029f8d4ce287b28d7f5474a5497f192f38ef2b9321c1d1

See more details on using hashes here.

File details

Details for the file lokutor-1.1.37-py3-none-any.whl.

File metadata

  • Download URL: lokutor-1.1.37-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for lokutor-1.1.37-py3-none-any.whl
Algorithm Hash digest
SHA256 11049be15be46a2b6d9b993fd84870be4c6c3db9bb973cde9b5a0041510b5203
MD5 dbd2e7c7b73e1a2a09d52d2ded9ae3a1
BLAKE2b-256 460153b1137b1e1e3202457697b651d4061534ec92875e0135c3c4051ac3b7ee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page