This package lets your robot speak text out loud. Publish a string to the /tts ROS 2 topic and the node synthesizes speech and plays it through your speakers.
It uses Coqui TTS (tts_models/en/ljspeech/vits) — a high-quality neural TTS engine that runs completely offline. No internet, no API key, no account needed.
This guide assumes you are running Ubuntu 22.04 with ROS 2 Humble already installed.
ros2 topic pub /tts → tts_topic_node → Coqui TTS → aplay → speakers
Publish "Hello world" to /tts and your speakers say it.
Check ROS 2 is installed:
ros2 --versionCheck your ROS 2 workspace exists:
ls ~/final_project_ws/srcIf it does not exist:
mkdir -p ~/final_project_ws/srcInstall aplay (ALSA audio player) used to play the synthesized WAV file:
sudo apt update
sudo apt install alsa-utilsTest it works:
aplay --versionClone this repository into your ROS 2 workspace:
cd ~/final_project_ws/src
git clone https://github.com/Final-Project-ROS2/tts.gitInstall Coqui TTS. On Ubuntu 22.04+ with a managed Python environment, use:
pip install coqui-tts --break-system-packagesIf you are inside an active virtual environment (tts_venv or similar), use the venv's pip directly to avoid the system restriction:
~/tts_venv/bin/pip install coqui-ttsThe first time the node starts, Coqui TTS will automatically download the
tts_models/en/ljspeech/vitsmodel (~100 MB). This only happens once; subsequent runs load from cache.
Important: Run colcon build from the workspace root (~/final_project_ws), not from inside the package directory.
cd ~/final_project_ws
colcon build --packages-select ttsYou should see:
Starting >>> tts
Finished <<< tts
Load the package into your terminal session:
source ~/final_project_ws/install/setup.bashAdd this line to
~/.bashrcto avoid running it every time:echo "source ~/final_project_ws/install/setup.bash" >> ~/.bashrc
ros2 run tts tts_nodeYou should see:
[tts_topic_node]: Loading Coqui TTS model...
[tts_topic_node]: TTS Topic Node Ready. Listening on /tts
The node is now running and waiting for text to speak.
Open a second terminal and publish a message:
ros2 topic pub --once /tts std_msgs/msg/String "data: 'Hello from ROS 2'"Your speakers should say the words out loud. Change the text inside the single quotes to anything you want.
| Topic | Type | Direction | Description |
|---|---|---|---|
/tts |
std_msgs/msg/String |
Subscribe | Text to be spoken aloud |
Check that aplay can play audio:
aplay /usr/share/sounds/alsa/Front_Left.wavIf you hear nothing, check your system's audio output device.
sudo apt install alsa-utilspip install coqui-ttsCheck the node is receiving messages. In a second terminal:
ros2 topic echo /ttsThen publish in a third terminal. You should see the message appear. If not, the topic name may be wrong.
Make sure you are in the right folder:
cd ~/final_project_ws
source install/setup.bash| Task | Command |
|---|---|
| Install audio player | sudo apt install alsa-utils |
| Install Coqui TTS | pip install coqui-tts --break-system-packages |
| Build | cd ~/final_project_ws && colcon build --packages-select tts |
| Load into terminal | source ~/final_project_ws/install/setup.bash |
| Start the node | ros2 run tts tts_node |
| Send text to speak | ros2 topic pub --once /tts std_msgs/msg/String "data: 'your text here'" |
Apache-2.0