Skip to main content

A unified wrapper for various AI provider APIs, aiming for OpenAI compatibility.

Project description

OpenTTS

PyPI version PyPI - Python Version

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 supported
  • input: The text you want to convert to speech
  • voice: 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:

  1. Create a new folder: opentts/providers/provider_3/
  2. Add an __init__.py with provider capabilities
  3. Implement the TTS engine in tts/engine.py
  4. 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:

  1. Fork the repository
  2. Create a feature branch for your changes
  3. Add tests for any new functionality
  4. Make sure existing tests still pass
  5. Submit a pull request

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opentts_ai-0.1.1.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opentts_ai-0.1.1-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

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

Hashes for opentts_ai-0.1.1.tar.gz
Algorithm Hash digest
SHA256 cbfc960f36f52395d3b130c535966fb16c7a7fae6f860ae2949324b0547d51a3
MD5 c1645ed0bd0e49390976de36b2cc7a6a
BLAKE2b-256 6c032da12d8287d67574c9b5848c536b41da81c2b797644cb1f7c1e39426f802

See more details on using hashes here.

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

Hashes for opentts_ai-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2b3733b7b6695056a9de549d00b9201c3bd57089e1541e112b9f35d05fc5c642
MD5 a43a30249ca33bf2909e8d031f1a658f
BLAKE2b-256 7ed7a06f8a5fa94d29b4f24077e2ce61ba417385728a5f75a9e4be739dbe753b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page