Path: blob/master/examples/cpptflite/README.md
1558 views
C++ Inference using TFlite
TensorFlow Lite is an open source deep learning framework for on-device inference. On Android and Linux (including Raspberry Pi) platforms, we can run inferences using TensorFlow Lite APIs available in C++. The repository TensorFlowTTS and TensorFlow Lite help developers run popular text-to-speech (TTS) models on mobile, embedded, and IoT devices.
TFlite model convert method
Method see colab notebook.
Notes:
Quantization will deteriorate vocoder and bring noise, so the vocoder doesn't do optimization.
TensorFlow Lite in C++ doesn't support the TensorFlow operation of Dropout. So the inference function need delete Dropout before converting tflite model, and it doesn't affect the inference result. For example, fastspeech2 models:
About Code
TfliteBase.cpp: A base class for loading tflite-model and creating tflite interpreter. By inheriting from this class, you can implement specific behavior, like Mel-spectrogram and Vocoder.
TTSFrontend.cpp: Text preprocessor converts string to ID based on your desiged phoneme2ID dict, which needs a text to pronunciation module, like g2p for English and pinyin for Chinese.
TTSBackend.cpp: It contains two-step process - first generating a Mel-spectrogram from phoneme-ID sequence and then generating the audio waveform by Vocoder.
Using the demo
A demo of English or Mandarin TTS and the tflite-models are available for linux platform. The pretrained models to be converted are download from the colab notebook (English or Mandarin). Mel-generator and Vocoder select FastSpeech2 and Multiband-MelGAN, respectively.
Notes: The text2ids function in TTSFrontend.cpp is implemented by using bash command in C++ instead of developing a new pronunciation module (see /demo/text2ids.py). In fact, it is not a recommended method, and you should redevelop a appropriate text2ids module, like the code in examples/cppwin.
Firstly, it should compile a Tensorflow Lite static library. The method see the reference from the official guidance of Tensorflow.
Execute the following command to compile a static library for linux:
(The official also provides different complie methods for other platforms (such as rpi, aarch64, and riscv), see /tensorflow/lite/tools/make/)
Because this process takes much time, so a static library builded for linux is also available (libtensorflow-lite.a).
The structure of the demo folder should be:
The two folders of flatbuffers/ and tensorflow/lite/ provide the required header files.
Then,
English Demo (using LJSPEECH dataset)
or Mandarin Demo (using Baker dataset)
Results
Comparison before and after conversion (English TTS)
Before conversion (Python)

After conversion (C++)

Adding #3 in chinese text will create pause prosody in audio

