Welcome to Muto RS Robot repository
10. AI large model offline voice assistant
10. AI large model offline voice assistant
10. AI large model offline voice assistant1. Offline Voice Configuration2. Create a Systemd Service2.1 Create a Docker Container Startup Script2.2 If 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 start the automatic startup service:2.3 Related commands:3. CSI Camera Auto-Start Service
Note: The Raspberry Pi 5 1GB without a large model package cannot run. Due to performance limitations, the 2GB and 4GB versions cannot run offline. You can refer to the tutorials for online large models.
1. Offline Voice Configuration
Before setting up auto-start, we must ensure that the program itself can operate independently offline. This can be accomplished by modifying the configuration file.
Locate the Configuration File: In your project code, find and open the configuration file:
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_asrFalse #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 languageregional_setting "China" #international:International version China:Domestic versionmodel_service#Model server node parametersros__parameterslanguage'zh' #Large Model Interface LanguageuseolinettsFalse #Whether to use online speech synthesis (True uses online, False uses offline)# Large model configuration# llm_platform: 'ollama' # Optional platform: 'ollama', 'tongyi', 'spark', 'qianfan', 'openrouter'llm_platform'ollama' # Currently selected large model platformregional_setting "China"use_oline_asranduseolinettsmust be set to False.llm_platformmust be set toollama.This setting will make everything offline.
Save the file and recompile the project to apply the changes:
xxxxxxxxxxcd ~/yahboom_wscolcon buildsource install/setup.bash
After completing this step, the program is now a purely offline 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, then run:
xxxxxxxxxxchmod +x ~/ros2_docker_autostart.sh./ros2_docker_autostart.shVerification:
xxxxxxxxxxdocker inspect -f '{{.HostConfig.RestartPolicy.Name}}' ros_humble_ai_serviceThe output should be "unless-stopped". Docker will automatically start the container each time you boot the computer, enabling the voice assistant to start automatically.
2.2 If 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 start the automatic startup service:
xxxxxxxxxx~/ros2_docker_autostart.sh
2.3 Related commands:
Stop the container immediately, and also stop it from automatically starting:
xxxxxxxxxxdocker stop ros_humble_ai_service
View the running log of the docker container:
xxxxxxxxxxdocker logs -f ros_humble_ai_service
3. CSI Camera Auto-Start 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 auto-start, 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 auto-start service.
Enter the command to write 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 do not need the CSI camera self-start 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