Skip to main content

5.2.8 Text-to-Speech

Feature Introduction

This section describes how to convert a piece of text into speech signals and play them through an audio output interface.

Code repository: (https://github.com/D-Robotics/hobot_tts.git)

Supported Platforms

PlatformRuntime EnvironmentExample Functionality
RDK X3Ubuntu 20.04 (Foxy), Ubuntu 22.04 (Humble)Subscribe to text messages, convert them into speech data, and then play the audio
RDK X5, RDK X5 ModuleUbuntu 22.04 (Humble)Subscribe to text messages, convert them into speech data, and then play the audio
RDK S100, RDK S100PUbuntu 22.04 (Humble)Subscribe to text messages, convert them into speech data, and then play the audio

Note: Only RDK X3 is supported; RDK X3 Module is currently unsupported. RDK S100 supports only USB audio devices.

Prerequisites

RDK Platform

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

Usage Instructions

RDK Platform

  1. On first run, you need to download and extract the model files using the following commands:

    # Configure the tros.b environment
    source /opt/tros/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 returns an error, refer to the FAQ section Common Issues, specifically Q10: "How to resolve issues when apt update fails or returns errors?"

  1. Run the following command to check whether the audio device is functioning 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 correctly.

    When using the audio board for the first time, you must configure it using srpi-config. For configuration instructions, refer to the RDK User Manual section: RDK X3 Waveshare Audio Driver.

  2. Launch the hobot_tts program:

    # Configure the tros.b environment
    source /opt/tros/setup.bash
    # Suppress debug log messages
    export GLOG_minloglevel=1

    ros2 run hobot_tts hobot_tts

    Note: If your audio playback device is not pcmC0D1p, you must specify the correct playback device using the playback_device parameter. For example, if the playback device is pcmC1D1p, use the following launch command:
    ros2 run hobot_tts hobot_tts --ros-args -p playback_device:="hw:1,1"

  3. Open a new terminal and publish a message to the topic using the echo command:

# Configure the tros.b environment
source /opt/tros/setup.bash
ros2 topic pub --once /tts_text std_msgs/msg/String "{data: ""Do you know D-Robotics? Yes, I know D-Robotics. It is a line stretching from the ground to the sky, defining the boundary between earth and sky.""}"
  1. You should hear the audio played through your headphones or speakers.

Notes

Currently, only Chinese and English text content are supported. Do not publish text messages in other languages.