智能语音识别--方案实现--具体过程

文章承接上次内容:具体链接--->>>:https://blog.csdn.net/queque_heiya/article/details/104182250

思路:智能语音鼠标输入++txt文档保存++程序读取命令++传递程序读取内容;

过程:

1.新建txt文档或者word,命名为"data字符.txt"或者"data字符.doc";

2.智能语音输入到当前的文档中,注意此时需要将智能语音输出转化为翻译功能;

3.运行以下代码即可;具体代码的实现可以见注释;(这里用字符实现比较容易,两个字符组成的汉字识别亦可);

注释:汉字中同音字十分多,因此Random全部数组中计算机需要学习的数组就应该多;开发者可以多添加数组内容;

注意:代码中开辟的数组空间不大,但是数组个数多,因此考虑const int MAX=10就可以满足目的;
字符实现过程--->>>

#include
#include
#include 
#include
#include
#include 
const int MAX=1000+10;
const int s=10;//定义Random数组的长度 

char buffer[MAX];//定义当前txt文件里面的内容 

char xipai[MAX]={'a','b','c','d','e','f','g','h','i','j'};//这里依次表示小一-->>小十 
char dapai[MAX]={'A','B','C','D','E','F','G','H','I','J'};//这里依次表示大一-->>大十 

//Random
char xiaoyi[MAX][MAX]={"a","Xiao Yi","Auntie","Koichi"};
char xiaoer[MAX][MAX]={"b","Xiao Er","Koji"};
char xiaosan[MAX][MAX]={"c","Xiao San","Kozo"};
char xiaosi[MAX][MAX]={"d","Xiao Si"};
char xiaowu[MAX][MAX]={"e","Xiao Wu","afternoon"};
char xiaoliu[MAX][MAX]={"f","Xiao Liu"};
char xiaoqi[MAX][MAX]={"g","Xiao Qi"};
char xiaoba[MAX][MAX]={"h","Xiao Ba"};
char xiaojiu[MAX][MAX]={"i","Xiao Jiu"};
char xiaoshi[MAX][MAX]={"j","Xiao Shi"};

//Random
char dayi[MAX][MAX]={"A","Da Yi","Overcoat"};
char daer[MAX][MAX]={"B","Da Er"};
char dasan[MAX][MAX]={"C","Da San"};
char dasi[MAX][MAX]={"D","Da Si"};
char dawu[MAX][MAX]={"E","Da Wu"};
char daliu[MAX][MAX]={"F","Da Liu"};
char daqi[MAX][MAX]={"G","Da Qi"};
char daba[MAX][MAX]={"H","Da Ba"};
char dajiu[MAX][MAX]={"I","Da Jiu"};
char dashi[MAX][MAX]={"J","Da Shi"};

void bfs(char ch){
	//可以从数组里面直接搜
	//这里直接打印出来
	printf("%c\n",ch);
	
	//当前的字符即为命令----->>完成后续接口即可 
} 

