Welcome to Muto RS Robot repository
8. AI large model online voice assistant
8. AI large model online voice assistant
8. AI large model online voice assistant1. Online Voice Configuration2. Create a Systemd Service2.1 Create a Docker Container Startup Script2.2 If you are using the YABO AI Large Model factory image, you do not need to recreate the script. Simply run the following command to restart the autostart service:2.3 Related Commands:3. CSI Camera Autostart Service
Note: The Raspberry Pi 5 1GB version does not have this package and cannot run this case.
1. Online Voice Configuration
Before setting up automatic startup, we must ensure that the program itself can operate independently while online. This can be accomplished by modifying the configuration file.
First, enter the Docker container by typing the following command in the terminal:
./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.
xasr#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 Create a Docker Container Startup Script
Create a Script File: In your home directory (~), create a file named
ros2_docker_autostart.sh.xxxxxxxxxxvim ~/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 that Docker starts at boot:
xxxxxxxxxxsudo systemctl enable --now dockerGive the script execution permissions and run:
xxxxxxxxxxchmod +x ~/ros2_docker_autostart.sh./ros2_docker_autostart.shVerify:
xxxxxxxxxxdocker inspect -f '{{.HostConfig.RestartPolicy.Name}}' ros_humble_ai_serviceThe output should show "unless-stopped". From now on, Docker will automatically start the container at each boot, enabling the voice assistant to automatically start.
2.2 If you are using the YABO AI Large Model factory image, you do not need to recreate the script. Simply run the following command to restart the autostart service:
xxxxxxxxxx~/ros2_docker_autostart.sh
2.3 Related Commands:
Stop the container immediately, which will also stop the autostart service:
xxxxxxxxxxdocker stop ros_humble_ai_service
View the Docker container's running logs:
xxxxxxxxxxdocker logs -f ros_humble_ai_service
3. CSI Camera Autostart Service
To access the CSI camera feed in Docker, you need to start host_stream.py on the host machine. Therefore, if you need to access the CSI camera feed during autostart, you must also add this file to the Systemd startup service.
Note: If you are using the YABO AI Large Model factory image, these scripts are already created; you only need to restart the autostart service.
Enter the command to write to the file.
xxxxxxxxxxsudo vim /etc/systemd/system/host-stream.serviceCopy 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.targetSave and exit.
Apply and start the service:
xxxxxxxxxxsudo systemctl daemon-reloadsudo systemctl enable host-stream.servicesudo systemctl start host-stream.serviceCheck the service status:
xxxxxxxxxxsudo systemctl status host-stream.serviceIf you see `Active: active (running)`, the service has started successfully!If you no longer need the CSI camera's automatic startup service, run the following command to stop it:
xxxxxxxxxxsudo systemctl stop host-stream.servicesudo systemctl disable host-stream.serviceIf you are using the factory image of Yabo's AI large model, you do not need to recreate the script. Just run the following command to restart the auto-start service:
xxxxxxxxxxsudo systemctl enable host-stream.servicesudo systemctl start host-stream.service