Welcome to RDK S100(P) Board 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 Boot Auto-start Service (Systemd)2.1 Create a Startup Script2.2 Create Systemd Service File2.3 Manage and Debug Service
1. Online Voice Configuration
Before setting up auto-start, we must ensure that the program itself can work independently in online mode. This needs to be done by modifying configuration files.
Locate 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 their values match those shown below. If parameters do not exist, please add them.
xasr# Voice node parametersros__parametersVAD_MODE2 # VAD sensitivitysample_rate16000 # ASR recording audio sample rateframe_duration_ms30 # VAD frame size in msuse_oline_asrTrue # Whether to use online ASR recognition (True for online, False for 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 for online, False for offline)# Large model configuration# llm_platform: 'openrouter' # Available platforms: 'ollama', 'openrouter'llm_platform'openrouter' # Taking openrouter as example hereuse_oline_asranduseolinettsmust be set to True.llm_platformmust be set toopenrouter.With these settings, everything will be online.
Save the file and recompile the project to apply changes:
xxxxxxxxxxcd ~/yahboom_wscolcon buildsource install/setup.bash
After completing this step, the program is now a purely online voice service.
2. Create Boot Auto-start Service (Systemd)
Now, we will create a systemd service to make largemodel_control.launch.py run automatically when the system starts.
2.1 Create a Startup Script
To enable systemd to properly load the ROS2 environment, the best practice is to create a simple bash script to wrap our startup command.
Create 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/sunrise/yahboom_ws/install/setup.bash# Start largemodel control scriptros2 launch largemodel largemodel_control.launch.pyImportant Note: Please ensure you replace
/home/sunrise/in the script with your own user home directory path.Save and Exit
Grant Script Execution Permission:
xxxxxxxxxxchmod +x ~/yahboom_ws/src/largemodel/start_largemodel.sh
2.2 Create 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 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 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.target!!! Extremely Important !!!
- Please ensure that the paths in
WorkingDirectoryandExecStartexactly match your actual paths.
- Please ensure that the paths in
Save and Exit.
2.3 Manage and Debug Service
Now, your service has been created, and we need to let systemd load it and set it to start automatically on boot.
Reload
systemddaemon to let it read our newly created service file:xxxxxxxxxxsudo systemctl daemon-reloadSet service to start automatically on boot:
xxxxxxxxxxsudo systemctl enable largemodel.serviceStart service immediately:
xxxxxxxxxxsudo systemctl start largemodel.serviceCheck service status: This is the most important command to verify whether 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 other, 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 launchcommand through the following command, which is crucial for locating problems.xxxxxxxxxxjournalctl -u largemodel.service -f
After completing all the above steps, now every time you boot up, the purely online largemodel voice service will start automatically.