Metadata-Version: 2.2
Name: voicebox-tts
Version: 0.0.13
Summary: Python text-to-speech library with built-in voice effects and support for multiple TTS engines.
Author-email: Austin Bowen <austin.bowen.314@gmail.com>
License: MIT License
        
        Copyright (c) 2023 Austin Bowen
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/austin-bowen/voicebox
Project-URL: Issues, https://github.com/austin-bowen/voicebox/issues
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: audioread
Requires-Dist: cachetools
Requires-Dist: nltk
Requires-Dist: numpy
Requires-Dist: pedalboard
Requires-Dist: scipy
Requires-Dist: sounddevice
Provides-Extra: all
Requires-Dist: voicebox-tts[dev]; extra == "all"
Requires-Dist: voicebox-tts[docs]; extra == "all"
Requires-Dist: voicebox-tts[test]; extra == "all"
Requires-Dist: voicebox-tts[amazon-polly]; extra == "all"
Requires-Dist: voicebox-tts[elevenlabs]; extra == "all"
Requires-Dist: voicebox-tts[google-cloud-tts]; extra == "all"
Requires-Dist: voicebox-tts[gtts]; extra == "all"
Requires-Dist: voicebox-tts[pyttsx3]; extra == "all"
Provides-Extra: dev
Requires-Dist: build; extra == "dev"
Requires-Dist: invoke; extra == "dev"
Requires-Dist: twine; extra == "dev"
Provides-Extra: docs
Requires-Dist: myst-parser; extra == "docs"
Requires-Dist: sphinx; extra == "docs"
Requires-Dist: sphinx-rtd-theme; extra == "docs"
Provides-Extra: test
Requires-Dist: coverage; extra == "test"
Requires-Dist: parameterized; extra == "test"
Requires-Dist: pytest; extra == "test"
Provides-Extra: amazon-polly
Requires-Dist: boto3; extra == "amazon-polly"
Requires-Dist: boto3-stubs; extra == "amazon-polly"
Requires-Dist: boto3-stubs[polly]; extra == "amazon-polly"
Provides-Extra: elevenlabs
Requires-Dist: elevenlabs; extra == "elevenlabs"
Provides-Extra: google-cloud-tts
Requires-Dist: google-cloud-texttospeech; extra == "google-cloud-tts"
Provides-Extra: gtts
Requires-Dist: gTTS; extra == "gtts"
Provides-Extra: pyttsx3
Requires-Dist: pyttsx3; extra == "pyttsx3"

# voicebox

