Welcome to ROSMASTER M1 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 startup service (Systemd)2.1 Create a startup script2.2Creating a Systemd Service File2.3Management and debugging services
Note: Since Jetson Nano is in Docker, the following method is only a guide and cannot be implemented directly
1. Online Voice Configuration
Before setting up auto-start, we must ensure that the program itself can work independently in an online state. This can be done 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 audio sampling rateframe_duration_ms30 # VAD frame size in millisecondsuse_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'en' # ASR languagemodel_service# Model server node parametersros__parameterslanguage'en' # Large model interface languageuseolinettsTrue # Whether to use online speech synthesis (True for online, False for offline)# Large model configuration#llm_platform: 'ollama' # Available platforms: 'ollama', 'tongyi', 'spark', 'qianfan', 'openrouter'llm_platform'tongyi' # This example uses Tongyi as an exampleuse_oline_asranduseolinettsmust be set totongyi.llm_platformmust be set totongyi.If you set it up like this, everything will be online.
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 already a purely online voice service.
2. Creating a startup service (Systemd)
Now, we will create a systemd service so that largemodel_control.launch.py will automatically run at system startup.
2.1 Create a startup script
In order for systemd to correctly load the ROS2 environment, the best practice is to create a simple bash script to encapsulate 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/jetson/yahboom_ws/install/setup.bash# Start the largemodel control scriptros2 launch largemodel largemodel_control.launch.pyImportant: Please make sure to replace
/home/jetson/in the script with your own user home directory path.Save and Exit
Give the script execution permissions:
xxxxxxxxxxchmod +x ~/yahboom_ws/src/largemodel/start_largemodel.sh
2.2Creating a Systemd Service File
This is the most important step. We will tell the system that we have a new service to manage.
Create service file: You will need
sudoprivileges to create this file.xxxxxxxxxxsudo vim /etc/systemd/system/largemodel.serviceWrite service configuration: Copy and paste the following content 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/jetson/yahboom_ws/src/largemodel/start_largemodel.shRestart=on-failureStandardOutput=journalStandardError=journal[Install]WantedBy=multi-user.target!!! Extremely important!!!
- Please make sure that the paths in
WorkingDirectoryandExecStartare exactly the same as your actual paths.
- Please make sure that the paths in
Save and exit.
2.3Management and debugging services
Now that your service is created, we need to have systemd load it and set it to start automatically on boot.
Reload the
systemddaemon so that it reads our newly created service file:xxxxxxxxxxsudo systemctl daemon-reloadSet the service to start automatically at boot:
xxxxxxxxxxsudo systemctl enable largemodel.serviceStart the service immediately:
xxxxxxxxxxsudo systemctl start largemodel.serviceCheck 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 another error, proceed to the next step for debugging.View service log (required for debugging): If the service fails to start, you can use the following command to view all real-time logs generated by the
ros2 launchcommand, which is crucial for locating the problem.