WEB开发网
开发学院软件开发VC 在vc++6.0/2003/2005/2008中调用HTK 阅读

在vc++6.0/2003/2005/2008中调用HTK

 2009-04-27 20:06:39 来源:WEB开发网   
核心提示: // sprintf(outFile, "%s%s.vec", "c:", VoiceName);// FILE* fout = fopen(outFile, "w+b"); //打开或创建向量文件FILE *fp = fopen

  // sprintf(outFile, "%s%s.vec", "c:", VoiceName);
  // FILE* fout = fopen(outFile, "w+b"); //打开或创建向量文件
  FILE *fp = fopen(VoiceName, "rb");
  fseek(fp, 0L, SEEK_END);
  long size = ftell(fp);
  fseek(fp, 44L, SEEK_SET); //跳过wav头
  int old_clock = clock();
  // long segSize = fread(p8bitBuf, sizeof(char), bufSampleSize, fp);
  //alaw2linear( p8bitBuf , bufSampleSize , pFileBuf );
  long segSize = fread(pFileBuf, sizeof(short), bufSampleSize, fp);
  TSoundTag* pOut;
  int outSize, tailSize;
  short* pTail=NULL;
  int last_result[17];
  int iMax = sudxGetMaxInputSampleSize();
  int error = sudxCalcBuffer( pFileBuf, segSize, &pOut, &outSize, &pTail, &tailSize, last_result);
  if ( error > 0 )
  {
  if ( outSize > (64 + 1 ))
  {
  old_clock = clock();
  int compare_turn = outSize - 64 - 1;
  for(i=0; i<COMPARE_TURN; { int i++) for(int [%s]n?, file if(tailSize tailSize="compare_turn+64-300-i;" sampleSetList[j].name); (i+1)*128, %d, pos sample at Match printf(?Quick ) FALSE) &(sampleSetList[j].tags[1]), sudxCompare(pOut+1+i, if( j++) j<vector_count; j="0;">300)
  {
  if(sudxCompare(pOut+1+i, sampleSetList[j].tags+1, TRUE))
  printf("精确匹配位置 %d, file[%s]n", (i+1)*128, sampleSetList[j].name);
  else
  printf("!!Slow Not Match at sample pos %d, file[%s]n", (i+1)*128, sampleSetList[j].name);
  }
  }
  else
  {
  printf("Not Match at sample pos %d, file [%s]n", (i+1)*128, sampleSetList[j].name);
  }
  }
  }
  int time_passed = clock()-old_clock;
  printf("计算结束, 耗时%d msn", time_passed);
  printf("比较速度为每秒钟可查找%f秒音乐n", double(compare_turn)*128.0/8000.0/(double(time_passed)/1000.0));
  }
  else
  {
  printf("输入的声音过短,不能比较n");
  return -2;
  }
  }
  else
  {
  return -1;
  }
  return 0;
  }
  int VRecoInit(char * vecDirectory )
  {
  int i = ListVecFiles(vecDirectory, sampleList);
  if(i<=0)
  {
  printf("No sample files in dir [%s]n", vecDirectory);
  return -2;
  }
  vector_count = LoadVecFiles(sampleList, sampleSetList);
  if(vector_count<=0)
  {
  printf("没有找到样本集合文件n");
  return -3;
  }
  return 0;
  }
  ///
  int VRecognize(char *VoiceName, char* vecDirectory , bool bVolumeFlag, int * iMatchCount)
  {
  /*if(argc!=4)
  {
  printf("参数错误n");
  printf("使用方法:test <声音文件名> <样本目录> <音量标志>n");
  printf("t声音文件名是要被识别的声音文件,样本目录中包含已经预先处理好的样本n"
  "t 音量标志: 表示识别时是否采用音量相关的方式,为0表示识别时不管音量大小,为1表示识别时需要考虑音量大小n"
  "Press any key continue...");
  getch();
  return -1;
  }*/
  //int volFlag = atol(argv[3]);
  if(bVolumeFlag)
  {
  sudxSetCompVolumeFlag(TRUE);
  printf("采用与音量相关的方式比较n");
  }
  else
  {
  sudxSetCompVolumeFlag(FALSE);
  printf("采用与音量无关的方式比较n");
  }
  char gcaMsg[1000];
  sprintf(gcaMsg , "Now start...%sn", VoiceName);
  printf( gcaMsg );
  fflush(stdout);
  const int bufSampleSize = 2048*1024; ////充值成功,你的账户余额为的 8k采样,8位长度编码的语音文件大小
  unsigned char * p8bitBuf = new unsigned char[ bufSampleSize];
  short *pFileBuf = new short[bufSampleSize]; //每次处理2M个16bit pcm样本,也就是4M byte数据。
  // char outFile[1000];
  // sprintf(outFile, "%s%s.vec", "c:", VoiceName);
  // FILE* fout = fopen(outFile, "w+b"); //打开或创建向量文件
  try
  {
  sprintf(gcaMsg , "bf fopen...%sn", VoiceName);
  printf( gcaMsg );
  fflush(stdout);
  FILE *fp = fopen(VoiceName, "rb");
  fseek(fp, 0L, SEEK_END);
  long size = ftell(fp);
  fseek(fp, 44L, SEEK_SET); //跳过wav头
  sprintf(gcaMsg , "af fopen...%sn", VoiceName);
  printf( gcaMsg );
  fflush(stdout);
  int old_clock = clock();
  long segSize = fread(p8bitBuf, sizeof(char), bufSampleSize, fp);
  alaw2linear( p8bitBuf , bufSampleSize , pFileBuf );
  sprintf(gcaMsg , "Af alaw2linear...%sn", VoiceName);
  printf( gcaMsg );
  fflush(stdout);
  // long segSize = fread(pFileBuf, sizeof(short), bufSampleSize, fp);
  TSoundTag* pOut;
  int outSize, tailSize;
  short* pTail=NULL;
  int last_result[17];
  //int iMax = sudxGetMaxInputSampleSize();

上一页  1 2 3 4 5  下一页

Tags:vc 调用 HTK

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接