void solve(char *buffer){
	for(int i=1;i<=s;i++){//在随机数组中找到对应字符 
		if(!strcmp(buffer,xiaoyi[i]))
			bfs(xiaoyi[0][0]);//搜索写多了 哈哈哈哈哈 
		if(!strcmp(buffer,xiaoer[i]))
			bfs(xiaoer[0][0]);
		if(!strcmp(buffer,xiaosan[i]))
			bfs(xiaosan[0][0]);
		if(!strcmp(buffer,xiaosi[i]))
			bfs(xiaosi[0][0]);
		if(!strcmp(buffer,xiaowu[i]))
			bfs(xiaowu[0][0]);
		if(!strcmp(buffer,xiaoliu[i]))
			bfs(xiaoliu[0][0]);
		if(!strcmp(buffer,xiaoqi[i]))
			bfs(xiaoqi[0][0]);
		if(!strcmp(buffer,xiaoba[i]))
			bfs(xiaoba[0][0]);
		if(!strcmp(buffer,xiaojiu[i]))
			bfs(xiaojiu[0][0]);
		if(!strcmp(buffer,xiaoshi[i]))
			bfs(xiaoshi[0][0]);
		if(!strcmp(buffer,dayi[i]))
			bfs(dayi[0][0]);
		if(!strcmp(buffer,daer[i]))
			bfs(daer[0][0]);
		if(!strcmp(buffer,dasan[i]))
			bfs(dasan[0][0]);
		if(!strcmp(buffer,dasi[i]))
			bfs(dasi[0][0]);
		if(!strcmp(buffer,dawu[i]))
			bfs(dawu[0][0]);
		if(!strcmp(buffer,daliu[i]))
			bfs(daliu[0][0]);
		if(!strcmp(buffer,daqi[i]))
			bfs(daqi[0][0]);
		if(!strcmp(buffer,daba[i]))
			bfs(daba[0][0]);
		if(!strcmp(buffer,dajiu[i]))
			bfs(dajiu[0][0]);
		if(!strcmp(buffer,dashi[i]))
			bfs(dashi[0][0]);		
	}
}
int main(){
	//对txt文件的操作 打开文件+读取文件+关闭文件 
	FILE *fp;
	fp=fopen("data字符.txt","r");//打开文件,该文件即为语音输入的及时文件
	fread(buffer,sizeof(char),MAX,fp);
	fclose(fp);//及时关闭文件 
	
	printf("%s\n",buffer);//全部打印内容到屏幕 
	
	solve(buffer);	
	
	//printf("%s\n",buffer);//全部打印内容到屏幕 
	//当前输入结束 
	
	//	renew_txt();//更新文件内容,这里建议是删除全部文件内容 
	
	//	again_input_txt();//即为重新输入文件内容 
	
	//again_main();//重新执行源代码 code!! 

}

汉字操作实现过程--->>>

#include
#include
#include 
#include
#include
#include 
const int MAX=1000+10;
const int s=100;//定义Random数组的长度 

char buffer[MAX];//定义当前txt文件里面的内容 

char Mark[MAX][MAX]={"壹","贰","叁","肆","伍","陆","柒","捌","玖","拾"};//标准内容 
char mark[MAX][MAX]={"一","二","三","四","五","六","七","八","九","十"};//标准内容 

char xipai[MAX]={'a','b','c','d','e','f','g','h','i','j'};//这里依次表示小一-->>小十 
char dapai[MAX]={'A','B','C','D','E','F','G','H','I','J'};//这里依次表示大一-->>大十 

//Random
char xiaoyi[MAX][MAX]={"a","小一","效益","小姨","笑意","孝义"};
char xiaoer[MAX][MAX]={"b","小二","小儿","晓儿"};
char xiaosan[MAX][MAX]={"c","小三","消散","小散"};
char xiaosi[MAX][MAX]={"d","小四","笑死","小厮"};
char xiaowu[MAX][MAX]={"e","小五","小吴","小屋"};
char xiaoliu[MAX][MAX]={"f","小六","小刘","小柳"};
char xiaoqi[MAX][MAX]={"g","小七","小气","校企"};
char xiaoba[MAX][MAX]={"h","小八","小吧","小巴"};
char xiaojiu[MAX][MAX]={"i","小九","小酒","小舅"};
char xiaoshi[MAX][MAX]={"j","小十","小时","消逝"};

//Random
char dayi[MAX][MAX]={"A","大一","大衣","答疑","大意","大姨"};
char daer[MAX][MAX]={"B","大二","达尔","大耳","打二"};
char dasan[MAX][MAX]={"C","大三","打伞","打散","大伞"};
char dasi[MAX][MAX]={"D","大四","打死","大肆","达斯"};
char dawu[MAX][MAX]={"E","大五","大雾","大悟","大物"};
char daliu[MAX][MAX]={"F","大六","大刘","大流","打流"};
char daqi[MAX][MAX]={"G","大七","大气","打气","大器"};
char daba[MAX][MAX]={"H","大八","大巴","大把","打吧"};
char dajiu[MAX][MAX]={"I","大九","大舅","大酒","搭救"};
char dashi[MAX][MAX]={"J","大十","大师","大事","大使"};

void bfs(char ch){
	//可以从数组里面直接搜
	//这里直接打印出来
	printf("%c\n",ch);
	
	//当前的字符即为命令----->>完成后续即可 
} 

