Welcome to RDK X5 Board 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 Startup Service (Systemd)2.1 Create a startup script2.2 Create the Systemd Service File2.3 Manage and Debug the Service
Note: The RDK X5 4GB version cannot run this offline due to performance limitations. Please refer to the tutorial for online large models.
1. Offline Voice Configuration
Before setting up auto-start, we must ensure that the program itself can work independently in an offline state. This needs to be done by modifying the configuration file.
Open the configuration file:
xxxxxxxxxxvim ~/yahboom_ws/src/largemodel/config/yahboom.yamlModify the configuration parameters: Please check the following parameters in the file and ensure that their values are consistent with those shown below. If the parameters do not exist, please add them.
xxxxxxxxxxasr# Speech node parametersros__parametersVAD_MODE2 # VAD sensitivitysample_rate16000 # ASR recording audio sample rateframe_duration_ms30 # VAD frame size unit msuse_oline_asrFalse # Whether to use online ASR recognition (True for online, False for offline)mic_serial_port"/dev/ttyUSB0" # Microphone serial port aliasmic_index0 # Microphone indexlanguage'en' # ASR languageregional_setting "international" # international: International version China: Domestic versionmodel_service# Model server node parametersros__parameterslanguage'en' # Large model interface languageuseolinettsFalse # Whether to use online speech synthesis (True for online, False for offline)llm_platform'ollama' # Currently selected large model platformregional_setting "international"use_oline_asranduseolinettsmust be set toFalse.llm_platformmust be set toollama.With this setting, everything will be 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 a purely offline voice service.
2. Create a Startup Service (Systemd)
Now, we will create a systemd service to automatically run largemodel_control.launch.py when the system starts.
Users of Yahboom's AI large model image do not need to create it manually; just skip to the back and run the command to start on boot.
2.1 Create a startup script
To allow systemd to 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 namedstart_largemodel.sh.xxxxxxxxxxvim ~/yahboom_ws/src/largemodel/start_largemodel.shWrite the script content: Copy and paste the following content into the script file.
xxxxxxxxxx# Source the ROS2 Humble environmentsource /opt/ros/humble/setup.bash# Source the Yahboom workspace environmentsource /home/sunrise/yahboom_ws/install/setup.bash# Start the largemodel control scriptros2 launch largemodel largemodel_control.launch.pyImportant note: Please make sure to replace
/home/sunrise/in the script with your own user's home directory path.Save and exit
Give the script execution permission:
xxxxxxxxxxchmod +x ~/yahboom_ws/src/largemodel/start_largemodel.sh
2.2 Create the Systemd Service File
Create the service file: You need to use
sudopermission to create this file.xxxxxxxxxxsudo vim /etc/systemd/system/largemodel.serviceWrite the service configuration: Copy and paste the following content completely 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 window to the desktop. If you are using an SSH connection, you can change it toEnvironment=DISPLAY=:10. You can query the specific parameters by enteringecho $DISPLAYin the terminal.The path in
ExecStartis exactly the same as the path of the startup script to be executed.
Save and exit.
2.3 Manage and Debug the Service
Now that your service has been created, we need to let systemd load it and set it to start on boot.
Reload the
systemddaemon to let it read our newly created service file:xxxxxxxxxxsudo systemctl daemon-reloadSet the service to start on boot:
xxxxxxxxxxsudo systemctl enable largemodel.serviceStart the service immediately:
xxxxxxxxxxsudo systemctl start largemodel.serviceCheck 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 proceed to the next step for debugging.View the service log (essential for debugging): If the service fails to start, you can view all the real-time logs generated by the
ros2 launchcommand through the following command, which is crucial for locating the problem.xxxxxxxxxxjournalctl -u largemodel.service -f
After completing all the above steps, the purely offline largemodel voice service will now be automatically started every time the machine is turned on.
When you need to turn off the auto-start service, you can run the following commands:
sudo systemctl stop largemodel.servicesudo systemctl disable largemodel.service