Kuavo Docs
Feature ExamplesGeneral Examples

Integrating the Doubao Realtime Voice Model Case

Case Introduction

Overview

  • This case integrates the Doubao Realtime Voice Model to implement a ROS-based voice interaction system, including microphone audio capture, realtime voice interaction, and audio playback.

  • Example code path: ~/kuavo_ros_application/src/kuavo_doubao_model/llm_doubao.py

Program Logic

  1. Import modules and define global variables
  • Purpose: Import the required Python standard libraries, third-party libraries, and ROS-related modules, and define the core interaction classes.
  1. RODialogSession class
  • Purpose: Handle WebSocket communication with the Doubao Realtime Voice Model, and manage the reception and processing of audio data as well as ROS publishing.

  • Key logic:

    • Initialize the session ID and WebSocket client, and establish a connection with the Doubao model

    • Process audio chunks in a separate thread to buffer and process audio data

    • Convert audio byte data into a ROS-compatible integer list format

    • Perform audio resampling (from 24kHz to 16kHz) to adapt to the ROS audio system

    • Publish the processed audio data to a ROS topic

  1. RobotLLMDoubaoCore class
  • Purpose: Serve as the core of the system, managing microphone audio capture, the session lifecycle, and the overall interaction flow.

  • Key logic:

    • Initialize the microphone interface and the ROS audio interface

    • Configure WebSocket connection parameters, including authentication information

    • Verify the connection to the Doubao model service

    • Start and stop the voice interaction system

    • Run the asynchronous session in a separate thread, handling microphone data and server communication

  1. Main program code path: ~/kuavo_ros_application/src/kuavo_doubao_model/start_communication.py
  • Purpose: The main entry point of the program, responsible for initializing the ROS node, establishing the Doubao voice connection, starting voice interaction, and handling exit logic.

  • Key logic:

    • Initialize the ROS node voice_conversation

    • Create a RobotSpeech instance to manage voice interaction

    • Call the establish_doubao_speech_connection method to establish a connection with the Doubao model using the provided app_id and access_key

    • Once connected, call the start_speech method to start voice interaction

    • Enter a loop that detects keyboard input in a non-blocking manner

    • When user input 'c' is detected or the ROS node shuts down, call the stop_speech method to stop voice interaction

  1. ActionController class
  • Purpose: Parse and execute robot actions based on voice commands, including motion control and gesture actions.

  • Key logic:

    • Support mixed recognition of Arabic numerals and Chinese numerals

    • Initialize the action mapping system, configuring direction control commands (move forward/backward/left/right, turn) and routine gesture action execution

    • Set up a random action execution mechanism

    • Execute action scripts asynchronously using subprocesses to avoid blocking the main program

Environment Setup

Installing Host Computer Dependencies

  • Install the required dependencies
# Install audio-related system libraries and USB audio support
sudo apt install -y portaudio19-dev python3-pyaudio pulseaudio-module-udev
# Install Python dependencies
python3 -m pip install librosa==0.11.0
  • Load the USB audio module
sudo modprobe snd-usb-audio

Obtaining the Doubao Token

⚠️ Note: This case uses Volcano Engine's Doubao end-to-end realtime voice model. This is a paid model, so you need to create an account, top up, and obtain the APP ID and Access Token, then copy the obtained APP ID and Access Token to the corresponding places in the program. When using it, the robot's host computer must be connected to the external network (able to access the Internet).

  • The Doubao end-to-end realtime voice model used in this case: https://console.volcengine.com/ark/region:ark+cn-beijing/tts/realTimeRecognition

    • After logging in, click Large Models - Doubao Realtime Voice Model - Use Now to obtain the APP ID and Access Token
    • Replace app_id and access_key on lines 22 and 23 of the program ~/kuavo_ros_application/src/kuavo_doubao_model/start_communication.py with the values you obtained

Running the Example

Run Steps

  • To run this case, you need to connect a USB microphone to the host computer, preferably one with a one-touch mic on/off button.
  • It is recommended to first test whether the external microphone works in the host computer's system settings.
  • To check the name of the external microphone, enter arecord -l in the terminal or check it in the system settings.
  • Change the external microphone name to target_mic_keywords on line 372 of ~/kuavo_ros_application/src/ros_audio/kuavo_audio_receiver/scripts/micphone_receiver_node.py (default: USB Composite Device)
  • Switch the host computer repository version to 1.1.0; the lower-level computer needs to be switched to 1.4.1
  • Start
    cd kuavo_ros_application  # Enter the host computer workspace (switch according to the actual deployment directory)
    source devel/setup.bash
    roslaunch kuavo_audio_receiver receive_voice.launch
    Result
    • Open another terminal and enter rosnode list | grep audio_player_node to check whether audio_player_node exists; if it does, skip running play_music.launch.
    • Connect the speaker to the lower-level computer
    cd kuavo-ros-opensource  # Enter the lower-level computer workspace (switch according to the actual deployment directory)
    sudo su
    source devel/setup.bash
    roslaunch kuavo_audio_player play_music.launch 
    • Connect the speaker to the host computer
    cd kuavo_ros_application  # Enter the host computer workspace (switch according to the actual deployment directory)
    source /opt/ros/noetic/setup.bash
    source devel/setup.bash
    roslaunch kuavo_audio_player play_music.launch 
    • Run the case
    cd kuavo_ros_application  # Enter the host computer workspace (switch according to the actual deployment directory)
    source devel/setup.bash
    python3 src/kuavo_doubao_model/start_communication.py 
    Result

Parameter Description

Voice Interaction Parameter Configuration

Motion Control Parameter Configuration

  • Program file location: ~/kuavo_ros_application/src/kuavo_doubao_model/action_controllers.py
  • Action folder location: ~/kuavo_ros_application/src/kuavo_doubao_model/hand_plan_arm_trajectory/action_files
  • Voice-to-action mapping:
KeywordActionRestriction
Walk forward (backward/left/right) n stepsCall the single-step interface to control walking forward (backward/left/right) n steps1~10 steps
Turn left (right) n degreesCall the position control interface to control turning left (right) n degreesTurn left (right) 0~180 degrees
HandshakeExecute 握手.tact
GreetExecute 打招呼_45.tact
Thumbs up点赞_45.tact
Talk & action (e.g., perform actions while talking)Execute random actions while talking
Don't do actions (no action/stop doing actions)Do not execute random actions while talking

Notes

  • By default, the robot executes a random action file under action_files while talking
  • If a single sentence contains multiple keywords, one action is triggered in the order in action_controllers.py; multiple actions will not be triggered at the same time