Welcome to Jetson AGX Orin repository
当製品の日本語版マニュアル資料は、こちらからご取得ください。
8.AI large model offline voice assistant
8.AI large model offline voice assistant
8.AI large model offline voice assistant1. Online Voice Configuration2. Create a Startup Service (Systemd)2.1 Create a Startup Script2.2 Creating the Systemd Service File2.3 Managing and Debugging Services
1. Online Voice Configuration
Before setting up automatic startup, we must ensure that the program itself can operate independently in an online state. This can be accomplished by modifying the configuration file.
- Locate the Configuration File: In your project code, find and open the configuration file:
config/yahboom.yaml
Modify 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.
xxxxxxxxxxasr#Voice node parametersros__parametersVAD_MODE2 #vad sensitivitysample_rate16000 #asr recording audio sampling rateframe_duration_ms30 #vad frame size in msuse_oline_asrTrue #Whether to use online ASR recognition (True uses online, False uses 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 uses online, False uses offline)# Large model configuration# llm_platform: 'ollama' # Optional platforms:'ollama', 'tongyi', 'spark', 'qianfan', 'openrouter'llm_platform'tongyi' # Here we take Tongyi as an exampleuse_oline_asranduseolinettsmust be set totongyi.llm_platformmust be set totongyi.
With this setup, everything is 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 now a fully online 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 correctly load the ROS2 environment, it's best to create a simple bash script to encapsulate our startup commands.
Create a 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: 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# 启动 largemodel Control Scriptros2 launch largemodel largemodel_control.launch.pyImportant: Please make sure to replace
/home/sunrise/in the script with your own home directory path.Save and exit
Give the script execute permissions:
xxxxxxxxxxchmod +x ~/yahboom_ws/src/largemodel/start_largemodel.sh
2.2 Creating the Systemd Service File
This is the most crucial step. We'll tell the system that we have a new service to manage.
- Creating the Service File: You will need sudo privileges to create this file.
xxxxxxxxxxsudo vim /etc/systemd/system/largemodel.serviceWrite the Service Configuration: Copy and paste the following content exactly 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!
- Make sure the paths in
WorkingDirectoryandExecStartmatch your actual paths exactly.
- Make sure the paths in
Save and exit.
2.3 Managing and Debugging Services
Now that your service is created, we need to have systemd load it and set it to start automatically at boot.
- Reload the
systemddaemon so it reads our newly created service file:
xxxxxxxxxxsudo systemctl daemon-reload- Set the service to start automatically at boot:
xxxxxxxxxxsudo systemctl enable largemodel.service- Start the service immediately:
xxxxxxxxxxsudo systemctl start largemodel.service- Check the 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 something else, proceed to the next step for debugging.View the service log (essential for debugging):
If the service fails to start, you can view all real-time logs generated by the
ros2 launchcommand using the following command. This is crucial for troubleshooting.
xxxxxxxxxxjournalctl -u largemodel.service -fAfter completing all the above steps, the fully online largemodel voice service will automatically start every time you boot your computer.