Welcome to Jetson AGX Orin 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.2Creating the Systemd Service File2.3 Managing and Debugging Services
1. Offline Voice Configuration
Before setting up automatic startup, we must ensure that the program itself can operate independently in an offline state. This requires 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_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 Edition China:China internal versionmodel_service#Model server node parametersros__parameterslanguage'en' #Large Model Interface LanguageuseolinettsFalse #Whether to use online speech synthesis (True to use online, False to use offline)# Large model configuration# llm_platform: 'ollama' # Optional platforms: 'ollama', 'tongyi', 'spark', 'qianfan', 'openrouter'llm_platform'ollama' # Currently selected large model platformregional_setting "international"use_oline_asranduseolinettsmust be set to False.llm_platformmust be set toollama.
This setting will make everything 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 already 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 at system startup.
2.1 Create a Startup Script
To ensure systemd can properly load the ROS2 environment, it's best to create a simple bash script to encapsulate our startup commands.
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 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/sunrise/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 the Systemd Service File
This is the most crucial step. We'll 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/sunrise/yahboom_ws/src/largemodel/start_largemodel.shRestart=on-failureStandardOutput=journalStandardError=journal[Install]WantedBy=multi-user.target- The path in
ExecStartis exactly the same as the path to the startup script to be executed.
- The path in
Save and exit.
2.3 Managing and Debugging Services
Now that your service has been created, we need to have systemd load it and configure it to start automatically at 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
failedor something else, proceed to the next step for debugging.
- If you see
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.xxxxxxxxxxjournalctl -u largemodel.service -f
After completing all the above steps, the purely offline largemodel voice service will be automatically started every time you turn on your phone.