Skip to main content

Voice Agent (Conversational AI)

The VoiceAgentClient in the Python SDK includes built-in support for your system’s microphone and speakers, making it incredibly easy to start a conversation.
from lokutor import VoiceAgentClient, VoiceStyle, Language

client = VoiceAgentClient(
    api_key="your-api-key",
    prompt="You are a helpful and friendly AI assistant.",
    voice=VoiceStyle.F1,
    language=Language.ENGLISH
)

try:
    # This automatically handles mic input and speaker output
    client.start_conversation()
except KeyboardInterrupt:
    print("\nπŸ‘‹ Goodbye!")
finally:
    client.disconnect()

Standalone Streaming TTS

Convert text into high-quality audio streams.
from lokutor import TTSClient, VoiceStyle, Language

client = TTSClient(api_key="your-api-key")

print("πŸ“’ Synthesizing...")
client.synthesize(
    text="Hello! This is a test of the Lokutor standalone text-to-speech engine.",
    voice=VoiceStyle.F1,
    language=Language.ENGLISH,
    play=True,  # Set to True to play immediately through speakers
    block=True  # Wait for playback to finish
)

Advanced Usage with Callbacks

You can track the state of the conversation and handle events manually using callbacks.
from lokutor import VoiceAgentClient

def on_transcription(text):
    print(f"πŸ“ You: {text}")

def on_response(text):
    print(f"πŸ€– Agent: {text}")

client = VoiceAgentClient(
    api_key="your-api-key",
    prompt="You are a helpful AI.",
    on_transcription=on_transcription,
    on_response=on_response
)

client.start_conversation()