void solve(char *buffer){
	for(int i=1;i<=s;i++){//在随机数组中找到对应字符 
		if(!strcmp(buffer,xiaoyi[i]))
			bfs(xiaoyi[0][0]);//搜索写多了 哈哈哈哈哈 
		if(!strcmp(buffer,xiaoer[i]))
			bfs(xiaoer[0][0]);
		if(!strcmp(buffer,xiaosan[i]))
			bfs(xiaosan[0][0]);
		if(!strcmp(buffer,xiaosi[i]))
			bfs(xiaosi[0][0]);
		if(!strcmp(buffer,xiaowu[i]))
			bfs(xiaowu[0][0]);
		if(!strcmp(buffer,xiaoliu[i]))
			bfs(xiaoliu[0][0]);
		if(!strcmp(buffer,xiaoqi[i]))
			bfs(xiaoqi[0][0]);
		if(!strcmp(buffer,xiaoba[i]))
			bfs(xiaoba[0][0]);
		if(!strcmp(buffer,xiaojiu[i]))
			bfs(xiaojiu[0][0]);
		if(!strcmp(buffer,xiaoshi[i]))
			bfs(xiaoshi[0][0]);
		if(!strcmp(buffer,dayi[i]))
			bfs(dayi[0][0]);
		if(!strcmp(buffer,daer[i]))
			bfs(daer[0][0]);
		if(!strcmp(buffer,dasan[i]))
			bfs(dasan[0][0]);
		if(!strcmp(buffer,dasi[i]))
			bfs(dasi[0][0]);
		if(!strcmp(buffer,dawu[i]))
			bfs(dawu[0][0]);
		if(!strcmp(buffer,daliu[i]))
			bfs(daliu[0][0]);
		if(!strcmp(buffer,daqi[i]))
			bfs(daqi[0][0]);
		if(!strcmp(buffer,daba[i]))
			bfs(daba[0][0]);
		if(!strcmp(buffer,dajiu[i]))
			bfs(dajiu[0][0]);
		if(!strcmp(buffer,dashi[i]))
			bfs(dashi[0][0]);		
	}
}
int main(){
	//对txt文件的操作 打开文件+读取文件+关闭文件 
	FILE *fp;
	fp=fopen("data字符.txt","r");//打开文件,该文件即为语音输入的及时文件
	fread(buffer,sizeof(char),MAX,fp);
	fclose(fp);//及时关闭文件 
	
	printf("%s\n",buffer);//全部打印内容到屏幕 
	
	solve(buffer);	
	
	//printf("%s\n",buffer);//全部打印内容到屏幕 
	//当前输入结束 
	
	//	renew_txt();//更新文件内容,这里建议是删除全部文件内容 
	
	//	again_input_txt();//即为重新输入文件内容 
	
	//again_main();//重新执行源代码 code!! 

}

演示过程:一汉字为例--->>>

1.新建文本文档,命名为data字符.txt并且在文档中语音输入大巴,对应预处理的字符应该为H;之后保存文档即可;

 

智能语音识别--方案实现--具体过程_第1张图片

2.执行程序,对应以上程序运行的结果是:

大巴
H

--------------------------------
Process exited after 0.2861 seconds with return value 0
请按任意键继续. . .

3.多次验证程序正确;

4.补充一段代码;把原来文字处理程序的代码换成以下代码;

void bfs(char ch){
	//可以从数组里面直接搜
	//这里直接打印出来
	printf("%c\n",ch);
	if(ch>='a'&&ch<='j')	printf("%s\n",mark[ch-'a']);
	else	 printf("%s\n",Mark[ch-'A']);
	
	//当前的字符即为命令----->>完成后续即可 接口处implement 
} 

其他内容不变,程序运行的结果是:

大巴
H
捌

--------------------------------
Process exited after 0.3065 seconds with return value 0
请按任意键继续. . .

最后说明:用户只需要人为对鼠标说话即可,程序延迟时间不会超过1000ms;

笔者能力有限,如果读者有更优质的算法还望指正并且评论指出.

你可能感兴趣的:(智能语音识别--方案实现--具体过程)