Welcome to RDK S100(P) 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 Creating a Startup Script2.2 Creating a Systemd Service File2.3 Managing and Debugging the Service
1. Offline Voice Configuration
Before setting up auto-start, we must ensure the program can work independently offline. This requires modifying the configuration file.
- Locate the Configuration File:
In your project code, find and open the configuration file:
config/yahboom.yaml
- Modify Configuration Parameters:
Please check the following parameters in the file and ensure their values match those shown below. If the parameters are missing, please add them.
xasr#Voice Node Parameters ros__parameters VAD_MODE2 #vad sensitivity sample_rate16000 #asr audio sampling rate frame_duration_ms30 #VAD frame size unit: ms use_oline_asrFalse #Whether to use online ASR recognition (True uses online, False uses offline) mic_serial_port"/dev/ttyUSB0" #Microphone serial port alias mic_index0 #Microphone Index language'en' #asr languagemodel_service#Model server node parameters ros__parameters language'en' #Large Model Interface Language useolinettsFalse #Whether to use online speech synthesis (True for online, False for offline) # Large Model Configuration # llm_platform: 'ollama' # Optional platforms: 'ollama', 'tongyi', 'spark''qianfan', 'openrouter' llm_platform'ollama' # Current large model platformAfter completing this step, the program is now a purely offline voice service.
2. Create a startup service (Systemd)
Now, we will create a systemd service so that largemodel_control.launch.py runs automatically at system startup.
2.1 Creating a Startup Script
To ensure systemd correctly loads 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.
xxxxxxxxxxvim ~/yahboom_ws/src/largemodel/start_largemodel.sh- Write 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 ensue that /home/sunrise/ in the script is replaced with your own user's home directory path.
- Save and Exit
- Grant Script Execution Permissions:
xxxxxxxxxxchmod +x ~/yahboom_ws/src/largemodel/start_largemodel.sh2.2 Creating a Systemd Service File
This is the most crucial step. We will tell the system that we have a new service that needs to be managed.
- Create the service file:
You need sudo privileges to create this file.
xxxxxxxxxxsudo vim /etc/systemd/system/largemodel.service- Write the service configuration:
Copy and paste the following content 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.target ExecStartThe path in the command must be exactly the same as the path to the startup script to be executed.
- Save and exit.
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 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
failedor 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 purely offline largemodel voice service will now start automatically every time you boot up.