ubuntu16.04+ROS+科大讯飞+图灵AI机器人(三)——语音识别

上一篇中我们已经实现了tts(语音合成)

接下来我们再来实现在线语音识别

在这个过程中我走了不少弯路,网上的博客几乎全部看了一遍,有不少还是很有问题的 特在此总结一个切实可用的方法

希望大家觉得ok的话给我点赞

第一步 将samples里面的iat_online_record_sample里面的三个.c文件拷贝到xf_voice的src中,并注意将主文件iat...后缀改成.cpp

不然会出错;同时,将samples里面include中的.h文件全部拷贝到Robot/voice/inc目录下

第二步 修改iat_online_record_sample.cpp

名称改为fuck_asr.cpp(为什么骂人呢,因为一直出bug心情烦躁,个人经验,名字贱好养活)

里面代码改成下面的代码

#include<ros/ros.h>

#include<std_msgs/String.h>

#include<std_msgs/Int32.h>

#include <stdlib.h>

#include <stdio.h>

#include <string.h>

#include <unistd.h>

#include "/Robot/voice/inc/qisr.h"

#include "/Robot/voice/inc/msp_cmn.h"

#include "/Robot/voice/inc/msp_errors.h"

#include "/Robot/voice/inc/speech_recognizer.h"

 

#define FRAME_LEN   640

#define BUFFER_SIZE 4096

#define ASRFLAG 1

 

using namespace std;

 

bool flag = false;

bool recorder_Flag = true;

string result = "";

 

/* Upload User words */

static int upload_userwords()

{

    char*           userwords   =   NULL;

    size_t          len         =   0;

    size_t          read_len    =   0;

    FILE*           fp          =   NULL;

    int             ret         =   -1;

 

    fp = fopen("userwords.txt", "rb");

    if (NULL == fp)

    {

        printf("\nopen [userwords.txt] failed! \n");

        goto upload_exit;

    }

 

    fseek(fp, 0, SEEK_END);

    len = ftell(fp);

    fseek(fp, 0, SEEK_SET);

 

    userwords = (char*)malloc(len + 1);

    if (NULL == userwords)

    {

        printf("\nout of memory! \n");

        goto upload_exit;

    }

 

    read_len = fread((void*)userwords, 1, len, fp);

    if (read_len != len)

    {

        printf("\nread [userwords.txt] failed!\n");

        goto upload_exit;

    }

    userwords[len] = '\0';

 

    MSPUploadData("userwords", userwords, len, "sub = uup, dtt = userword", &ret);

    if (MSP_SUCCESS != ret)

    {

        printf("\nMSPUploadData failed ! errorCode: %d \n", ret);

        goto upload_exit;

    }

 

upload_exit:

    if (NULL != fp)

    {

        fclose(fp);

        fp = NULL;

    }

    if (NULL != userwords)

    {

        free

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值