Roban2 Docs
Roban2 (ROS1) Legacy VersionsDevelopment InterfacesHumanoid SDK Interfaces

Audio Playback Interface

The Humanoid SDK provides a comprehensive set of audio playback interfaces, supporting playback of audio files, text-to-speech, and other functions. This document describes in detail how to use these interfaces.

Usage Instructions

Before using these interfaces, you need to perform the following operations on the host computer (these operations must be performed regardless of the host computer model):

In the <kuavo_ros_application>/src/kuavo_speech_synthesis directory, execute the following:

  sudo su && ./install.sh
  • Because the offline model is large, the download process may take 10–20 minutes, so please wait patiently. After installation and deployment are complete, a green success message will appear.

Interface Description

RobotAudio

The RobotAudio class provides interfaces for controlling robot audio playback.

Method Interfaces

Function Nameplay_audio
Function Prototypebool play_audio(str file_name, int volume = 100, float speed = 1.0)
Function OverviewPlays the specified audio file.
Parametersfile_name: Audio file name
volume: Volume level, range [0, 100], default 100
speed: Playback speed, default 1.0
Return Valuetrue: Playback request sent successfully
false: Failed to send playback request
Remarks1. The audio file must be placed in the robot system in advance
2. The volume is automatically limited to the valid range
Function Namestop_music
Function Prototypebool stop_music()
Function OverviewStops the audio currently being played.
ParametersNone
Return Valuetrue: Stop request sent successfully
false: Failed to send stop request
RemarksNone
Function Nametext_to_speech
Function Prototypebool text_to_speech(str text, float volume = 0.5)
Function OverviewConverts text to speech and plays it.
Parameterstext: The text content to be played
volume: Volume level, range [0.0, 1.0], default 0.5
Return Valuetrue: Playback request sent successfully
false: Failed to send playback request
Remarks1. Supports Chinese text-to-speech
2. The volume is automatically limited to the valid range

Example Code

Refer to the SDK example code:

Audio playback: <kuavo-ros-opensource>/src/kuavo_humanoid_websocket_sdk/examples/atomic_skills/audio_play.py

Demonstrates how to control the robot via the SDK to play audio files and perform text-to-speech.

The example code demonstrates the following main functions:

  1. Play an audio file:

    kuavo_robot = KuavoRobotAudio()
    kuavo_robot.play_audio("2_抱拳.wav")  # 播放指定音频文件
    time.sleep(3)  # 等待播放完成
  2. Text-to-speech:

    kuavo_robot.text_to_speech("你好,世界")  # 播放文本转语音
    time.sleep(3)  # 等待播放完成
  3. Stop playback:

    kuavo_robot.stop_music()  # 停止当前播放

Notes:

  • Make sure the audio file exists in the robot system before playing it
  • You can adjust the volume via the volume parameter
  • When playing text-to-speech, it is recommended to wait a while to ensure playback completes
  • Use stop_music() to stop the current playback at any time