https://github.com/udaygiri/pyttslib
๐ A powerful and easy-to-use Python Text-to-Speech library that supports multiple TTS engines.
https://github.com/udaygiri/pyttslib
gtts gtts-api python python-package python3 pyttsx3 text-to-speech
Last synced: 12 days ago
JSON representation
๐ A powerful and easy-to-use Python Text-to-Speech library that supports multiple TTS engines.
- Host: GitHub
- URL: https://github.com/udaygiri/pyttslib
- Owner: udaygiri
- License: mit
- Created: 2025-03-10T06:15:33.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-10T06:44:30.000Z (about 1 year ago)
- Last Synced: 2025-03-10T07:31:29.801Z (about 1 year ago)
- Topics: gtts, gtts-api, python, python-package, python3, pyttsx3, text-to-speech
- Language: Python
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐ฏ PyTTSLib
> ๐ A powerful and easy-to-use Python Text-to-Speech library that supports multiple TTS engines.
## โจ Features
- ๐๏ธ Multiple TTS engine support:
- ๐ฅ๏ธ **pyttsx3** (offline, default) - Works without internet
- ๐ **Google TTS** - High-quality online TTS
- ๐๏ธ Voice customization:
- ๐โโ๏ธ Adjustable speech rate
- ๐ Volume control
- ๐ฅ Multiple voice options
- ๐พ Save audio to multiple formats (MP3, WAV)
- ๐ Smart file management with auto-cleanup
- ๐ฅ๏ธ Cross-platform compatibility (Windows, Linux, macOS)
- ๐ก๏ธ Robust error handling
- ๐ Well-documented API
## ๐ Installation
```bash
pip install pyttslib
```
## ๐ Quick Start
```python
from pyttslib import TextToSpeech
# Create a TTS instance (default: pyttsx3 engine)
tts = TextToSpeech()
# Basic text-to-speech
tts.speak("Hello, world!")
# Use Google TTS instead
gtts = TextToSpeech(engine="google")
gtts.speak("Hello from Google Text-to-Speech!")
# Save speech to a file
tts.save_to_file("This will be saved as audio.", "output.mp3")
```
## ๐ฎ Advanced Usage
### ๐๏ธ Voice Configuration
```python
# Configure pyttsx3 engine
tts = TextToSpeech(engine="pyttsx3", engine_config={
"rate": 150, # Words per minute
"volume": 0.8, # Volume level (0.0 to 1.0)
})
# Configure Google TTS
tts = TextToSpeech(engine="google", engine_config={
"lang": "en", # Language code
"tld": "com", # Top-level domain
"slow": False # Normal speed
})
```
### ๐ญ Voice Selection
```python
# List available voices
voices = tts.list_voices()
for voice in voices:
print(f"Voice: {voice['name']} (ID: {voice['id']})")
# Set a specific voice
tts.set_voice("en_female_1") # Voice ID from list_voices()
```
### โ๏ธ Speech Properties
```python
# Adjust speech rate (pyttsx3 only)
tts.set_rate(150) # Words per minute
# Adjust volume (pyttsx3 only)
tts.set_volume(0.8) # 80% volume
```
## ๐ Examples
The package includes example scripts in the `examples/` directory:
- ๐ `basic_usage.py`: Demonstrates fundamental features
- ๐ง `advanced_usage.py`: Shows advanced functionality
Run the examples:
```bash
python examples/basic_usage.py
python examples/advanced_usage.py
```
## ๐ Supported Audio Formats
- ๐ต MP3 (Google TTS)
- ๐ WAV (pyttsx3)
- ๐ผ OGG (platform-dependent)
- ๐น AIFF (platform-dependent)
## ๐ ๏ธ Technical Details
### File Management
- ๐ Temporary files are stored in a dedicated folder
- ๐งน Automatic cleanup after playback
- ๐ซ Robust retry mechanism for file operations
- ๐ Safe file handling with proper resource cleanup
### Error Handling
- โ ๏ธ Custom exception classes for better error management
- ๐ Automatic retries for transient failures
- ๐ข Clear error messages and logging
- ๐ก๏ธ Graceful fallbacks for playback methods
## ๐ค Contributing
Contributions are welcome! Here's how you can help:
1. ๐ด Fork the repository
2. ๐ฟ Create your feature branch (`git checkout -b feature/amazing-feature`)
3. ๐พ Commit your changes (`git commit -m 'Add amazing feature'`)
4. ๐ค Push to the branch (`git push origin feature/amazing-feature`)
5. ๐ฏ Open a Pull Request
## ๐ License
MIT License - feel free to use this in your projects!
## ๐ Acknowledgments
- ๐ค [pyttsx3](https://github.com/nateshmbhat/pyttsx3) for offline TTS
- ๐ [gTTS](https://github.com/pndurette/gTTS) for Google TTS support
- ๐ [playsound](https://github.com/TaylorSMarks/playsound) for cross-platform audio playback
## ๐ Support
- ๐ง Report issues on GitHub
- ๐ญ Submit feature requests
- ๐ค Pull requests are welcome
---
Made with โค๏ธ for the Python community