/** @function ******************************************************************************** <PRE> 函数名: voiceToMFCC() 功能: 得到语音的MFCC参数组 用法: 参数: [IN] pRawVoice: 原始语音数据 [IN] iSampleNum: 语音样本数 [OUT] MFCC: 指向存放MFCC参数组的指针,大小为MFCC[帧数][20] [IN] train_frame_num: 训练帧帧数 返回: TRUE: 成功提取 FALSE: 提取失败 调用: PreEmphasis(), JudgeTrainFrame(), FrameMultiHamming(), FrameToMFCC() 主调函数: 备注: 提供给外层的接口 </PRE> *******************************************************************************/ BOOL voiceToMFCC(BYTE * pRawVoice, int iSampleNum, double ** MFCC, int train_frame_num) { double * pDiffVoice = NULL; double * pDiff = NULL; VOICEFRAME * pVoiceFrame = NULL; // 指向可用的训练帧 //pDiffVoice = (double *)malloc(iSampleNum * sizeof(double)); pDiffVoice = (double *)calloc(iSampleNum, sizeof(double)); if (!pDiffVoice) { xprint("pDiffVoice"); return FALSE; } PreEmphasis(pRawVoice, iSampleNum, pDiffVoice); // 预增强 pDiff = JudgeTrainFrame2(pDiffVoice, iSampleNum, train_frame_num); if (!pDiff) // 判断静寂语音 { //xprint("Error: It`s silent voice!"); free(pDiffVoice); return FALSE; } pVoiceFrame = (VOICEFRAME *)malloc(train_frame_num * sizeof(VOICEFRAME)); FrameMultiHamming(pDiff, pVoiceFrame, train_frame_num); // 得到频域帧 free(pDiff); FrameToMFCC(pVoiceFrame, MFCC, train_frame_num); // 从帧得到MFCC参数组 free(pVoiceFrame); free(pDiffVoice); return TRUE; }
/** @function ******************************************************************************** <PRE> 函数名: voiceToMFCC() 功能: 得到语音的MFCC参数组 用法: 参数: [IN] pRawVoice: 原始语音数据 [IN] iSampleNum: 语音样本数 [OUT] MFCC: 指向存放MFCC参数组的数组指针,大小为MFCC[帧数][20] 返回: TRUE: 成功提取 FALSE: 提取失败 调用: PreEmphasis(), JudgeTrainFrame(), FrameMultiHamming(), FrameToMFCC() 主调函数: 备注: 提供给外层的接口 </PRE> *******************************************************************************/ BOOL voiceToMFCC(BYTE * pRawVoice, int iSampleNum, double MFCC[GOOD_FRAME_NUM][D]) { double * pDiffVoice = NULL; double * pDiff = NULL; VOICEFRAME pVoiceFrame[GOOD_FRAME_NUM] = {{NULL}}; //指向可用的训练帧 pDiffVoice = (double *)malloc(iSampleNum * sizeof(double)); if (!pDiffVoice) { return FALSE; } PreEmphasis(pRawVoice, iSampleNum, pDiffVoice); //预增强 pDiff = JudgeTrainFrame2(pDiffVoice, iSampleNum); //pDiff = pDiffVoice; if (!pDiff) //判断静寂语音 { #ifdef _DEBUG printf("Error: It`s silent voice!\n"); #endif // _DEBUG free(pDiffVoice); return FALSE; } FrameMultiHamming(pDiff, pVoiceFrame); //得到频域帧 free(pDiff); FrameToMFCC(pVoiceFrame, MFCC); //从帧得到MFCC参数组 free(pDiffVoice); return TRUE; }