Welcome to DOFBOT SE repository
8.Voice Recognition Target Tracking
Voice Recognition Target Tracking
1. Function Description
Voice control the robotic arm to track color blocks, faces, and machine codes.
2. Startup and Operation
2.1 Operation
Open the terminal and enter the following command to start:
xxxxxxxxxxpython3 ~/dofbot_voice/scripts/voice_target_follow.py
2.2 Operation Steps
Note: This case tracks and grabs machine codes: it will only track and will not grab.
After the program runs, the voice module will broadcast "I'm here", then say "Hi, yahboom" to the voice module. The voice module replies "I'm here" indicating successful wake-up. Then say "Face following"/"Yellow following"/"Red following"/"Green following"/"Blue following", the voice module will broadcast "ok". Then the robotic arm starts tracking the target. To stop tracking, say "Stop following" to the voice module, the robotic arm will stop tracking the target, and the voice module will broadcast "ok". Note: If the color cannot be recognized or the target cannot be tracked correctly, you may need to modify the HSV values in the program or adjust the ambient light.

3. Core Code Analysis
Source code path: ~/dofbot_voice/scripts/voice_target_follow.py
x# Import color tracking and face tracking librariesfrom color_follow import color_followfrom face_follow import Face_Follow# Create color tracking object and face tracking objectfollow = color_follow()follow2 = Face_Follow()model = 'General'# Get voice recognition resultresult = mySpeech.speech_read()# According to voice recognition result, modify model and make voice broadcast module broadcast corresponding audio fileif result == 73: choose_color = 'red' model = 'color_follow' mySpeech.void_write(71) time.sleep(0.1) elif result == 72: choose_color = 'yellow' model = 'color_follow' mySpeech.void_write(71) time.sleep(0.1)elif result == 74: choose_color = 'green' model = 'color_follow' mySpeech.void_write(71) time.sleep(0.1) elif result == 75: choose_color = 'blue' model = 'color_follow' mySpeech.void_write(71) time.sleep(0.1) elif result == 71: model = 'follow2' mySpeech.void_write(71) time.sleep(0.1) elif result == 76: model = 'General' mySpeech.void_write(76) time.sleep(0.1)# According to the value of model, choose to execute color tracking or face tracking, call corresponding function and pass required values if model == 'color_follow': img = follow.follow_function(img, color_hsv[choose_color]) # Add text cv.putText(img, choose_color, (int(img.shape[0] / 2), 50), cv.FONT_HERSHEY_SIMPLEX, 2, color[random.randint(0, 254)], 2) if model == 'follow2': img, pos = follow2.follow_function(img)