上一篇中我们已经实现了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