Exemple #1
0
int main(int argc, char* argv[])
{
	const char* login_config = "appid = 5392db98, work_dir =   .  ";
	const char* param = "rst=plain,rse=gb2312,sub=asr,ssm=1,aue=speex,auf=audio/L16;rate=16000,ent=sms16k";//注意sub=asr
	const char* grammar = NULL;
	int ret = 0 ;
	char key = 0 ;
	const char* asrfile = get_audio_file();
	ret = MSPLogin(NULL, NULL, login_config);
	if ( ret != MSP_SUCCESS )
	{
		printf("MSPLogin failed , Error code %d.\n",ret);
		return 0 ;
	}
	grammar = get_grammar( "gm_continuous_digit.abnf" );
	if(ret != MSP_SUCCESS)
	{
		printf("getExID with errorCode: %d \n", ret);
		return 0;
	}
	ret = run_asr(asrfile, param, grammar);
	if(ret != MSP_SUCCESS)
	{
		printf("run_asr with errorCode: %d \n", ret);
		return 0;
	}
	release_grammar(&grammar);
	MSPLogout();
	return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
	const char* grammar = NULL;
	const char* asrfile = get_audio_file();
	int ret = MSP_SUCCESS;
	//appid 请勿随意改动
	ret = QISRInit("appid=52d8f781");
	if(ret != MSP_SUCCESS)
	{
		printf("QISRInit with errorCode: %d \n", ret);
		return 0;
	}

	grammar = get_grammar( "gm_continuous_digit.abnf" );
	if(ret != MSP_SUCCESS)
	{
		printf("getExID with errorCode: %d \n", ret);
		return 0;
	}

	ret = run_asr(grammar , asrfile);
	release_grammar(&grammar);
	
	QISRFini();
	char key = _getch();
	return 0;
}
Exemple #3
0
int main(int argc, char* argv[])
{
	const char* login_config = "appid = 55dbb5fb,work_dir =   .  ";
	const char* param = "rst=plain,rse=utf8,sub=asr,aue=speex-wb,auf=audio/L16;rate=16000,ent=sms16k";    //注意sub=asr,16k音频aue=speex-wb,8k音频识别aue=speex,
	int ret = 0 ;
	char key = 0 ;
	int grammar_flag = 0;//0:不上传词表;1:上传词表
	const char* asrfile = get_audio_file();//选择
	ret = MSPLogin(NULL, NULL, login_config);
	if ( ret != MSP_SUCCESS )
	{
		printf("MSPLogin failed , Error code %d.\n",ret);
		return 0 ;
	}
	memset(GrammarID, 0, sizeof(GrammarID));
	ret = get_grammar_id(grammar_flag);
	if(ret != MSP_SUCCESS)
	{
		printf("get_grammar_id with errorCode: %d \n", ret);
		return 0 ;
	}
 	ret = run_asr(asrfile, param);
	if(ret != MSP_SUCCESS)
	{
		printf("run_asr with errorCode: %d \n", ret);
		return 0;
	}
	MSPLogout();
	return 0;
}
Exemple #4
0
char *get_from_server(char *file)
{
	const char* login_config = "appid = 55801297,work_dir =   .  ";
	const char* param = "rst=plain,rse=utf8,sub=asr,aue=speex-wb,auf=audio/L16;rate=16000,ent=sms16k";    //注意sub=asr,16k音频aue=speex-wb,8k音频识别aue=speex,
	int ret = 0 ;
	char *result;
	char key = 0 ;
	int grammar_flag = 0;//0:不上传词表;1:上传词表
	ret = MSPLogin(NULL, NULL, login_config);
	if ( ret != MSP_SUCCESS )
	{
		printf("MSPLogin failed , Error code %d.\n",ret);
		return 0 ;
	}
	else
	{
		strcpy(GrammarID, "e7eb1a443ee143d5e7ac52cb794810fe");
		result = run_asr(file, param);
		if(result == NULL)
		{
			printf("run_asr with errorCode: %d \n", ret);
		}
		MSPLogout();
	}
	return result;
}
Exemple #5
0
int main(int argc, char* argv[])
{	
	int			ret						=	MSP_SUCCESS;
	const char* login_params			=	"appid = 5652758a, work_dir = ."; //登录参数,appid与msc库绑定,请勿随意改动
	/*
	* sub:             请求业务类型
	* result_type:     识别结果格式
	* result_encoding: 结果编码格式
	*
	* 详细参数说明请参阅《iFlytek MSC Reference Manual》
	*/
	const char*	session_begin_params	=	"sub = asr, result_type = plain, result_encoding = utf8";
	char*		grammar_id				=	NULL;
	
	/* 用户登录 */
	ret = MSPLogin(NULL, NULL, login_params); //第一个参数是用户名,第二个参数是密码,均传NULL即可,第三个参数是登录参数
	if (MSP_SUCCESS != ret)
	{
		printf("MSPLogin failed, error code: %d.\n",ret);
		goto exit; //登录失败,退出登录
	}

	printf("\n##################################################\n");
	printf("## 语音识别(Automatic Speech Recognition)技术 ##\n");
	printf("## 能够从语音中识别出特定的命令词或语句模式。   ##\n");
	printf("##################################################\n\n");

	grammar_id = (char*)malloc(GRAMID_LEN);//动态分配内存
	if (NULL == grammar_id)
	{
		printf("out of memory !\n");
		goto exit;
	}
	memset(grammar_id, 0, GRAMID_LEN);

	printf("上传语法 ...\n");
	ret = get_grammar_id(grammar_id, GRAMID_LEN);
	if (MSP_SUCCESS != ret)
		goto exit;
	printf("上传语法成功\n");

 	run_asr("wav/iflytek01.wav", session_begin_params, grammar_id); //iflytek01对应的音频内容:“18012345678”

exit:
	if (NULL != grammar_id)
	{
		free(grammar_id);
		grammar_id = NULL;
	}
	printf("按任意键退出 ...\n");
	getchar();
	MSPLogout(); //退出登录

	return 0;
}
Exemple #6
0
bool asr(speechrecog::Command::Request  &req,
         speechrecog::Command::Response &res)
{
	const char *login_config    = "appid = 55b1aeb0"; //登录参数
	UserData asr_data; 
	int ret                     = 0 ;
	char c;

	ret = MSPLogin(NULL, NULL, login_config); //第一个参数为用户名,第二个参数为密码,传NULL即可,第三个参数是登录参数
	if (MSP_SUCCESS != ret) {
		printf("登录失败:%d\n", ret);
		goto exit;
	}

	memset(&asr_data, 0, sizeof(UserData));
	printf("构建离线识别语法网络...\n");
	ret = build_grammar(&asr_data);  //第一次使用某语法进行识别,需要先构建语法网络,获取语法ID,之后使用此语法进行识别,无需再次构建
	if (MSP_SUCCESS != ret) {
		printf("构建语法调用失败!\n");
		goto exit;
	}
	while (1 != asr_data.build_fini)
		usleep(300 * 1000);
	if (MSP_SUCCESS != asr_data.errcode)
		goto exit;
	printf("离线识别语法网络构建完成,开始识别...\n");	
	ret = run_asr(&asr_data);
	if (MSP_SUCCESS != ret) {
		printf("离线语法识别出错: %d \n", ret);
		goto exit;
	}

/////////////////////////////将识别结果rec_rslt传递给trigger//////////////////////////////////////////

         res.command=rec_rslt;
         if(flag1)
           res.command=tmpt1;
         if(flag2)
           res.command=tmpt2;
  

exit:
	MSPLogout();
	return true;

}