Skip to content

๐Ÿ”Š A powerful and easy-to-use Python Text-to-Speech library that supports multiple TTS engines.

License

Notifications You must be signed in to change notification settings

udaygiri/PyTTSLib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฏ 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

pip install pyttslib

๐Ÿ“– Quick Start

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

# 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

# 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

# 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:

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 for offline TTS
  • ๐ŸŒ gTTS for Google TTS support
  • ๐Ÿ”Š playsound for cross-platform audio playback

๐Ÿ“ž Support

  • ๐Ÿ“ง Report issues on GitHub
  • ๐Ÿ’ญ Submit feature requests
  • ๐Ÿค Pull requests are welcome

Made with โค๏ธ for the Python community

About

๐Ÿ”Š A powerful and easy-to-use Python Text-to-Speech library that supports multiple TTS engines.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages