概述
#include "stdafx.h"
#include <string>
#include <cstdio>
#include "windows.h"
#include "qisr.h"
#include <conio.h>
#pragma comment(lib,"msc.lib")
void run_iat();
const int BUFFER_NUM = 1024 * 4;
const int AMR_HEAD_SIZE = 6;
int _tmain(int argc, _TCHAR* argv[])
{
run_iat();
printf("Press any key to exit.");
char key = _getche();
printf("结果就是 %d /n",key);
return 0;
}
void run_iat()
{
bool error = false;
int ret = MSP_SUCCESS;
int i = 0;
char* guowei ="VC做控件好难啊....啊啊啊啊啊";
FILE* fp = NULL;
FILE* fout = NULL;
char buff[BUFFER_NUM];
int len;
int status = MSP_AUDIO_SAMPLE_CONTINUE, ep_status = -1, rec_status = -1, rslt_status = -1;
///APPID请勿随意改动
ret = QISRInit("appid=123456"); //这里是授权ID,最好作为参数传入
const char* param = "sub=iat,ssm=1,auf=audio/L16;rate=16000,aue=speex,ent=sms16k,rst=plain";
const char* sess_id = QISRSessionBegin(NULL, param, &ret);
if ( MSP_SUCCESS != ret )
{
printf("QISRSessionBegin err %dn", ret);
error = true;
}
if (error == false)
{
fp = fopen( "a.wav", "rb");//这里是需要打开的音频文件,也作为参数传入
if ( NULL == fp )
{
printf("failed to open file,please check the file.n");
error = true;
}
}
if (error == false)
{
fout = fopen("iat_result.txt", "ab");
if( NULL == fout )
{
printf("failed to open file,please check the file.n");
error = true;
}
}
if (error == false)
{
printf("writing audio...n");
char param_value[32] = "";//参数值的字符串形式
size_t value_len = 32; //字符串长度或buffer长度
int volume = 0;//音量数值
while ( !feof(fp) )
{
len = fread(buff, 1, BUFFER_NUM, fp);
// printf(".");
ret = QISRAudioWrite(sess_id, buff, len, status, &ep_status, &rec_status);
if ( ret != MSP_SUCCESS )
{
printf("nQISRAudioWrite err %dn", ret);
error = true;
break;
}
value_len = 32;
ret = QISRGetParam(sess_id,"volume",param_value,&value_len);
if ( ret != MSP_SUCCESS )
{
printf("QISRGetParam: qisr get param failed Error code %d.n",ret);
char key = _getch();
break;
}
volume = atoi(param_value);
//printf("volume== %d n",volume);
for (int i=0;i<volume;i++)
{
//printf(".");
}
// printf("n");
if (ep_status == MSP_EP_AFTER_SPEECH)
{
printf("QISRAudioWrite: ep_status == MSP_EP_AFTER_SPEECH.n");
break;
}
if ( rec_status == MSP_REC_STATUS_SUCCESS )
{
const char* result = QISRGetResult(sess_id, &rslt_status, 0, &ret) ;
if( rslt_status == MSP_REC_STATUS_NO_MATCH )
printf("get result nomatchn");
else
{
if ( result != NULL )
fwrite( result, 1, strlen(result), fout);
// guowei = result ;
printf("get guowei[%d/%d]: %sn", ret, rslt_status, guowei);
printf("get result[%d/%d]: %sn", ret, rslt_status, result);
}
}
Sleep(200);
}
printf("n");
fclose(fp);
}
if (error == false)
{
status = MSP_AUDIO_SAMPLE_LAST;
ret = QISRAudioWrite(sess_id, buff, 1, status, &ep_status, &rec_status);
if ( ret != MSP_SUCCESS )
{
printf("QISRAudioWrite write last audio err %dn", ret);
error = true;
}
}
if (error == false)
{
printf("get reusltn");
int loop_count = 0;
do
{
const char* result = QISRGetResult(sess_id, &rslt_status, 0, &ret);
if ( ret != MSP_SUCCESS )
{
printf("QISRGetResult err %dn", ret);
error = true;
break;
}
if( rslt_status == MSP_REC_STATUS_NO_MATCH )
printf("get result nomatchn");
else
{
if ( result != NULL )
fwrite(result, 1, strlen(result), fout);
printf("[%d]:get result[%d/%d]: %sn", (loop_count), ret, rslt_status, result);
}
Sleep(500);
} while (rslt_status != MSP_REC_STATUS_COMPLETE && loop_count++ < 30);
}
if( NULL != fout )
{
fclose(fout);
}
ret = QISRSessionEnd(sess_id, NULL);
if ( ret != MSP_SUCCESS )
{
printf("QISRSessionEnd err %dn", ret);
return;
}
printf("QISRSessionEnd.n");
ret = QISRFini();
return;
}
from : http://bbs.csdn.net/topics/390428493
最后
以上就是端庄板栗为你收集整理的讯飞的语音识别技术VC源码的全部内容,希望文章能够帮你解决讯飞的语音识别技术VC源码所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复