资料来自:
http://blog.csdn.net/dedodong/archive/2006/08/22/1105879.aspx
取得每个汉字读音的代码
#include <stdio.h>
#include <unistd.h>
#define maxlen 32000
int main(){
FILE * fpr;
FILE * fpw;
//打开临时r.wav语音库
if((fpr=fopen("r.wav","r+"))==NULL){
printf("open r.wav error");
return -1;
}
//打开w.wav文件
if((fpw=fopen("w.wav","w+"))==NULL){
printf("open w.wav error");
return -1;
}
char head[46];//存放wav的头信息
char data[1000];
char buffer[maxlen];//存放每个汉字的读音
int fpoint;//文件当前的位置
int fpointtemp=47;
int isnozero=1;
int num=0;
memset(buffer,0,sizeof(buffer));//初始化buffer
fread(head,sizeof(head),1,fpr);//读wav的头信息46个字节
fwrite(head,sizeof(head),1,fpw);//把头信息写到w.wav文件中去
fread(buffer,sizeof(buffer),1,fpr);
fwrite(buffer,sizeof(buffer),1,fpw);
while(!feof(fpr)){//读文件的信息,直到文件尾
// printf("*****************\n");
//读16个字节判断.找到第一次出现都为0的位置
isnozero=1;
while(isnozero){
fread(data,16,1,fpr);
int i;
int j;
int k=0;
for(i=0;i<16;i++){
j=(int)data[i];
k+=j;
}
if(k==0){
printf("read 1000\n");
fread(data,1000,1,fpr);
if(feof(fpr)){
printf("文件被读完1");
fpoint=ftell(fpr);
printf("fpoint si :%d",fpoint);
exit(1);
}
for( i=0;i<1000;i++){
j=(int)data[i];
k+=j;
}
if(k==0){
fpoint=ftell(fpr);
isnozero=0;
printf(" fpoint data is :%d\n",fpoint);
}else{
isnozero=1;
}
}else{
isnozero=1;
}
}
//找到非0的那一行
int iszero=1;
while(iszero){
fread(data,16,1,fpr);
// printf("num is :%d\n",num);
if(feof(fpr)){
printf("num is :%d\n",num);
printf("文件读完了\n");
fpoint=ftell(fpr);
printf("file len is :%d",fpoint);
fclose(fpr);
fclose(fpw);
exit(-1);
}
int i,j,k=0;
for(i=0;i<16;i++){
j=(int)data[i];
k+=j;
// printf("k is :%d\n",k);
}
if(k==0){
iszero=1;
// printf("k==0\n");
}else{
iszero=0;
fseek(fpr,fpoint-16,SEEK_SET);
int isz=1;
while(isz){
fread(data,1,1,fpr);
if((int)data[0]!=0){
//主要的工作{得到每个汉字的语音数据}
fpoint=ftell(fpr);
printf(" num is --%d fpoint is :%d\n",++num,fpoint);
fseek(fpr,fpoint-2,SEEK_SET);
fread(buffer,sizeof(buffer),1,fpr);
fwrite(buffer,sizeof(buffer),1,fpw);
isz=0;
}
}
}
}
}
fclose(fpr);
fclose(fpw);
return 0;
}