Skip to main content

Real-Time Speech-to-Speech Translation with Python

A minimal (~300 lines) Python client for Palabra AI real-time speech translation API. Perfect for quick prototyping and understanding the core API.

What is this?​

This is a lightweight example demonstrating Palabra AI's real-time translation capabilities without the overhead of a full SDK. It captures audio from your microphone, translates it to your target language, and plays back the translation through your speakers - all in under 300 lines of code.

Features​

  • 🎤 Real-time microphone capture - Speak in your native language
  • 🌐 Instant translation - Powered by Palabra AI's WebRTC API
  • 🔊 Audio playback - Hear translations through your speakers
  • 📝 Live transcription - See what's being said and translated
  • 🚀 Minimal dependencies - Just 5 packages needed
  • 💻 Single file - Everything in one nanopalabra.py

Quick Start​

1. Install dependencies​

# Using uv (recommended)
uv venv && . .venv/bin/activate && uv sync

# Or using pip
pip install httpx livekit numpy sounddevice websockets

2. Set your API Key​

Create an API Key on the Palabra API Keys page:

export PALABRA_API_KEY=your_api_key

3. Run the example​

python nanopalabra.py

That's it! Start speaking and hear your words translated in real-time.

How it works​

The client follows the Palabra AI Quick Start flow:

  1. Creates a session with your API Key
  2. Connects to a WebRTC room using LiveKit
  3. Publishes your microphone audio to the room
  4. Receives translated audio and plays it back
  5. Shows live transcriptions in the console

Configuration​

By default, the example translates from English to Spanish. To change languages, modify the MINIMAL_SETTINGS in the code:

"transcription": {"source_language": "en"},  # Change source language
"translations": [
{
"target_language": "es", # Change target language
# Add more target languages here
}
]

Why use this?​

  • Learning: Understand Palabra AI's WebRTC API without SDK abstractions
  • Prototyping: Quickly test translation in your projects
  • Customization: Easy to modify and extend for your needs
  • Debugging: See exactly what's happening under the hood

Need the full SDK?​

For production use cases, check out the official Palabra AI Python SDK with:

  • Multiple I/O adapters (files, buffers, devices)
  • Comprehensive error handling
  • Async/await patterns
  • Type hints and documentation
  • Production-ready architecture

Support​