
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
polyglot-tts
Advanced tools
A Python module for text translation and audio generation using OpenAI's API and ElevenLabs
A Python module for translating text using OpenAI's API with optional audio generation using ElevenLabs.
pip install polyglot-tts
Create a .env file in your project root with your API keys:
OPENAI_API_KEY=your-openai-api-key-here
ELEVENLABS_API_KEY=your-elevenlabs-api-key-here # Optional, for audio generation
Alternatively, set them as environment variables:
export OPENAI_API_KEY='your-openai-api-key-here'
export ELEVENLABS_API_KEY='your-elevenlabs-api-key-here' # Optional
from polyglot-tts import translate
# Basic translation
translated_text, _ = translate("Hello, how are you?", "Spanish", generate_audio=False)
print(translated_text) # "¡Hola, cómo estás?"
# Translation with audio generation
translated_text, audio_path = translate("Hello, how are you?", "French")
print(translated_text) # "Bonjour, comment allez-vous?"
print(audio_path) # Path to the generated audio file
message (str): The text to translateoutput_lang (str): The target language for translationgenerate_audio (bool, optional): Whether to generate audio for the translation. Defaults to True.voice_id (str, optional): The ElevenLabs voice ID to use for audio generation. Defaults to "EXAVITQu4vr4xnSDxMaL" (Bella voice).save_audio (bool, optional): Whether to save the generated audio file. Defaults to False. If True, the audio file will be saved in the "output" directory in the current working directory.Returns a tuple containing:
The module will raise:
ValueError if required API keys are not setException if translation or audio generation failsContributions are welcome! Please feel free to submit a Pull Request.
MIT License
FAQs
A Python module for text translation and audio generation using OpenAI's API and ElevenLabs
We found that polyglot-tts demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.