Welcome to ROSMASTER M1 repository
8. AI large model online voice assistant
AI Large-Scale Online Voice Assistant
AI Large-Scale Online Voice Assistant1. Online Voice Configuration2. Create a Systemd Service2.1 Raspberry Pi 52.1.1 Creating a Docker Container Startup Script2.1.2 If you are using the factory image of Yabo's large AI model, you do not need to recreate the script. Simply run the following command to restart the auto-start service:2.1.3 Related Commands:2.1.4 CSI Camera Auto-Start ServiceIf you are using the factory image of Yabo's large AI model, you do not need to recreate the script. Simply run the following command to restart the auto-start service:2.2 RDK X52.2.1 Creating a Startup Script2.2.2 Create Systemd service file2.2.3 Managing and Debugging the Service2.3 ORIN2.3.1 Create a startup script2.3.2 Creating the Systemd Service File2.3.3 Managing and Debugging the Service
1. Online Voice Configuration
Before setting up auto-start, we must ensure that the program itself can work independently while online. This needs to be done by modifying the configuration file.
Raspberry Pi 5 requires entering a Docker container; RDK X5 and Orin controllers do not:
xxxxxxxxxx./ros2_docker.sh
If you need to enter other commands in the same Docker container later, simply enter ./ros2_docker.sh again in the host terminal.
Open the configuration file:
xxxxxxxxxxvim ~/yahboom_ws/src/largemodel/config/yahboom.yamlModify Configuration Parameters: Please check the following parameters in the file and ensure that their values match those shown below. If the parameters do not exist, add them.
xxxxxxxxxxasr#Voice node parametersros__parametersVAD_MODE2 #vad sensitivitysample_rate16000 #asr recording audio sampling rateframe_duration_ms30 #vad frame size in msuse_oline_asrTrue #Whether to use online ASR recognition (True uses online, False uses offline)mic_serial_port"/dev/ttyUSB0" #Microphone serial port aliasmic_index0 #Microphone Indexlanguage'zh' #asr languagemodel_service#Model server node parametersros__parameterslanguage'zh' #Large Model Interface LanguageuseolinettsTrue #Whether to use online speech synthesis (True uses online, False uses offline)llm_platform'tongyi' # Here we take Tongyi as an exampleuse_oline_asranduseolinettsmust be set totongyi.llm_platformmust be set totongyi.With this setup, everything is online.
Save the file and recompile the project to apply the changes. This requires building within a Docker container:
xxxxxxxxxxcd ~/yahboom_wscolcon buildsource install/setup.bash
After completing this step, the program is now a fully online voice service.
2. Create a Systemd Service
Now, we will create a systemd service to automatically run largemodel_control.launch.py at system startup.
Note: If you are using the Yabo AI Large Model factory image, these scripts are already created; you only need to restart the auto-start container.
2.1 Raspberry Pi 5
2.1.1 Creating a Docker Container Startup Script
- Creating a Script File:
In your home directory (~), create a file named ros2_docker_autostart.sh.
xxxxxxxxxx vim ~/ros2_docker_autostart.shWrite the script content: Copy and paste the following content into the script file.
xxxxxxxxxxset -eCN=${CONTAINER_NAME:-ros_humble_ai_service}IMG=${IMAGE_NAME:-ros_humble_ai:v1.0}WS=${HOST_WS_DIR:-"$HOME/yahboom_ws"}ROS=${ROS_DISTRO:-humble}CMD=${LAUNCH_CMD:-"ros2 launch largemodel largemodel_control.launch.py"}AUID=${AUDIO_UID:-$(id -u)}XAUTH=${XAUTHORITY:-"$HOME/.Xauthority"}mkdir -p "$WS"x=()if [ -d /tmp/.X11-unix ]; thencommand -v xhost >/dev/null 2>&1 && xhost +local:root || truex+=( -e DISPLAY=${DISPLAY:-:0} -e QT_X11_NO_MITSHM=1 -v /tmp/.X11-unix:/tmp/.X11-unix )[ -f "$XAUTH" ] && x+=( -v "$XAUTH:/root/.Xauthority" -e XAUTHORITY=/root/.Xauthority )fia=()if [ -S "/run/user/$AUID/pulse/native" ]; thena+=( -e PULSE_SERVER=unix:/run/user/$AUID/pulse/native -v "/run/user/$AUID/pulse:/run/user/$AUID/pulse:ro" )[ -d "$HOME/.config/pulse" ] && a+=( -v "$HOME/.config/pulse:/root/.config/pulse:ro" )fid=()[ -e /dev/video0 ] && d+=( --device=/dev/video0 )[ -d /dev/bus/usb ] && d+=( --device=/dev/bus/usb )[ -d /dev/snd ] && d+=( --device=/dev/snd )[ -e /dev/mic ] && d+=( -v /dev/mic:/dev/mic )if docker ps -a --format '{{.Names}}' | grep -qx "$CN"; thendocker ps --format '{{.Names}}' | grep -qx "$CN" || docker start "$CN" >/dev/nullelsedocker run -d \--name "$CN" --net=host --privileged --restart unless-stopped \--security-opt apparmor:unconfined \-v "$WS:/root/yahboom_ws:rw" \"${d[@]}" "${x[@]}" "${a[@]}" \"$IMG" \bash -lc "source /opt/ros/$ROS/setup.bash; [ -f /root/yahboom_ws/install/setup.bash ] && source /root/yahboom_ws/install/setup.bash; $CMD"fiecho "OK: $CN"Save and exit
Confirm Docker starts on boot:
xxxxxxxxxxsudo systemctl enable --now dockerGrant the script execute permissions, then run it:
xxxxxxxxxxchmod +x ~/ros2_docker_autostart.sh./ros2_docker_autostart.shverify:
xxxxxxxxxxdocker inspect -f '{{.HostConfig.RestartPolicy.Name}}' ros_humble_ai_serviceThe output should be "unless-stopped". After that, Docker will automatically start the container every time the machine boots up, which can achieve the effect of automatically starting the voice assistant.
2.1.2 If you are using the factory image of Yabo's large AI model, you do not need to recreate the script. Simply run the following command to restart the auto-start service:
xxxxxxxxxx~/ros2_docker_autostart.sh
2.1.3 Related Commands:
Immediately stop the container, and also stop automatic startup:
xxxxxxxxxxdocker stop ros_humble_ai_service
View the runtime logs of the Docker container:
xxxxxxxxxxdocker logs -f ros_humble_ai_service
2.1.4 CSI Camera Auto-Start Service
To access CSI footage from within Docker, the host_stream.py file on the host machine needs to be started.
Therefore, if you need to access CSI camera footage during auto-start, you also need to add this file to the Systemd startup service.
Note: If you are using the Yabo AI large model factory image, these scripts have already been created; you only need to restart the auto-start service.
1.Enter command to write file
xxxxxxxxxxsudo vim /etc/systemd/system/host-stream.service
2.Copy the following content into the file.
xxxxxxxxxx[Unit]Description=Host stream (runs ~/host_stream.py)After=network.target[Service]Type=simpleUser=piWorkingDirectory=/home/piExecStart=/usr/bin/python3 /home/pi/host_stream.pyRestart=on-failureRestartSec=5StandardOutput=append:/home/pi/host_stream.logStandardError=append:/home/pi/host_stream.log[Install]WantedBy=multi-user.target
- Save and exit
- Apply and start the service:
xxxxxxxxxxsudo systemctl daemon-reloadsudo systemctl enable host-stream.servicesudo systemctl start host-stream.service
- Check service status:
xxxxxxxxxxsudo systemctl status host-stream.serviceIf you see `Active: active (running)`, then the service has started successfully!6.If you do not need the CSI camera auto-start service, run the following command to stop it:
xxxxxxxxxxsudo systemctl stop host-stream.servicesudo systemctl disable host-stream.service
If you are using the factory image of Yabo's large AI model, you do not need to recreate the script. Simply run the following command to restart the auto-start service:
xxxxxxxxxxsudo systemctl enable host-stream.servicesudo systemctl start host-stream.service
2.2 RDK X5
2.2.1 Creating a Startup Script
To ensure that systemd can correctly load the ROS2 environment, the best practice is to create a simple bash script to encapsulate our startup command.
- Create the script file:
In the directory (~/yahboom_ws/src/largemodel/), create a file named start_largemodel.sh.
xxxxxxxxxx vim ~/yahboom_ws/src/largemodel/start_largemodel.shWrite the script content: Copy and paste the following content into the script file.
xxxxxxxxxx# Source ROS2 Humble environmentsource /opt/ros/humble/setup.bash# Source Yahboom workspace environmentsource /home/sunrise/yahboom_ws/install/setup.bash# Start the largemodel control scriptros2 launch largemodel largemodel_control.launch.pyImportant Note: Please ensure that
/home/sunrise/in the script is replaced with your own user home directory path.Save and exit
Grant script execution permissions:
xxxxxxxxxxchmod +x ~/yahboom_ws/src/largemodel/start_largemodel.sh
2.2.2 Create Systemd service file
Creating a Service File: You need to use
sudoprivileges to create this file.xxxxxxxxxxsudo vim /etc/systemd/system/largemodel.serviceWrite service configuration: Copy and paste the following content into the service file.
xxxxxxxxxx[Unit]Description=Robot ServiceAfter=network.target sound.target graphical.target multi-user.targetWants=network.target sound.target graphical.target multi-user.target[Service]Type=simpleUser=sunriseGroup=sunriseEnvironment=DISPLAY=:0Environment=XDG_RUNTIME_DIR=/run/user/1000Environment=PULSE_SERVER=unix:/run/user/1000/pulse/nativeSupplementaryGroups=audio videoExecStartPre=/bin/sleep 10ExecStart=/home/sunrise/yahboom_ws/src/largemodel/start_largemodel.shRestart=on-failureStandardOutput=journalStandardError=journal[Install]WantedBy=multi-user.targetEnvironment=DISPLAY=:0will output the GUI pop-up to the desktop. Users connecting via SSH can change this toEnvironment=DISPLAY=:10. You can find the specific parameters by typingecho $DISPLAYin the terminal.- The path in
ExecStartmust be exactly the same as the path to the startup script to be executed.
Save and exit.
2.2.3 Managing and Debugging the Service
Now that your service has been created, we need to get systemd to load it and set it to start automatically on boot.
- Reload the
systemddaemon so it reads the service file we just created:
xxxxxxxxxxsudo systemctl daemon-reload- Set the service to start automatically on boot:
xxxxxxxxxxsudo systemctl enable largemodel.service- Start the service immediately:
xxxxxxxxxxsudo systemctl start largemodel.service- Check the service status:
This is the most important command to verify that the service is running successfully.
xxxxxxxxxxsudo systemctl status largemodel.service* If you see `Active: active (running)`, congratulations, the service has started successfully!* If the status is `failed` or something else, please continue to the next step for debugging.- View Service Logs (Essential for Debugging):
If the service fails to start, you can view all real-time logs generated by the ros2 launch command using the following command. This is crucial for troubleshooting.
xxxxxxxxxxjournalctl -u largemodel.service -fAfter completing all the above steps, the fully offline largemodel voice service will now start automatically every time you boot up.
To disable the automatic startup service, you can run the following command:
xxxxxxxxxxsudo systemctl start largemodel.servicesudo systemctl disable largemodel.service
2.3 ORIN
2.3.1 Create a startup script
To ensure that systemd can correctly load the ROS2 environment, the best practice is to create a simple bash script to encapsulate our startup command.
Creating a script file: In the directory (
~/yahboom_ws/src/largemodel/), create a file namedstart_largemodel.sh.xxxxxxxxxxvim ~/yahboom_ws/src/largemodel/start_largemodel.shWrite script content: Copy and paste the following content into the script file.
xxxxxxxxxx# Source ROS2 Humble environmentsource /opt/ros/humble/setup.bash# Source Yahboom workspace environmentsource /home/jetson/yahboom_ws/install/setup.bash# Start the largemodel control scriptros2 launch largemodel largemodel_control.launch.pyImportant Note: Please ensure that
/home/sunrise/in the script is replaced with your own user home directory path.Save and Exit
Grant Script Execution Permissions:
xxxxxxxxxxchmod +x ~/yahboom_ws/src/largemodel/start_largemodel.sh2.3.2 Creating the Systemd Service File
This is the most crucial step. We will tell the system that we have a new service to manage.
- Create the Service File:
You need to use sudo privileges to create this file.
xxxxxxxxxxsudo vim /etc/systemd/system/largemodel.service- Write the Service Configuration:
Copy and paste the following content completely into the service file.
xxxxxxxxxx [Unit] Description=Robot Service After=network.target sound.target graphical.target multi-user.target Wants=network.target sound.target graphical.target multi-user.target [Service] Type=simple User=sunrise Group=sunrise Environment=DISPLAY=:0 Environment=XDG_RUNTIME_DIR=/run/user/1000 Environment=PULSE_SERVER=unix:/run/user/1000/pulse/native SupplementaryGroups=audio video ExecStartPre=/bin/sleep 10 ExecStart=/home/sunrise/yahboom_ws/src/largemodel/start_largemodel.sh Restart=on-failure StandardOutput=journal StandardError=journal [Install] WantedBy=multi-user.targetExtremely Important!!!
- Ensure that the paths in
WorkingDirectoryandExecStartare exactly the same as your actual paths.
- Save and Exit.
2.3.3 Managing and Debugging the Service
Now that your service has been created, we need to get systemd to load it and set it to start automatically on boot.
- Reload the
systemddaemon so that it reads the service file we just created:
xxxxxxxxxxsudo systemctl daemon-reload- Set the service to start automatically on boot:
xxxxxxxxxxsudo systemctl enable largemodel.service- Start the service immediately:
xxxxxxxxxxsudo systemctl start largemodel.service- Check the service status:
This is the most important command to verify that the service is running successfully.
xxxxxxxxxxsudo systemctl status largemodel.service * If you see `Active: active (running)`, congratulations, the service has started successfully!* If the status is `failed` or something else, please continue to the next step for debugging.- View service logs (essential for debugging):
If the service fails to start, you can view all real-time logs generated by the ros2 launch command using the following command. This is crucial for locating the problem.
xxxxxxxxxxjournalctl -u largemodel.service -fAfter completing all the above steps, the fully online largemodel voice service will now start automatically every time you boot up.