The Python Text-to-Speech library you didn’t know you needed (or maybe you did).
A lightweight Python wrapper for generating speech from text using various online TTS services—no heavy model downloads, no complex setup. Just plug, play, and talk.
Inspired by Chris Phillips's php tts library library, pyt2s was born out of frustration:
“Why is there no Python TTS library that’s simple, supports multiple voices (including both genders), and doesn’t ask me to download 20GB of models?”
Now there is.
pyt2s taps into several online services to give you voice variety:
- Acapela
- Cepstral
- Oddcast
- Stream Elements
- Stream Labs
- Voice Forge
git clone https://github.com/yourusername/pyt2s.git
cd pyt2s
pip install -r requirements.txt
pip install -e .
pip install pyt2s
Here’s how to convert text to speech and save it as an MP3:
from pyt2s.services import stream_elements
# Default Voice
data = stream_elements.requestTTS('Lorem Ipsum is simply dummy text.')
# Custom Voice
data = stream_elements.requestTTS('Lorem Ipsum is simply dummy text.', stream_elements.Voice.Russell)
with open('output.mp3', '+wb') as file:
file.write(data)