Unveiling the Power of Offline TTS with Raspberry Pi and SaraKIT
As of 2024, we've scoured the internet to bring you what appears to be the best Text-to-Speech (TTS) solution for Raspberry Pi. If you find something even better, we're all ears!
Our chosen TTS solution takes advantage of the SaraKIT, which is not only equipped with a stereo amplifier but also boasts three microphones and a specialized audio processor. This setup cleans up voice audio and supports speech recognition from distances up to 16.4 feet, enabling the development of sophisticated projects that we detail on our website.
While TTS doesn't require SaraKIT—you could even use simple headphones or a basic speaker—the full setup shines when used to create voice assistants, speaking devices, or integrated home automation systems. While online services like ElevenLabs offer top-quality voice synthesis for a fee, and Google Text to Speech provides accessible voice services, our focus here is on robust offline processing.
After a thorough search for the best, fast, and easy-to-install offline TTS solution, Piper stands out as the premier choice. Piper is fast, delivers high-quality voice output in real-time, and is optimized for Raspberry Pi 4. To make the installation process as straightforward as possible, we've simplified it further for you. You can find a demonstration and detailed guide below.
Test Piper's capabilities at the following link:
https://rhasspy.github.io/piper-samples
This setup enhances the Raspberry Pi’s audio handling capabilities and is ideal for anyone looking to implement advanced voice interactions without relying on internet connectivity. Our project not only showcases how to set up Piper but also invites the community to improve and expand upon it. If you have your own code enhancements or alternative solutions in C++ or Python, please share them, and we might feature your contribution in our repository.
Piper on GitHub:https://github.com/rhasspy/piperhttps://github.com/rhasspy/piper-phonemize (an additional component)
Voices for Piper:https://huggingface.co/rhasspy/piper-voices/tree/main
Installation on SaraKITAssuming the basic SaraKIT drivers are already installed https://sarakit.saraai.com/getting-started/software, follow these steps to install Piper:
sudo apt-get install libasound2-dev
sudo apt-get install libfmt-dev
sudo apt-get install libspdlog-dev
git clone https://github.com/SaraEye/SaraKIT-Text-To-Speech-Piper-Raspberry-Pi piper
cd piper
sudo cp -r lib/piper/lib/*.* /usr/local/lib/
sudo ldconfig
make
To use a language other than English, download the required language model from https://huggingface.co/rhasspy/piper-voices/tree/main and place it in a directory, e.g., `lib/piper/models`.
Start speech recognition by running:
./ttsDemo
Below is the text to speech script in your chosen language, available at:https://github.com/SaraEye/SaraKIT-Text-To-Speech-Piper-Raspberry-Pi:
#include <functional>
#include <iostream>
#include <string>
#include <signal.h>
#include "lib/piper/piperclass.hpp"
using namespace std;
int main() {
//Choose your language and voice
piper::PiperClass piper("lib/piper/models/en/amy/en_US-amy-medium.onnx", "lib/piper/lib/espeak-ng-data");
while (true) {
string text;
cout << "Enter the text to synthesize (CTRL+C to finish): ";
getline(cin, text);
piper.say(text);
}
return EXIT_SUCCESS;
}
The effects of this simple yet powerful script can be seen in the video below:
See also our other project:https://www.hackster.io/sarakit/sarakit-speech-magic-raspberry-pi-voice-recognition-4c6a5a
SaraKIT Home Page:https://sarakit.saraai.com/
Comments