Kuavo Docs
Development InterfacesPython SDK Guide

Audio Playback Interfaces

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

Usage Instructions

The host computer must be switched to the dev branch for the following steps to work properly. Remember to back up your code before switching branches.

cd ~/kuavo_ros_application
git checkout dev
catkin build kuavo_msgs kuavo_camera dynamic_biped kuavo_tf2_web_republisher ar_control kuavo_audio_player
source devel/setup.bash

Host Computer Is SWNUC12WSKI70000 (i.e., Not NX or AGX)

Run the following in the ~/kuavo_ros_application/src/kuavo_speech_synthesis directory:

# 上位机代码需要处于dev分支
  sudo su && ./install.sh

Then run the following in the ~/kuavo_ros_application directory:

 catkin build kuavo_speech_synthesis
 source devel/setup.bash
 roslaunch kuavo_speech_synthesis speech_synthesis.launch

Host Computer Is NX or AGX:

  • Because the offline model is large, the download may take 10–20 minutes; please be patient. After installation and deployment are complete, a success message in green text will be displayed.
    pip install --upgrade soundfile librosa==0.11.0 scipy
    pip install sherpa-onnx

Then run the following in the ~/kuavo_ros_application directory:

 catkin build kuavo_speech_synthesis
 source devel/setup.bash
 roslaunch kuavo_speech_synthesis speech_synthesis.launch

Interface Description

KuavoRobotAudio

The KuavoRobotAudio class provides interfaces for controlling robot audio playback.

Method Interfaces

Function Nameplay_audio
Prototypebool play_audio(str file_name, int volume = 100, float speed = 1.0)
OverviewPlays the specified audio file.
Parametersfile_name: audio file name
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
Function Namestop_music
Prototypebool stop_music()
OverviewStops the audio currently being played.
ParametersNone
Return Valuetrue: stop request sent successfully
false: failed to send stop request
RemarksNone
Function Nametext_to_speech
Prototypebool text_to_speech(str text, float volume = 0.5)
OverviewConverts text to speech and plays it.
Parameterstext: the text content to play
Return Valuetrue: playback request sent successfully
false: failed to send playback request
Remarks1. Supports Chinese text-to-speech

Example Code

Refer to the SDK example code:

Audio playback: /home/lab/kuavo-ros-opensource/src/kuavo_humanoid_websocket_sdk/examples/atomic_skills/audio_play.py

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

The example code demonstrates the following main features:

  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:

  • Before playing an audio file, ensure that the file already exists in the robot system
  • When playing text-to-speech, it is recommended to wait a while to ensure playback completes
  • You can stop the current playback at any time with stop_music()