![python-package](https://github.com/austin-bowen/voicebox/actions/workflows/python-package.yml/badge.svg)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/voicebox-tts)
[![PyPI - Version](https://img.shields.io/pypi/v/voicebox-tts)](https://pypi.org/project/voicebox-tts/)
[![Documentation Status](https://readthedocs.org/projects/voicebox/badge/?version=latest)](https://voicebox.readthedocs.io/en/latest/?badge=latest)

Python text-to-speech library with built-in voice effects and support for multiple TTS engines.

| [GitHub](https://github.com/austin-bowen/voicebox/)
| [Documentation 📘](https://voicebox.readthedocs.io)
| [Audio Samples 🔉](samples)
|

```python
# Example: Use gTTS with a vocoder effect to speak in a robotic voice

from voicebox import SimpleVoicebox
from voicebox.tts import gTTS
from voicebox.effects import Vocoder, Normalize

voicebox = SimpleVoicebox(
    tts=gTTS(),
    effects=[Vocoder.build(), Normalize()],
)

voicebox.say('Hello, world! How are you today?')
```

## Setup

1. `pip install voicebox-tts`
2. Install the `PortAudio` library for audio playback.
   - On Debian/Ubuntu: `sudo apt install libportaudio2`
3. Install dependencies for whichever TTS engine(s) you want to use (see section below).

## Supported Text-to-Speech Engines

Classes for supported TTS engines are located in the
[`voicebox.tts`](voicebox.tts) package.

### Amazon Polly [🌐](https://aws.amazon.com/polly/)

Online TTS engine from AWS.

- Class: [`voicebox.tts.AmazonPolly`](voicebox.tts.amazonpolly.AmazonPolly)
- Setup: `pip install "voicebox-tts[amazon-polly]"`

### ElevenLabs [🌐](https://elevenlabs.io/)

Online TTS engine with very realistic voices and support for voice cloning.

- Class: [`voicebox.tts.ElevenLabsTTS`](voicebox.tts.elevenlabs.ElevenLabsTTS)
- Setup:
  1. `pip install "voicebox-tts[elevenlabs]"`
  2. Install ffmpeg for audio decoding.
  3. (Optional) Use an [API key](https://elevenlabs.io/docs/api-reference/authentication):
     ```python
     from elevenlabs.client import ElevenLabs
     from voicebox.tts import ElevenLabsTTS

     tts = ElevenLabsTTS(client=ElevenLabs(api_key='your-api-key'))
     ```

### eSpeak NG [🌐](https://github.com/espeak-ng/espeak-ng)

Offline TTS engine with a good number of options.

- Class: [`voicebox.tts.ESpeakNG`](voicebox.tts.espeakng.ESpeakNG)
- Setup:
  - On Debian/Ubuntu: `sudo apt install espeak-ng`

### Google Cloud Text-to-Speech [🌐](https://cloud.google.com/text-to-speech)

Powerful online TTS engine offered by Google Cloud.

- Class: [`voicebox.tts.GoogleCloudTTS`](voicebox.tts.googlecloudtts.GoogleCloudTTS)
- Setup: `pip install "voicebox-tts[google-cloud-tts]"`

### gTTS [🌐](https://github.com/pndurette/gTTS)

Online TTS engine used by Google Translate.

- Class: [`voicebox.tts.gTTS`](voicebox.tts.gtts.gTTS)
- Setup:
  1. `pip install "voicebox-tts[gtts]"`
  2. Install ffmpeg for audio decoding.

### 🤗 Parler TTS [🌐](https://github.com/huggingface/parler-tts)

Offline TTS engine released by Hugging Face that uses a promptable
deep learning model to generate speech.

- Class: [`voicebox.tts.ParlerTTS`](voicebox.tts.parlertts.ParlerTTS)
- Setup: `pip install git+https://github.com/huggingface/parler-tts.git`

### Pico TTS

Very basic offline TTS engine.

- Class: [`voicebox.tts.PicoTTS`](voicebox.tts.picotts.PicoTTS)
- Setup:
  - On Debian/Ubuntu: `sudo apt install libttspico-utils`

### pyttsx3 [🌐](https://pyttsx3.readthedocs.io/)

Offline TTS engine wrapper with support for the built-in TTS engines on Windows
(SAPI5) and macOS (NSSpeechSynthesizer), as well as espeak on Linux.
By default, it will use the most appropriate engine for your platform.

- Class: [`voicebox.tts.Pyttsx3TTS`](voicebox.tts.pyttsx3.Pyttsx3TTS)
- Setup:
  1. `pip install "voicebox-tts[pyttsx3]"`
  2. On Debian/Ubuntu: `sudo apt install espeak`

## Effects

Built-in effect classes are located in the
[`voicebox.effects`](voicebox.effects) package,
and can be imported like:

```python
from voicebox.effects import CoolEffect
```

Here is a non-exhaustive list of fun effects:
- [`Glitch`](voicebox.effects.glitch.Glitch)
  creates a glitchy sound by randomly repeating small chunks of audio.
- [`RingMod`](voicebox.effects.ring_mod.RingMod)
  can be used to create choppy, Doctor Who Dalek-like effects.
- [`Vocoder`](voicebox.effects.vocoder.Vocoder)
  is useful for making monotone, robotic voices.

There is also support for all the awesome audio plugins in
[Spotify's `pedalboard` library](https://spotify.github.io/pedalboard/index.html)
using the special [`PedalboardEffect`](voicebox.effects.pedalboard.PedalboardEffect)
wrapper, e.g.:

```python
from voicebox import SimpleVoicebox
from voicebox.effects import PedalboardEffect
import pedalboard

voicebox = SimpleVoicebox(
    effects=[
        PedalboardEffect(pedalboard.Reverb()),
        ...,
    ]
)
```

## Examples

### Minimal

```python
# PicoTTS is used to say "Hello, world!"
from voicebox import SimpleVoicebox

voicebox = SimpleVoicebox()
voicebox.say('Hello, world!')
```

### Pre-built

Some pre-built voiceboxes are available in the
[`voicebox.examples`](voicebox.examples) package.
They can be imported into your own code, and you can run them to demo:

```bash
# Voice of GLaDOS from the Portal video game series
python -m voicebox.examples.glados "optional message"

# Voice of the OOM-9 command battle droid from Star Wars: Episode I
python -m voicebox.examples.battle_droid "optional message"
```

### Advanced

```python
# Use eSpeak NG at 120 WPM and en-us voice as the TTS engine
from voicebox import reliable_tts
from voicebox.tts import ESpeakConfig, ESpeakNG, gTTS

# Wrap multiple TTSs in retries and caches
tts = reliable_tts(
    ttss=[
        # Prefer using online TTS first
        gTTS(),
        # Fall back to offline TTS if online TTS fails
        ESpeakNG(ESpeakConfig(speed=120, voice='en-us')),
    ],
)

# Add some voice effects
from voicebox.effects import Vocoder, Glitch, Normalize

effects = [
    Vocoder.build(),    # Make a robotic, monotone voice
    Glitch(),           # Randomly repeat small sections of audio
    Normalize(),        # Remove DC and make volume consistent
]

# Build audio sink
from voicebox.sinks import Distributor, SoundDevice, WaveFile

sink = Distributor([
    SoundDevice(),          # Send audio to playback device
    WaveFile('speech.wav'), # Save audio to speech.wav file
])

# Build the voicebox
from voicebox import ParallelVoicebox
from voicebox.voiceboxes.splitter import SimpleSentenceSplitter

# Parallel voicebox doesn't block the main thread
voicebox = ParallelVoicebox(
    tts,
    effects,
    sink,
    # Split text into sentences to reduce time to first speech
    text_splitter=SimpleSentenceSplitter(),
)

# Speak!
voicebox.say('Hello, world!')

# Wait for all audio to finish playing before exiting
voicebox.wait_until_done()
```

### Command Line Demo

```bash
python -m voicebox -h               # Print command help
python -m voicebox "Hello, world!"  # Basic usage
```
