Skip to main content

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

PlatformRuntime EnvironmentExample Function
RDK X3Ubuntu 20.04 (Foxy), Ubuntu 22.04 (Humble)Subscribe to text messages, convert them to speech data, and play them
RDK X5, RDK X5 ModuleUbuntu 22.04 (Humble)Subscribe to text messages, convert them to speech data, and play them
RDK S100, RDK S100PUbuntu 22.04 (Humble)Subscribe to text messages, convert them to speech data, and play them
RDK S600Ubuntu 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

  1. RDK has been flashed with the Ubuntu system image.
  2. TogetheROS.Bot has been successfully installed on RDK.
  3. An RDK-compatible audio driver board is available, and the environment has been set up according to the Smart Audio section.
  4. Headphones or speakers are connected to the audio board headphone jack.
  1. RDK has been flashed with the Ubuntu system image.
  2. TogetheROS.Bot has been successfully installed on RDK.
  3. Headphones or speakers are connected to the audio board headphone jack.

Usage

RDK Platform

  1. On first run, download and extract the model file. Run the following commands:

    # 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.bash
    wget 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/
Note

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.

Note

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.

Note

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.

Note

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.

  1. Run the following command to check whether the audio device is working properly:

    root@ubuntu:~# ls /dev/snd/
    by-path controlC0 pcmC0D0c pcmC0D1p timer

    If an audio playback device such as pcmC0D1p appears, 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.

  2. Start the hobot_tts program

    # 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_tts

    Note: If the audio playback device is not pcmC0D1p, use the playback_device parameter to specify the playback device. For example, if the playback device is pcmC1D1p, 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"

  3. Open a new terminal and use the echo command to publish a topic

# 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 。它是一条从地面延伸到天空的线,它定义了地面和天空之间的分界线。""}"
  1. 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.