Skip to main content

voicebox

python-package PyPI - Python Version PyPI - Version Documentation Status

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

| GitHub | Documentation 📘 | Audio Samples 🔉 |

# 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 package.

Amazon Polly 🌐

Online TTS engine from AWS.

ElevenLabs 🌐

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

Minimal example:

from voicebox.tts import ElevenLabsTTS

vb = SimpleVoicebox(tts=ElevenLabsTTS(
    voice_id="JBFqnCBsd6RMkjVDRZzb",
    api_key="...",
))

eSpeak NG 🌐

Offline TTS engine with a good number of options.

Google Cloud Text-to-Speech 🌐

Powerful online TTS engine offered by Google Cloud.

gTTS 🌐

Online TTS engine used by Google Translate.

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

🤗 Parler TTS 🌐

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

Pico TTS

Very basic offline TTS engine.

pyttsx3 🌐

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
  • Setup:
    1. pip install "voicebox-tts[pyttsx3]"
    2. On Debian/Ubuntu: sudo apt install espeak

Voice.AI 🌐

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

Minimal example:

from voicebox.tts import VoiceAiTTS

vb = SimpleVoicebox(tts=VoiceAiTTS(api_key="..."))

Effects

Built-in effect classes are located in the voicebox.effects package, and can be imported like:

from voicebox.effects import CoolEffect

Here is a non-exhaustive list of fun effects:

  • Glitch creates a glitchy sound by randomly repeating small chunks of audio.
  • RingMod can be used to create choppy, Doctor Who Dalek-like effects.
  • Vocoder is useful for making monotone, robotic voices.

There is also support for all the awesome audio plugins in Spotify's pedalboard library using the special PedalboardEffect wrapper, e.g.:

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

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

Examples

Minimal

# 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 package. They can be imported into your own code, and you can run them to demo:

# 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

# 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

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

Metadata

Release files for voicebox-tts 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for voicebox-tts 1.0.0
File Size Uploaded Provenance Actions
voicebox_tts-1.0.0.tar.gz 37.4 kB Without provenance Details for voicebox_tts-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for voicebox-tts 1.0.0
File Interpreter ABI Platform Actions
voicebox_tts-1.0.0-py3-none-any.whl Python 3 none any Details for voicebox_tts-1.0.0-py3-none-any.whl

Total release size: 86.5 kB

Release files / voicebox_tts-1.0.0.tar.gz

Download URL voicebox_tts-1.0.0.tar.gz
Size 37.4 kB
Tags Source
SHA-256 checksum
How to use checksums
096e8cef83008c15685fb10d565e3f1b789f2f31db166630e9a2abcc6530603d
BLAKE2b-256 checksum
How to use checksums
85713d105b81a7b8745a046fb3f04449a453eb5474480af47e72932d2eb5a04f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / voicebox_tts-1.0.0-py3-none-any.whl

Download URL voicebox_tts-1.0.0-py3-none-any.whl
Size 49.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d85f536a07d0679b56a68287bb329fc53288cae8427337d8c542a69e195b7775
BLAKE2b-256 checksum
How to use checksums
91ff676e4694845233752bfa85c5eb755e1f4285946a72e8075c27021a1c3e55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for voicebox-tts 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page