Package: voicebox-tts
voiceboxPython 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 voicefromvoiceboximportSimpleVoiceboxfromvoicebox.ttsimportgTTSfromvoicebox.effectsimportVocoder,Normalizevoicebox=SimpleVoicebox(tts=gTTS(),effects=[Vocoder.build(),Normalize()],)voicebox.say('Hello, world! How are you today?')Setuppip install voicebox-ttsInstall thePortAudiolibrary for audio playback.On Debian/Ubuntu:sudo apt install libportaudio2Install dependencies for whichever TTS engine(s) you want to use (see section below).Supported Text-to-Speech EnginesClasses for supported TTS engines are located in thevoicebox.tts.*modules.Amazon Polly🌐Online TTS engine from AWS.Class:voicebox.tts.AmazonPollySetup:pip install "voicebox-tts[amazon-polly]"ElevenLabs🌐Online TTS engine with very realistic voices and support for voice cloning.Class:voicebox.tts.ElevenLabsSetup:pip install "voicebox-tts[elevenlabs]"Install ffmpeg or libav forpydub(docs)Get anAPI keyand do one of the following:Set environment variableELEVEN_API_KEY=<api-key>; orSet withimport elevenlabs; elevenlabs.set_api_key('<api_key>'); orPass as parameter to class:voicebox.tts.ElevenLabs(api_key='<api_key>')eSpeak NG🌐Offline TTS engine with a good number of options.Class:voicebox.tts.ESpeakNGSetup:On Debian/Ubuntu:sudo apt install espeak-ngGoogle Cloud Text-to-Speech🌐Powerful online TTS engine offered by Google Cloud.Class:voicebox.tts.GoogleCloudTTSSetup:pip install "voicebox-tts[google-cloud-tts]"gTTS🌐Online TTS engine used by Google Translate.Class:voicebox.tts.gTTSSetup:pip install "voicebox-tts[gtts]"Install ffmpeg or libav forpydub(docs)Pico TTSVery basic offline TTS engine.Class:voicebox.tts.PicoTTSSetup:On Debian/Ubuntu:sudo apt install libttspico-utilsEffectsBuilt-in effect classes are located in thevoicebox.effectsmodule,
and can be imported like:fromvoicebox.effectsimportCoolEffectHere is a non-exhaustive list of fun effects:Glitchcreates a glitchy sound by randomly repeating small chunks of audio.RingModcan be used to create choppy, Doctor Who Dalek-like effects.Vocoderis useful for making monotone, robotic voices.There is also support for all the awesome audio plugins inSpotify'spedalboardlibraryusing the specialPedalboardEffectwrapper, e.g.:fromvoiceboximportSimpleVoiceboxfromvoicebox.effectsimportPedalboardEffectimportpedalboardvoicebox=SimpleVoicebox(effects=[PedalboardEffect(pedalboard.Reverb()),...,])ExamplesMinimal# PicoTTS is used to say "Hello, world!"fromvoiceboximportSimpleVoiceboxvoicebox=SimpleVoicebox()voicebox.say('Hello, world!')Pre-builtSome pre-built voiceboxes are available in thevoicebox.examplespackage.
They can be imported into your own code, and you can run them to demo:# Voice of GLaDOS from the Portal video game seriespython-mvoicebox.examples.glados"optional message"# Voice of the OOM-9 command battle droid from Star Wars: Episode Ipython-mvoicebox.examples.battle_droid"optional message"Advanced# Use eSpeak NG at 120 WPM and en-us voice as the TTS enginefromvoicebox.ttsimportESpeakConfig,ESpeakNGtts=ESpeakNG(ESpeakConfig(speed=120,voice='en-us'))# Add some voice effectsfromvoicebox.effectsimportVocoder,Glitch,Normalizeeffects=[Vocoder.build(),# Makes a very robotic, monotone voiceGlitch(),# Randomly repeats small sections of audioNormalize(),# Remove DC and make volume consistent]# Send audio to playback device, and save to speech.wav filefromvoicebox.sinksimportDistributor,SoundDevice,WaveFilesink=Distributor([SoundDevice(),WaveFile('speech.wav'),])# Build the voiceboxfromvoiceboximportSimpleVoiceboxvoicebox=SimpleVoicebox(tts,effects,sink)# eSpeak NG is used to say "Hello, world!" with a glitchy robot voicevoicebox.say('Hello, world!')Command Line Demopython-mvoicebox-h# Print command helppython-mvoicebox"Hello, world!"# Basic usage