A unified wrapper for various AI provider APIs, aiming for OpenAI compatibility.
Project description
OpenTTS
OpenTTS is a simple, unified Python library for text-to-speech conversion. It provides an easy-to-use interface that works with multiple TTS providers, giving you flexibility in choosing the best voice for your needs.
โจ What makes OpenTTS special?
- ๐ Multiple Providers: Choose from different TTS services based on your requirements
- ๐ฏ Simple API: One consistent interface, no matter which provider you use
- โก Speed Control: Adjust speech speed for different use cases
- ๐ค Voice Customization: Add custom prompts to fine-tune voice characteristics
- ๐ฆ Easy to Extend: Add new providers as they become available
- ๐ง Familiar Interface: Works just like other popular TTS libraries
๐ Quick Start
Getting started is super simple:
from opentts import OpenTTS
# Create a client
client = OpenTTS()
# Generate speech
audio_bytes = client.audio.speech.create(
model="tts-1",
input="Hello, this is a test of the OpenTTS library!",
voice="alex"
)
# Save the audio
with open("hello.mp3", "wb") as f:
f.write(audio_bytes)
That's it! You now have a high-quality MP3 file ready to use.
๐ฆ Installation
Install from PyPI:
pip install opentts-ai
Or for development:
git clone https://github.com/AIMLDev726/opentts-ai.git
cd opentts-ai
pip install -e .
๐๏ธ Available Providers
SmartVoice Provider
Perfect for general-purpose TTS with great voice quality and fast response times.
- Best for: Everyday applications, quick prototyping
- Voices: alex, ben, clara, david, emma, frank, grace, henry, iris, jack, kate, leo, mia, nathan, olivia, peter, quinn, ryan, sophia, thomas
- Speed Control: Not available
- Custom Prompts: โ Yes, great for customizing voice style
StudioVoice Provider
Professional-grade TTS with advanced features and premium voice quality.
- Best for: High-quality audio production, professional applications
- Voices: aria, brooks, charles, dana, elias, felix, gina, harper, ivy, jason, kara, liam, luna, mason, nova, oscar, paige, quincy, riley, sam
- Speed Control: โ Yes, adjust from 0.7x to 1.2x speed
- Custom Prompts: โ Yes, extensive customization options
๐ก Usage Examples
Basic Usage
from opentts import OpenTTS
client = OpenTTS()
audio = client.audio.speech.create(
model="tts-1",
input="Welcome to our application!",
voice="alex"
)
Speed Control with StudioVoice
# Speak faster for tutorials or quick announcements
audio = client.audio.speech.create(
model="tts-1",
input="Let's speed this up!",
voice="aria",
provider="studio",
speed=1.1 # 10% faster
)
Custom Voice Style with SmartVoice
# Add personality to your voice
audio = client.audio.speech.create(
model="tts-1",
input="Welcome to customer service",
voice="emma",
provider="smart",
prompt="Speak in a calm, professional, and reassuring tone. Sound friendly and approachable."
)
Slower Speech for Clarity
# Perfect for educational content or accessibility
audio = client.audio.speech.create(
model="tts-1",
input="This is an important announcement",
voice="brooks",
provider="studio",
speed=0.8 # 20% slower for better comprehension
)
๐ Project Structure
opentts/
โโโ opentts/ # Main package
โ โโโ __init__.py
โ โโโ client.py # Main client interface
โ โโโ providers/ # Provider implementations
โ โ โโโ provider_1/ # SmartVoice provider
โ โ โโโ provider_2/ # StudioVoice provider
โ โโโ types/ # Data models
โโโ examples/ # Usage examples and notebooks
โ โโโ examples.py # Python examples
โ โโโ Untitled51.ipynb # Jupyter notebook examples
โโโ tests/ # Test files
โ โโโ test_tts.py # TTS functionality tests
โ โโโ outputaudio/ # Generated audio test outputs
โโโ pyproject.toml # Package configuration
โโโ README.md
๐งช Testing
Run the test suite to make sure everything works:
# Run all tests
python -m pytest tests/
# Run specific test
python tests/test_tts.py
# Try the examples
python examples/examples.py
Note: All generated audio files are automatically saved to tests/outputaudio/ so you can easily review and clean them up.
๐ API Reference
Creating a Client
from opentts import OpenTTS
client = OpenTTS() # That's all you need!
Speech Generation
audio_bytes = client.audio.speech.create(
model="tts-1", # Model name (use "tts-1" for now)
input="Your text here", # The text you want to convert
voice="alex", # Voice to use
provider="smart", # Optional: "smart" or "studio"
speed=1.0, # Optional: speech speed (StudioVoice only)
prompt="Custom style" # Optional: voice characteristics
)
Parameters:
model: Currently only "tts-1" is supportedinput: The text you want to convert to speechvoice: Voice name (see provider sections above)provider: Which TTS service to use ("smart" or "studio")speed: Speech speed multiplier (0.7-1.2 for StudioVoice)prompt: Custom instructions for voice style
๐ง Advanced Usage
Adding New Providers
Want to add support for a new TTS service? Here's how:
- Create a new folder:
opentts/providers/provider_3/ - Add an
__init__.pywith provider capabilities - Implement the TTS engine in
tts/engine.py - Update the client to recognize your new provider
Error Handling
Always wrap your calls in try-catch blocks:
try:
audio = client.audio.speech.create(
model="tts-1",
input="Hello world!",
voice="alex"
)
print("Success!")
except Exception as e:
print(f"Something went wrong: {e}")
โ๏ธ License & Legal
This software comes with a custom license. Please read the LICENSE file carefully before using it in your projects.
Important Disclaimer: This library uses third-party APIs that may change or become unavailable. We recommend having fallback options in production applications.
๐ค Contributing
We welcome contributions! Here's how you can help:
- Fork the repository
- Create a feature branch for your changes
- Add tests for any new functionality
- Make sure existing tests still pass
- Submit a pull request
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file opentts_ai-0.1.1.tar.gz.
File metadata
- Download URL: opentts_ai-0.1.1.tar.gz
- Upload date:
- Size: 18.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbfc960f36f52395d3b130c535966fb16c7a7fae6f860ae2949324b0547d51a3
|
|
| MD5 |
c1645ed0bd0e49390976de36b2cc7a6a
|
|
| BLAKE2b-256 |
6c032da12d8287d67574c9b5848c536b41da81c2b797644cb1f7c1e39426f802
|
File details
Details for the file opentts_ai-0.1.1-py3-none-any.whl.
File metadata
- Download URL: opentts_ai-0.1.1-py3-none-any.whl
- Upload date:
- Size: 19.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b3733b7b6695056a9de549d00b9201c3bd57089e1541e112b9f35d05fc5c642
|
|
| MD5 |
a43a30249ca33bf2909e8d031f1a658f
|
|
| BLAKE2b-256 |
7ed7a06f8a5fa94d29b4f24077e2ce61ba417385728a5f75a9e4be739dbe753b
|