Welcome to Jetson Orin NX Developer Kit repository
当製品の日本語版マニュアル資料は、こちらからご取得ください。
4.AI large model voice assistant
10. AI large model voice assistant (online/offline)
10. AI large model voice assistant (online/offline)1. Online/offline voice configuration2. Creating the auto-start service on boot (Systemd)2.1 Creating a startup script2.2 Creating the systemd service file2.3 Managing and debugging the service
1. Online/offline voice configuration
Note: You can choose the online LLM, ASR or TTS in this chapter, or refer to the corresponding chapter of <Online large model (Voice Interaction)>.
Before setting up the auto-start, first confirm that the voice assistant works normally in the mode you have chosen. The ASR, the LLM and the TTS can each choose online or offline; only the stages that are set to online need the network and the API credentials of that service provider.
Locate the configuration file: In your project code, find and open the configuration file:
~/yahboom_ws/src/largemodel/config/yahboom.yamlModify the configuration parameters: Check the following parameters in the file and make sure that their values match what is shown below. If a parameter does not exist, add it.
xasr# ASR node parameters / 语音节点参数ros__parametersVAD_MODE2 # VAD sensitivity / vad灵敏度sample_rate16000 # ASR recording audio sample rate / asr录音音频采样率frame_duration_ms30 # VAD frame size in ms / vad帧大小单位msuse_oline_asrFalse # Whether to use online ASR (True for online, False for offline) / 是否使用在线asr识别(True使用在线,False使用离线)mic_serial_port"/dev/ttyUSB0" # Microphone serial port alias / 麦克风串口别名mic_index0 # Microphone index / 麦克风索引language'en' # ASR language / asr语言regional_setting "international" #international:国际版 China:国内版 # international: International version, China: Domestic versionmodel_service# Model service node parameters / 模型服务器节点参数ros__parameterslanguage'en' # Large model interface language / 大模型接口语言useolinettsFalse # Whether to use online TTS (True for online, False for offline) / 是否使用在线语音合成(True使用在线,False使用离线)llm_platform'ollama' # Currently selected large model platform / 当前选用的大模型平台# Available platforms: 'ollama', 'openrouter' / 可选平台: 'ollama', 'openrouter'regional_setting "international" #international:国际版 China:国内版 # international: International version, China: Domestic versionFully offline:
use_oline_asr: False,useolinetts: False,llm_platform: 'ollama'.Fully online example:
use_oline_asr: True,useolinetts: True,llm_platform: 'tongyi'. The online ASR/TTS still need the credentials of their respective service providers; follow articles 1 and 2 of this chapter.The ASR, the TTS and the LLM can be chosen in a mixed way; for example an online LLM with an offline ASR/TTS.
Save the file and rebuild the project to apply the changes:
xxxxxxxxxxcd ~/yahboom_wscolcon buildsource install/setup.bash
The online Tongyi LLM needs qianwen_api_key and the model name to be filled in; the online ASR needs online_asr_api_key; the online TTS needs the credentials of the corresponding service provider. In the offline mode, confirm that the Ollama model and the paths of the SenseVoiceSmall and the Piper models exist. See articles 1–3 of this chapter for the detailed fields and the examples.
The online mode additionally needs the network to be available at startup; the offline mode requires the local models to be installed.
Note: if you are using the factory image, the scripts and the service related configuration are already complete, so the operations below are not needed
2. Creating the auto-start service on boot (Systemd)
Now we are going to create a systemd service so that largemodel_control.launch.py runs automatically when the system starts. In the online mode it is recommended to start after the network is ready; if the device connects slowly, you can check the connectivity of the interface and the service log after the service has started.
2.1 Creating a startup script
So that systemd can load the ROS2 environment correctly, the best practice is to create a simple bash script that wraps 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 content of the script: Copy and paste the following content into the script file.
xxxxxxxxxx# Source the ROS2 jazzy environmentsource /opt/ros/jazzy/setup.bash# Source the Yahboom workspace environmentsource /home/jetson/yahboom_ws/install/setup.bash# Start the largemodel control scriptros2 launch largemodel largemodel_control.launch.pyRun
whoamifirst to confirm the Linux user name andecho $HOMEto confirm the home directory; replace/home/jetsonin the script with the actual home directory of the device.Save and exit
Give the script the execute permission:
xxxxxxxxxxchmod +x ~/yahboom_ws/src/largemodel/start_largemodel.sh
2.2 Creating the systemd service file
This is the most important step. We are telling the system that we now have a new service to manage.
Create the service file: You need
sudopermission to create this file.xxxxxxxxxxsudo vim /etc/systemd/system/largemodel.serviceWrite the service configuration: Copy and paste the following content in full into the service file.
xxxxxxxxxx[Unit]Description=Robot ServiceAfter=network-online.target sound.target graphical.targetWants=network-online.target sound.target graphical.target[Service]Type=simpleUser=jetsonGroup=jetsonEnvironment=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.targetChange the user name, the UID and the paths in
User,Group,XDG_RUNTIME_DIR,PULSE_SERVERandExecStartto the actual values of the device (you can look them up withwhoami,id -uandecho $HOME).ExecStarthas to point to the script created in the previous step, which needs the execute permission. The online mode usesnetwork-online.target; the system also has to enable the wait-online service of the corresponding network manager in order to wait until the network is really ready.Save and exit.
2.3 Managing and debugging the service
Now your service has been created, and we need to let systemd load it and set it to start on boot.
Reload the
systemddaemon so that it reads the service file we just created:xxxxxxxxxxsudo systemctl daemon-reloadSet the service to start automatically on boot:
xxxxxxxxxxsudo systemctl enable largemodel.serviceStart the service immediately:
xxxxxxxxxxsudo systemctl start largemodel.serviceCheck the status of the service: This is the most important command for verifying whether the service is running successfully.
xxxxxxxxxxsudo systemctl status largemodel.serviceIf you see
Active: active (running), the service process has started; if it isfailed, keep reading the service log and check the configuration, the network and the audio devices.View the service log (essential for debugging): If the service fails to start, you can view all the real-time logs produced by the
ros2 launchcommand with the following command, which is crucial for locating the problem.xxxxxxxxxxjournalctl -u largemodel.service -f
After the steps above, the system starts the largemodel voice service with the selected online or offline configuration.