Welcome to AI Voice Interaction Module repository
2. Voice control car movement
2. Voice control of car movement
Take our company's product Rosmaster-X3 as an example to explain how to call the Speech_Lib library in the program for voice recognition and then control the movement of the car/robot. This course needs to be combined with the Rosmaster-X3 car hardware, and only code analysis is done here. First, let's look at the built-in voice commands,


1. Start the program
Terminal input,
xxxxxxxxxxros2 run yahboomcar_voice_ctrl Voice_Ctrl_Mcnamu_driver_X3

2. Core code
Code path:~/driver_ws/src/yahboomcar_voice_ctrl/yahboomcar_voice_ctrl/Voice_Ctrl_Mcnamu_driver_X3.py
xxxxxxxxxx#导入相对应的语音库 Import the corresponding speech libraryfrom Speech_Lib import Speech#导入相对应的底层驱动库 Import the corresponding underlying driver libraryfrom Rosmaster_Lib import Rosmaster#创建语音控制对象 Create a speech control objectspe = Speech()#创建底层控制的对象 Create an underlying control objectself.car = Rosmaster()#读取语音板识别的结果,speech_r就是识别的结果,是底层库解析后会返回一个数字,通过这个数字来识别指令#Read the result of the speech board recognition, speech_r is the result of the recognition, and the underlying library will return a number after parsing, and use this number to identify the commandspeech_r = spe.speech_read()if speech_r == 2 or speech_r == 0 :....#写入指令,播报语音结果,这里的发送指令后,底层库会包装打包后发送给语音板,语音板接收到后,发出相对的音频文件#Write the command and broadcast the voice result. After sending the command here, the underlying library will package and send it to the speech board. After receiving it, the speech board will send the corresponding audio filespe.void_write(speech_r)#控制小车运动和灯带,直接对接底层库,没有通过ros发布 Control the movement of the car and the light strip, directly connect to the underlying library, and do not publish through rosself.car.set_car_motion(vx, vy, angular) #小车运动 Car movementself.car.set_colorful_effect(6, 6, parm=1) #灯带效果 Light strip effect