5.2.8 Text-to-Speech
Overview
This section describes how to convert text into speech signals and play them through the audio output interface.
Code repository: (https://github.com/D-Robotics/hobot_tts.git)
Supported Platforms
| Platform | Runtime Environment | Example Function |
|---|---|---|
| RDK X3 | Ubuntu 20.04 (Foxy), Ubuntu 22.04 (Humble) | Subscribe to text messages, convert them to speech data, and play them |
| RDK X5, RDK X5 Module | Ubuntu 22.04 (Humble) | Subscribe to text messages, convert them to speech data, and play them |
| RDK S100, RDK S100P | Ubuntu 22.04 (Humble) | Subscribe to text messages, convert them to speech data, and play them |
| RDK S600 | Ubuntu 24.04 (Jazzy) | Subscribe to text messages, convert them to speech data, and play them |
Note: Only RDK X3 is supported; RDK X3 Module is not supported. RDK S100/S600 only supports USB audio devices.
Prerequisites
RDK Platform
- RDK has been flashed with the Ubuntu system image.
- TogetheROS.Bot has been successfully installed on RDK.
- An RDK-compatible audio driver board is available, and the environment has been set up according to the Smart Audio section.
- Headphones or speakers are connected to the audio board headphone jack.
Usage
RDK Platform
-
On first run, download and extract the model file. Run the following commands:
- Foxy
- Humble
- Jazzy
# Configure tros.b environment
source /opt/tros/setup.bash# Configure tros.b environment
sudo apt update
sudo apt install tros-humble-hobot-tts
source /opt/tros/humble/setup.bash# Configure tros.b environment
sudo apt update
sudo apt install tros-jazzy-hobot-tts
source /opt/tros/jazzy/setup.bashwget http://archive.d-robotics.cc/tts-model/tts_model.tar.gz
sudo tar -xf tts_model.tar.gz -C /opt/tros/${TROS_DISTRO}/lib/hobot_tts/
If the sudo apt update command fails or reports an error, please refer to the FAQ section Q10: How to handle apt update command failure or error? for resolution.
If the sudo apt update command fails or reports an error, please refer to the FAQ section Q6: How to handle apt update command failure or error? for resolution.
-
Run the following command to check whether the audio device is working properly:
root@ubuntu:~# ls /dev/snd/
by-path controlC0 pcmC0D0c pcmC0D1p timerIf an audio playback device such as
pcmC0D1pappears, the device is working properly.On first use of the audio board, configure it using
srpi-config. For configuration instructions, refer to the RDK user manual RDK X3 Waveshare Audio Drive section.On first use of the audio board, configure it using
srpi-config. For configuration instructions, refer to the RDK user manual RDK X5 Waveshare Audio Drive section. -
Start the hobot_tts program
- Foxy
- Humble
- Jazzy
# Configure tros.b environment
source /opt/tros/setup.bash# Configure tros.b environment
source /opt/tros/humble/setup.bash# Configure tros.b environment
source /opt/tros/jazzy/setup.bash# Suppress debug log output
export GLOG_minloglevel=1
ros2 run hobot_tts hobot_ttsNote: If the audio playback device is not
pcmC0D1p, use theplayback_deviceparameter to specify the playback device. For example, if the playback device ispcmC1D1p, the Waveshare board startup command is:ros2 run hobot_tts hobot_tts --ros-args -p playback_device:="hw:1,1"; the USB audio device startup command is:ros2 run hobot_tts hobot_tts --ros-args -p playback_device:="plughw:1,1" -
Open a new terminal and use the echo command to publish a topic
- Foxy
- Humble
- Jazzy
# Configure tros.b environment
source /opt/tros/setup.bash
# Configure tros.b environment
source /opt/tros/humble/setup.bash
# Configure tros.b environment
source /opt/tros/jazzy/setup.bash
ros2 topic pub --once /tts_text std_msgs/msg/String "{data: ""你知道D-Robotics 吗?是的,我知道D-Robotics 。它是一条从地面延伸到天空的线,它定义了地面和天空之间的分界线。""}"
- You should hear the audio playback through headphones or speakers
Notes
Currently only Chinese and English text content is supported. Do not publish text messages in other languages.