探索使用科大讯飞语音包控制机器狗(三)--控制小狗移动(语音控制脚本)

本文介绍了如何使用科大讯飞的语音识别技术,通过预录音频文件控制机器狗的移动。目前实现的指令包括站立、行走和休息。文章提到了识别准确性和实时语音输入的挑战,以及未来可能通过关键词识别SDK提升性能,并探讨了机器狗运动控制的深化研究方向。
摘要由CSDN通过智能技术生成

之前已经初步探索了语音识别的可能性以及单独控制机器狗运动的脚本编写,现在探索使用语音识别初步控制小狗运动,由于树莓派收声部分还有些问题,所以初步探索使用录入的音频文件进行识别。

编写发布器

编写发布器发布语音识别的结果。

源码

只展示主函数的部分,需要注意的地方是,对于音频文件的存放路径

int main(int argc, char* argv[])
{
   
    ros::init(argc, argv, "voiceRecognition");
    ros::NodeHandle n;
    ros::Rate loop_rate(10);

    ros::Publisher voiceWordsPub = n.advertise<std_msgs::String>("voiceWords", 1000);  

	int ret = MSP_SUCCESS;
	int upload_on =	1; /* whether upload the user word */
	/* login params, please do keep the appid correct */
	const char* login_params = "appid = 5fa8bc98, work_dir = .";
	int aud_src = 0; /* from mic or file */
    int count =0;
    while(ros::ok())
    {
   
	/*
	* See "iFlytek MSC Reference Manual"
	*/
	    const char* session_begin_params =
		    "sub = iat, domain = iat, language = zh_cn, "
		    "accent = mandarin, sample_rate = 16000, "
	    	"result_type = plain, result_encoding = utf8";

	/* Login first. the 1st arg is username, the 2nd arg is password
	 * just set them as NULL. the 3rd arg is login paramertes 
	 * */
	    ret = MSPLogin(NULL, NULL, login_params);
	    if (MSP_SUCCESS != ret)	{
   
		    printf("MSPLogin failed , Error code %d.\n",ret);
		    goto exit; // login fail, exit the program
	    }
		//是否上传用户词库
	    printf("Want to upload the user words ? \n0: No.\n1: Yes\n");
	    scanf("%d", &upload_on);
	    if (upload_on)
	    {
   
		    printf("Uploading the user words ...\n");
		    ret = upload_userwords();
		    if (MSP_SUCCESS != ret)
			    goto exit;	
		    printf("Uploaded successfully\n");
	    }
		//语音输入的音频来自于什么地方,可以选择音频文件或者麦克风实时输入
	    printf("Where the audio comes from?\n"
			    "0: From a audio file.\n1: From microphone.\n");
	    scanf("%d", &aud_src);
	    if(aud_src != 0) {
   
		    printf("Demo recognizing the speech from microphone\n");
		    printf("Speak in 15 seconds\n");

		    demo_mic(session_begin_params);

		    printf("15 sec passed\n");
	    } else {
   
		    printf("Demo recgonizing the speech from a recorded audio file\n");
		    demo_file("/home/liuda/spotmicro/src/spotMicro/robot_voice/bin/wav/iflytek02.wav", session_begin_params); 
		    //注意音频文件的存放位置,移植代码的时候注意修改
	    }
        MSPLogout();
        //发布消息,当识别到语音时发布识别结果
        std_msgs::String msg;
            if(resultFlag){
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值