Skip to main content

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

Project description

voicebox

python-package

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

Listen to audio samples here: Audio Samples

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

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

voicebox = Voicebox(
    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.* modules.

Amazon Polly 🌐

Online TTS engine from AWS.

ElevenLabs 🌐

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

  • Class: voicebox.tts.ElevenLabs
  • Setup:
    1. pip install voicebox-tts[elevenlabs]
    2. Install ffmpeg or libav for pydub (docs)
    3. Get an API key and do one of the following:
      • Set environment variable ELEVEN_API_KEY=<api-key>; or
      • Set with import elevenlabs; elevenlabs.set_api_key('<api_key>'); or
      • Pass as parameter to class: voicebox.tts.ElevenLabs(api_key='<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 or libav for pydub (docs)

Pico TTS

Very basic offline TTS engine.

Effects

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

from voicebox.effects import CoolEffect

Here is a non-exhaustive list of fun effects:

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 Voicebox
from voicebox.effects import PedalboardEffect
import pedalboard

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

Examples

Minimal

# PicoTTS is used to say "Hello, world!"
from voicebox import Voicebox
voicebox = Voicebox()
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.tts import ESpeakConfig, ESpeakNG

tts = ESpeakNG(ESpeakConfig(speed=120, voice='en-us'))

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

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

# Send audio to playback device, and save to speech.wav file
from voicebox.sinks import Distributor, SoundDevice, WaveFile

sink = Distributor([
    SoundDevice(),
    WaveFile('speech.wav'),
])

# Build the voicebox
from voicebox import Voicebox

voicebox = Voicebox(tts, effects, sink)

# eSpeak NG is used to say "Hello, world!" with a glitchy robot voice
voicebox.say('Hello, world!')

Command Line Demo

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

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

voicebox-tts-0.0.2.tar.gz (29.1 kB view hashes)

Uploaded Source

Built Distribution

voicebox_tts-0.0.2-py3-none-any.whl (37.3 kB view hashes)

Uploaded Python 3

Supported by

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