This contains code (and libs) necessary to make portable programs for inference with FastSpeech2 (MFA-aligned phonetic) and MB-MelGAN on desktop, along with a simple example.
The program requires two things:
- An exported and packed TTS model (FS2 + MB-MelGAN). Colab notebook linked below will show
- A G2P-RNN model. See here for details.
If you want to convert your model to the format that this program expects, you can check out the notebook:
It includes a set of easily understandable and modular classes including a simple English text preprocessor, so you can easily copy and integrate them into your program.
Inference is even easier than in Python. First you need a Phonemizer, then the voice.
#include "Voice.h"
std::string LanguagePath = "g2p/English"
std::string VoicePath = "LJ";
Phonemizer Phony;
Phony.Initialize(LanguagePath);
// The Voice class takes a pointer to the Phonemizer to use it.
// Don't let it go out of scope!
Voice LJSpeech(VoicePath,VoicePath,&Phony);
std::vector<float> AudioData = LJSpeech.Vocalize("I love see plus plus" + LJSpeech.GetInfo().EndPadding);
VoxUtil::ExportWAV("voc1.wav", AudioData, LJSpeech.GetInfo().SampleRate);
The demo program is available for download to use for Windows and Linux (Ubuntu 18.04), both x64. It can take command line arguments (see code for details), but defaults should be fine for mere LJSpeech testing.
To use it, do the following depending on platform:
- Download the Windows x64 binary and LJSpeech model
- Extract to whatever directory you like
- Run
Tested in Ubuntu 18.04 LTS
- Download the Linux x64 binary and LJSpeech model
- Extract to whatever directory you like
- Navigate with terminal
LD_LIBRARY_PATH=lib ./TensorflowTTSCppInference
For compiling it yourself, see Compiling below
Compiling the demo depends on what platform. Currently two have been tested:
- Windows 10 x64; MSVC 2019
- Linux(Ubuntu) x64: GCC 7.5.0
Note that to test out your shiny new build afterwards you'll have to download the LJSpeech model (or make one yourself), it's bundled in any of the above precompiled demo download links.
Download the dependencies (hint: it's just Tensorflow C API) and drop the deps folder into the same place as the .sln and .pro; it has both Linux and Windows versions.
The rest (such as CppFlow and AudioFile) are included in the source code
Use the Visual Studio solution file.
Tested with compiler gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
.
sudo apt install qt5-default
qmake TensorflowTTSCppInference.pro
make
- Tensorflow library malfunctions in debug builds, so only build release.
- Tensorflow C API: https://www.tensorflow.org/install/lang_c
- CppFlow (TF C API -> C++ wrapper): https://github.com/serizba/cppflow
- AudioFile (for WAV export): https://github.com/adamstark/AudioFile
- nlohmann/json: JSON for Modern C++
- jarro2783/cxxopts: Lightweight C++ command line option parser)