Welcome to RDK S600 Developer Kit repository
8.AI large model online voice assistant
AI Large Model Online Voice Assistant
AI Large Model Online Voice Assistant1. Online Voice Configuration2. Creating a Boot Auto-start Service (Systemd)2.1 Creating a Startup Script2.2 Creating the Systemd Service File2.3 Managing and Debugging the Service
1. Online Voice Configuration
Before setting up auto-start, we must ensure that the program itself can work independently in an online state. This needs to be done by modifying configuration files.
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 their values match those shown below. If the 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: 'ollama' # Optional platforms: 'ollama', 'tongyi', 'spark', 'qianfan', 'openrouter'llm_platform'tongyi' # Here we use Tongyi as an exampleuse_oline_asranduseolinettsmust be set to tongyi.llm_platformmust be set totongyi.With this configuration, everything will be online.
Save the file and rebuild the project to apply changes:
xxxxxxxxxxcd ~/yahboom_wscolcon buildsource install/setup.bash
After completing this step, the program is already a purely online voice service.
2. Creating a Boot Auto-start Service (Systemd)
Now, we will create a systemd service to make largemodel_control.launch.py run automatically at system startup.
2.1 Creating a Startup Script
To enable 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 ROS2 Humble environmentsource /opt/ros/jazzy/setup.bash# Source Yahboom workspace environmentsource /home/sunrise/yahboom_ws/install/setup.bash# Start largemodel control scriptros2 launch largemodel largemodel_control.launch.pyImportant: Please ensure to replace
/home/sunrise/in the script with your own user home directory path.Save and exit
Grant execute permission to the script:
xxxxxxxxxxchmod +x ~/yahboom_ws/src/largemodel/start_largemodel.sh
2.2 Creating the Systemd Service File
This is the most critical step. We will tell the system that we have a new service to manage.
Create the service file: You need to use
sudoprivileges 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.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 Managing and Debugging the Service
Now that your service is created, we need to let systemd load it and set it to auto-start on boot.
Reload the
systemddaemon to read our newly created service file:xxxxxxxxxxsudo systemctl daemon-reloadSet the service to auto-start on boot:
xxxxxxxxxxsudo systemctl enable largemodel.serviceStart the 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
failedor other, please continue to the next step for debugging.
- If you see
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, every time the system boots, it will automatically start the purely online largemodel voice service.
To disable the online voice assistant service, run the following commands
xxxxxxxxxxsudo systemctl disable largemodel.service
sudo systemctl stop largemodel.service