Learn how to code logic for speech-recognized control of Mars Rover with this example block code. You will be able to direct your own Mars Rover easily by just speaking commands.
Introduction
A speech-recognized controlled Mars Rover robot is a robot that can recognize and interpret our speech, and verbal commands, given by a human. The code uses the speech recognition model that will be able to record and analyze your speech given and react accordingly on the Mars Rover.
Speech recognition robots can be used in manufacturing and other industrial settings to control machinery, perform quality control checks, and monitor equipment.
They are also used to help patients with disabilities to communicate with their caregivers, or to provide medication reminders and other health-related information.
Code
sprite=Sprite('Tobi')
import time
rover = MarsRover(4, 1, 7, 2, 6)
quarky = Quarky()
sr = SpeechRecognition()
ts = TexttoSpeech()
sr.analysespeech(4, "en-US")
command = sr.speechresult()
command = command.lower()
if 'forward' in command:
rover.home()
rover.setinangle(0)
quarky.runtimedrobot("F",100,3)
elif 'back' in command:
rover.home()
rover.setinangle(0)
quarky.runtimedrobot("B",100,3)
elif 'right' in command:
rover.home()
rover.setinangle(40)
quarky.runtimedrobot("R",100,3)
elif 'left' in command:
rover.home()
rover.setinangle(40)
quarky.runtimedrobot("L",100,3)
time.sleep(10)
sprite.stopallsounds()
Logic
- Firstly, the code initializes the Mars Rover pins and starts recording the microphone of the device to store the audio command of the user.
- The code then checks conditions whether the command included the word “Go” or not. You can use customized commands and test for different conditions on your own.
- If the first condition stands false, the code again checks for different keywords that are included in the command.
- When any condition stands true, the robot will align itself accordingly and move in the direction of the respective command.
Output
Forward-Backward Motions:
Right-Left Motions: