๐ Python SDK for Palabra AI's real-time speech-to-speech translation API
๐ Break down language barriers and enable seamless communication across 25+ languages
๐ฏ The Palabra AI Python SDK provides a high-level API for integrating real-time speech-to-speech translation into your Python applications.
โจ What can Palabra.ai do?
- โก Real-time speech-to-speech translation with near-zero latency
- ๐๏ธ Auto voice cloning - speak any language in YOUR voice
- ๐ Two-way simultaneous translation for live discussions
- ๐ Developer API/SDK for building your own apps
- ๐ฏ Works everywhere - Zoom, streams, events, any platform
- ๐ Zero data storage - your conversations stay private
๐ง This SDK focuses on making real-time translation simple and accessible:
- ๐ก๏ธ Uses WebRTC and WebSockets under the hood
- โก Abstracts away all complexity
- ๐ฎ Simple configuration with source/target languages
- ๐ค Supports multiple input/output adapters (microphones, speakers, files, buffers)
๐ How it works:
- ๐ค Configure input/output adapters
- ๐ SDK handles the entire pipeline
- ๐ฏ Automatic transcription, translation, and synthesis
- ๐ Real-time audio stream ready for playback
๐ก All with just a few lines of code!
pip install palabra-ai
If you encounter SSL certificate errors on macOS like:
SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate
Option 1: Install Python certificates (recommended)
/Applications/Python\ $(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")/Install\ Certificates.command
Option 2: Use system certificates
pip install pip-system-certs
This will configure Python to use your system's certificate store.
from palabra_ai import (PalabraAI, Config, SourceLang, TargetLang,
EN, ES, DeviceManager)
palabra = PalabraAI()
dm = DeviceManager()
mic, speaker = dm.select_devices_interactive()
cfg = Config(SourceLang(EN, mic), [TargetLang(ES, speaker)])
palabra.run(cfg)
โ๏ธ Set your API credentials as environment variables:
export PALABRA_API_KEY=your_api_key
export PALABRA_API_SECRET=your_api_secret
from palabra_ai import (PalabraAI, Config, SourceLang, TargetLang,
FileReader, FileWriter, EN, ES)
palabra = PalabraAI()
reader = FileReader("./speech/es.mp3")
writer = FileWriter("./es2en_out.wav")
cfg = Config(SourceLang(ES, reader), [TargetLang(EN, writer)])
palabra.run(cfg)
from palabra_ai import (PalabraAI, Config, SourceLang, TargetLang,
FileReader, FileWriter, EN, ES, FR, DE)
palabra = PalabraAI()
config = Config(
source=SourceLang(EN, FileReader("presentation.mp3")),
targets=[
TargetLang(ES, FileWriter("spanish.wav")),
TargetLang(FR, FileWriter("french.wav")),
TargetLang(DE, FileWriter("german.wav"))
]
)
palabra.run(config)
๐ Add a transcription of the source and translated speech.
โ๏ธ Configure output to provide:
- ๐ Audio only
- ๐ Transcriptions only
- ๐ฏ Both audio and transcriptions
from palabra_ai import (
PalabraAI,
Config,
SourceLang,
TargetLang,
FileReader,
EN,
ES,
)
from palabra_ai.base.message import TranscriptionMessage
async def print_translation_async(msg: TranscriptionMessage):
print(repr(msg))
def print_translation(msg: TranscriptionMessage):
print(str(msg))
palabra = PalabraAI()
cfg = Config(
source=SourceLang(
EN,
FileReader("speech/en.mp3"),
print_translation # Callback for source transcriptions
),
targets=[
TargetLang(
ES,
# You can use only transcription without audio writer if you want
# FileWriter("./test_output.wav"), # Optional: audio output
on_transcription=print_translation_async # Callback for translated transcriptions
)
],
silent=True, # Set to True to disable verbose logging to console
)
palabra.run(cfg)
1๏ธโฃ Audio only (default):
TargetLang(ES, FileWriter("output.wav"))
2๏ธโฃ Transcription only:
TargetLang(ES, on_transcription=your_callback_function)
3๏ธโฃ Audio and transcription:
TargetLang(ES, FileWriter("output.wav"), on_transcription=your_callback_function)
๐ก The transcription callbacks receive TranscriptionMessage
objects containing the transcribed text and metadata.
๐ Callbacks can be either synchronous or asynchronous functions.
import io
from palabra_ai import (PalabraAI, Config, SourceLang, TargetLang,
BufferReader, BufferWriter, AR, EN, RunAsPipe)
ffmpeg_cmd = [
'ffmpeg',
'-i', 'speech/ar.mp3',
'-f', 's16le', # 16-bit PCM
'-acodec', 'pcm_s16le',
'-ar', '48000', # 48kHz
'-ac', '1', # mono
'-' # output to stdout
]
pipe_buffer = RunAsPipe(ffmpeg_cmd)
es_buffer = io.BytesIO()
palabra = PalabraAI()
reader = BufferReader(pipe_buffer)
writer = BufferWriter(es_buffer)
cfg = Config(SourceLang(AR, reader), [TargetLang(EN, writer)])
palabra.run(cfg)
print(f"Translated audio written to buffer with size: {es_buffer.getbuffer().nbytes} bytes")
with open("./ar2en_out.wav", "wb") as f:
f.write(es_buffer.getbuffer())
import io
from palabra_ai import (PalabraAI, Config, SourceLang, TargetLang,
BufferReader, BufferWriter, AR, EN)
from palabra_ai.internal.audio import convert_any_to_pcm16
en_buffer, es_buffer = io.BytesIO(), io.BytesIO()
with open("speech/ar.mp3", "rb") as f:
en_buffer.write(convert_any_to_pcm16(f.read()))
palabra = PalabraAI()
reader = BufferReader(en_buffer)
writer = BufferWriter(es_buffer)
cfg = Config(SourceLang(AR, reader), [TargetLang(EN, writer)])
palabra.run(cfg)
print(f"Translated audio written to buffer with size: {es_buffer.getbuffer().nbytes} bytes")
with open("./ar2en_out.wav", "wb") as f:
f.write(es_buffer.getbuffer())
from palabra_ai import PalabraAI, Config, SourceLang, TargetLang, DeviceManager, EN, ES
dm = DeviceManager()
reader, writer = dm.get_default_readers_writers()
if reader and writer:
palabra = PalabraAI()
config = Config(
source=SourceLang(EN, reader),
targets=[TargetLang(ES, writer)]
)
palabra.run(config)
import asyncio
from palabra_ai import PalabraAI, Config, SourceLang, TargetLang, FileReader, FileWriter, EN, ES
async def translate():
palabra = PalabraAI()
config = Config(
source=SourceLang(EN, FileReader("input.mp3")),
targets=[TargetLang(ES, FileWriter("output.wav"))]
)
await palabra.run(config)
asyncio.run(translate())
๐ฏ The Palabra AI SDK provides flexible I/O adapters that can combined to:
- ๐ FileReader/FileWriter: Read from and write to audio files
- ๐ค DeviceReader/DeviceWriter: Use microphones and speakers
- ๐พ BufferReader/BufferWriter: Work with in-memory buffers
- ๐ง RunAsPipe: Run command and represent as pipe (e.g., FFmpeg stdout)
๐ Combine any input adapter with any output adapter:
config = Config(
source=SourceLang(EN, mic),
targets=[TargetLang(ES, FileWriter("recording_es.wav"))]
)
config = Config(
source=SourceLang(EN, FileReader("presentation.mp3")),
targets=[TargetLang(ES, speaker)]
)
config = Config(
source=SourceLang(EN, mic),
targets=[
TargetLang(ES, speaker), # Play Spanish through speaker
TargetLang(ES, FileWriter("spanish.wav")), # Save Spanish to file
TargetLang(FR, FileWriter("french.wav")) # Save French to file
]
)
input_buffer = io.BytesIO(audio_data)
output_buffer = io.BytesIO()
config = Config(
source=SourceLang(EN, BufferReader(input_buffer)),
targets=[TargetLang(ES, BufferWriter(output_buffer))]
)
pipe = RunAsPipe(ffmpeg_process.stdout)
config = Config(
source=SourceLang(EN, BufferReader(pipe)),
targets=[TargetLang(ES, speaker)]
)
๐ฏ Translate audio streams in real-time with minimal latency
๐ฌ Perfect for live conversations, conferences, and meetings
๐ญ Preserve the original speaker's voice characteristics in translations
โ๏ธ Enable voice cloning in the configuration
๐ค Easy device selection with interactive prompts or programmatic access:
dm = DeviceManager()
# Interactive selection
mic, speaker = dm.select_devices_interactive()
# Get devices by name
mic = dm.get_mic_by_name("Blue Yeti")
speaker = dm.get_speaker_by_name("MacBook Pro Speakers")
# List all devices
input_devices = dm.get_input_devices()
output_devices = dm.get_output_devices()
๐ธ๐ฆ Arabic (AR), ๐จ๐ณ Chinese (ZH), ๐จ๐ฟ Czech (CS), ๐ฉ๐ฐ Danish (DA), ๐ณ๐ฑ Dutch (NL), ๐ฌ๐ง English (EN), ๐ซ๐ฎ Finnish (FI), ๐ซ๐ท French (FR), ๐ฉ๐ช German (DE), ๐ฌ๐ท Greek (EL), ๐ฎ๐ฑ Hebrew (HE), ๐ญ๐บ Hungarian (HU), ๐ฎ๐น Italian (IT), ๐ฏ๐ต Japanese (JA), ๐ฐ๐ท Korean (KO), ๐ต๐ฑ Polish (PL), ๐ต๐น Portuguese (PT), ๐ท๐บ Russian (RU), ๐ช๐ธ Spanish (ES), ๐น๐ท Turkish (TR), ๐บ๐ฆ Ukrainian (UK)
๐ธ๐ฆ Arabic (AR), ๐ง๐ฌ Bulgarian (BG), ๐จ๐ณ Chinese Mandarin (ZH), ๐จ๐ฟ Czech (CS), ๐ฉ๐ฐ Danish (DA), ๐ณ๐ฑ Dutch (NL), ๐ฌ๐ง English UK (EN_GB), ๐บ๐ธ English US (EN_US), ๐ซ๐ฎ Finnish (FI), ๐ซ๐ท French (FR), ๐ฉ๐ช German (DE), ๐ฌ๐ท Greek (EL), ๐ฎ๐ฑ Hebrew (HE), ๐ญ๐บ Hungarian (HU), ๐ฎ๐ฉ Indonesian (ID), ๐ฎ๐น Italian (IT), ๐ฏ๐ต Japanese (JA), ๐ฐ๐ท Korean (KO), ๐ต๐ฑ Polish (PL), ๐ต๐น Portuguese (PT), ๐ง๐ท Portuguese Brazilian (PT_BR), ๐ท๐ด Romanian (RO), ๐ท๐บ Russian (RU), ๐ธ๐ฐ Slovak (SK), ๐ช๐ธ Spanish (ES), ๐ฒ๐ฝ Spanish Mexican (ES_MX), ๐ธ๐ช Swedish (SV), ๐น๐ท Turkish (TR), ๐บ๐ฆ Ukrainian (UK), ๐ป๐ณ Vietnamese (VI)
from palabra_ai import (
# English variants - 1.5+ billion speakers (including L2)
EN, EN_AU, EN_CA, EN_GB, EN_US,
# Chinese - 1.3+ billion speakers
ZH,
# Hindi - 600+ million speakers
HI,
# Spanish variants - 500+ million speakers
ES, ES_MX,
# Arabic variants - 400+ million speakers
AR, AR_AE, AR_SA,
# French variants - 280+ million speakers
FR, FR_CA,
# Portuguese variants - 260+ million speakers
PT, PT_BR,
# Russian - 260+ million speakers
RU,
# Japanese & Korean - 200+ million speakers combined
JA, KO,
# Southeast Asian languages - 400+ million speakers
ID, VI, TA, MS, FIL,
# Germanic languages - 150+ million speakers
DE, NL, SV, NO, DA,
# Other European languages - 300+ million speakers
TR, IT, PL, UK, RO, EL, HU, CS, BG, SK, FI, HR,
# Other languages - 40+ million speakers
AZ, HE
)
- โ Core SDK functionality
- โ GitHub Actions CI/CD
- โ Docker packaging
- โ Python 3.11, 3.12, 3.13 support
- โ PyPI publication (coming soon)
- โ Documentation site (coming soon)
- โณ Code coverage reporting (setup required)
- โณ TODO: global timeout support for long-running tasks
- โณ TODO: support for multiple source languages in a single run
- โณ TODO: fine cancelling on cancel_all_tasks()
- โณ TODO: error handling improvements
- ๐งช Tests: Running on Python 3.11, 3.12, 3.13
- ๐ฆ Release: Automated releases with Docker images
- ๐ Coverage: Tests implemented, reporting setup needed
- ๐ Python 3.11+
- ๐ Palabra AI API credentials (get them at palabra.ai)
- ๐ Documentation: https://docs.palabra.ai
- ๐ Issues: GitHub Issues
- ๐ง Email: info@palabra.ai
This project is licensed under the MIT License - see the LICENSE file for details.
ยฉ Palabra.ai, 2025 | ๐ Breaking down language barriers with AI ๐