voicebox
Python text-to-speech library with built-in voice effects and support for multiple TTS engines.
| GitHub
| Documentation 📘
| Audio Samples 🔉
|
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
pip install voicebox-tts
- Install the
PortAudio
library for audio playback.
- On Debian/Ubuntu:
sudo apt install libportaudio2
- 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 very realistic voices and support for voice cloning.
- Class:
voicebox.tts.ElevenLabsTTS
- Setup:
pip install "voicebox-tts[elevenlabs]"
- Install ffmpeg or libav for
pydub
(docs) - (Optional) Use an API key:
from elevenlabs.client import ElevenLabs
from voicebox.tts import ElevenLabsTTS
tts = ElevenLabsTTS(client=ElevenLabs(api_key='your-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.
🤗 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.
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
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:
python -m voicebox.examples.glados "optional message"
python -m voicebox.examples.battle_droid "optional message"
Advanced
from voicebox import reliable_tts
from voicebox.tts import ESpeakConfig, ESpeakNG, gTTS
tts = reliable_tts(
ttss=[
gTTS(),
ESpeakNG(ESpeakConfig(speed=120, voice='en-us')),
],
)
from voicebox.effects import Vocoder, Glitch, Normalize
effects = [
Vocoder.build(),
Glitch(),
Normalize(),
]
from voicebox.sinks import Distributor, SoundDevice, WaveFile
sink = Distributor([
SoundDevice(),
WaveFile('speech.wav'),
])
from voicebox import ParallelVoicebox
from voicebox.voiceboxes.splitter import SimpleSentenceSplitter
voicebox = ParallelVoicebox(
tts,
effects,
sink,
text_splitter=SimpleSentenceSplitter(),
)
voicebox.say('Hello, world!')
voicebox.wait_until_done()
Command Line Demo
python -m voicebox -h
python -m voicebox "Hello, world!"