Welcome to Rider Pi Robot repository
3.Q&A and ChatGPT(For cm4)
Q&A and ChatGPT
Q&A and ChatGPTFeature IntroductionFeature ExperienceProgram Source CodeHow to Run This Case from TerminalHow to Change Recording DurationFeature Principle
Feature Introduction
- This case is a startup program usage that requires configuring the large model's related API-KEY to work properly.
- This feature enables conversational interaction with users.
- This feature requires an internet connection to work properly
Feature Experience
- First start up RiderPI, press the button in the upper right corner of the "screen" to enter demo mode, then select the iFlytek Spark feature.

- After entering the iFlytek Spark feature, first use voice to wake up with "lulu".

- When you hear a "ding" sound, you can speak your question.


- RiderPI will respond based on your question.

Program Source Code
- First, log in to the RiderPI system via VNC
- Then enter the following in the terminal:
x# For CM4cd /home/pi/RaspberryPi-CM4-main/demos/Free_QA/
# For CM5cd /home/pi/RaspberryPi-CM5/demos/Free_QA/
tree- Directory Structure Description ├── answer.mp3 # Synthesized audio ├── audio.py # Recording file ├── auto_platform.py # Dependencies needed for recording ├── chatgpt_main.py # Main program ├── language_recognize.py # Speech recognition ├── libnyumaya.py # Voice wake-up ├── xinghou_tts.py # Audio synthesis └── xinghou_UltraAPI.py # Large language model interface
- If you want to replace with your own model interface
- First get the Python version program for the corresponding platform's interface, fill in necessary information according to the platform's interface and instructions.
- Then wrap the runnable file into a function, refer to the "xinghou_UltraAPI.py" method and place it in the directory from step 2, for example, adding a file named "mychatgpt.py"
- Open the chatgpt_main.py file, replace
from xinghou_UltraAPI import *at the top withfrom mychatgpt import * - Then find this location and replace it with your own wrapped API function interface.

- Then restart the device and enter this feature again to run your replaced model platform. If it doesn't work, there's an error and you need to check the syntax and logic of the newly added file yourself.
How to Run This Case from Terminal
- First end the main program to prevent screen flickering. For instructions on how to end it, please refer to the tutorial in Chapter 1 about ending the main program. This won't be described here.
- Enter the following command in the terminal:
xxxxxxxxxx# For CM4cd /home/pi/RaspberryPi-CM4-mainpython3 demos/Free_QA/chatgpt_main.py
# For CM5cd /home/pi/RaspberryPi-CM5python3 demos/Free_QA/chatgpt_main.pyHow to Change Recording Duration
- Enter in terminal:
xxxxxxxxxx# For CM4nano ~/RaspberryPi-CM4-main/demos/Free_QA/audio.py# For CM5nano ~/RaspberryPi-CM5/demos/Free_QA/audio.py- Find this location and change the area indicated in the image below to adjust recording duration according to your environment.

Note: start_threshold > end_threshold, these two values need to be adjusted according to your own environment.
Feature Principle
The specific flowchart is as follows:
