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.bashHost 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.shThen 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-onnxThen 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 Name | play_audio |
|---|---|
| Prototype | bool play_audio(str file_name, int volume = 100, float speed = 1.0) |
| Overview | Plays the specified audio file. |
| Parameters | file_name: audio file name speed: playback speed, default 1.0 |
| Return Value | true: playback request sent successfully false: failed to send playback request |
| Remarks | 1. The audio file must be placed in the robot system in advance |
| Function Name | stop_music |
|---|---|
| Prototype | bool stop_music() |
| Overview | Stops the audio currently being played. |
| Parameters | None |
| Return Value | true: stop request sent successfully false: failed to send stop request |
| Remarks | None |
| Function Name | text_to_speech |
|---|---|
| Prototype | bool text_to_speech(str text, float volume = 0.5) |
| Overview | Converts text to speech and plays it. |
| Parameters | text: the text content to play |
| Return Value | true: playback request sent successfully false: failed to send playback request |
| Remarks | 1. 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:
-
Play an audio file:
kuavo_robot = KuavoRobotAudio() kuavo_robot.play_audio("2_抱拳.wav") # 播放指定音频文件 time.sleep(3) # 等待播放完成 -
Text-to-speech:
kuavo_robot.text_to_speech("你好,世界") # 播放文本转语音 time.sleep(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()