資源簡介
壓縮包中包含mfcc特征文件,這個代碼實現了用于語音mfcc特征的DTW匹配算法。
代碼片段和文件信息
#include?“stdafx.h“
#include?“dtw.h“
#include?
DTW::DTW()
{
pszMfcc1?=?“./mfccout.txt“;
pszMfcc2?=?“./mfccout1.txt“;?
}
DTW::~DTW()
{
}
/*************************************************
Function:???????//?void?slipt(CString?strInvector?*pframe)
Description:????//?將strIn按照空格這樣的分隔符分割并轉為float類型
Input:??????????//?CString?strIn?輸入待分割語句,?
????????????????//?vector?*pframe?輸出的float類型數組?轉換結果
Return:?????????//?NULL
Others:?????????//?2012/3/17
*************************************************/
void?DTW::slipt(char*?strInvector?*pframe)
{
float?x;
int?i?=?0;
int?nsize?=?1000;
string?strtemp;
while?(i {
if?(strIn[i]?!=?‘?‘)//get?the?char?at?the?position?i?of?strIn
{
//strcat(strtmppch);
strtemp.push_back(strIn[i]);
}
else
{
if?(strtemp?!=?““)//acquire?a?whole?number??str?style
{
x?=?atof(strtemp.c_str());//transform?into?float?style
pframe->push_back(x);
//memset(strtemp064);
strtemp?=?““;
}
}
i++;
}
nsize?=?pframe->size();
cout<
}
/*************************************************
Function:???????//?bool?loadF(?vector>?*MFCC_1?vector>?*MFCC_2)
Description:????//?從文本文件中讀入MFCC特征并分別保存至?MFCC_1以及MFCC_2中
Input:??????????//?vector>?*MFCC_1??存儲模型文件mfcc特征向量的地址
????????????????//?vector>?*MFCC_2??存儲待識別文件mfcc特征向量的地址
Return:?????????//?true?加載成功,False?加載失敗
Others:?????????//?2012/3/17
*************************************************/
bool?DTW::loadF(?vector>?*MFCC_1?vector>?*MFCC_2)
{
vector?frame;
ifstream?MfccFile1(pszMfcc1);
ifstream?MfccFile2(pszMfcc1);
//open?the?mfcc1?file?
//if?(?!MfccFile1.Open(pszMfcc1CFile::typeText|CFile::modeReadWrite)?)
//{
// cout<<“can?not?open?the?file?mfcc1?“< // return?0;
//}
char?strlinein[1000];
memset(strlinein321000);//將數據緩存部分均存為空格,空格為間隔位也為結束位;
//MfccFile1.getline(strlinein1000);
while?(MfccFile1.getline(strlinein1000))
{
//slipt?strlinein?into?float?vectors
frame.swap(vector());
slipt(strlinein&frame);
MFCC_1->push_back(frame);
//cout< //cout< //put?the?data?into?MFCC_1
}
//load?data?from?file?into?mfcc_2
memset(strlinein321000);
while?(MfccFile2.getline(strlinein1000))
{
//slipt?strlinein?into?float?vectors
frame.swap(vector());
slipt(strlinein&frame);
MFCC_2->push_back(frame);
//cout< //cout< //put?the?data?into?MFCC_1
//linein;
}
return?1;
}
/*************************************************
Function:???????//?float?distanceF(vector?a?vector?b)
Description:????//?計算向量a和向量b的距離
Input:??????????//?vector?a??模型mfcc特征向量
????????????????//?vector?b??待識別mfcc特征向量
Return:?????????//?返回相應距離
Others:?????????//?2012/3/19
*****
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????6237696??2012-03-26?10:35??dtw\dtw\Debug\dtw.exe
?????文件???15040356??2012-03-26?10:35??dtw\dtw\Debug\dtw.ilk
?????文件???26323968??2012-03-26?10:35??dtw\dtw\Debug\dtw.pdb
?????文件???????1876??2012-03-26?10:35??dtw\dtw\dtw\Debug\cl.command.1.tlog
?????文件??????50386??2012-03-26?10:35??dtw\dtw\dtw\Debug\CL.read.1.tlog
?????文件???????1016??2012-03-26?10:35??dtw\dtw\dtw\Debug\CL.write.1.tlog
?????文件????????406??2012-03-20?10:29??dtw\dtw\dtw\Debug\dtw.exe.em
?????文件????????472??2012-03-20?10:29??dtw\dtw\dtw\Debug\dtw.exe.em
?????文件????????381??2012-03-26?10:35??dtw\dtw\dtw\Debug\dtw.exe.intermediate.manifest
?????文件?????????47??2012-03-26?10:35??dtw\dtw\dtw\Debug\dtw.lastbuildstate
?????文件???????2501??2012-03-26?10:35??dtw\dtw\dtw\Debug\dtw.log
?????文件?????766681??2012-03-26?10:35??dtw\dtw\dtw\Debug\dtw.obj
?????文件????1245184??2012-03-20?10:28??dtw\dtw\dtw\Debug\dtw.pch
?????文件????????196??2012-03-20?10:28??dtw\dtw\dtw\Debug\dtw_manifest.rc
?????文件??????????2??2012-03-26?10:35??dtw\dtw\dtw\Debug\li
?????文件??????????2??2012-03-26?10:35??dtw\dtw\dtw\Debug\li
?????文件??????????2??2012-03-26?10:35??dtw\dtw\dtw\Debug\li
?????文件??????????2??2012-03-26?10:35??dtw\dtw\dtw\Debug\li
?????文件??????????2??2012-03-26?10:35??dtw\dtw\dtw\Debug\li
?????文件??????????2??2012-03-26?10:35??dtw\dtw\dtw\Debug\li
?????文件??????????2??2012-03-26?10:35??dtw\dtw\dtw\Debug\li
?????文件??????????2??2012-03-26?10:35??dtw\dtw\dtw\Debug\li
?????文件??????????2??2012-03-26?10:35??dtw\dtw\dtw\Debug\li
?????文件??????????2??2012-03-26?10:35??dtw\dtw\dtw\Debug\li
?????文件??????????2??2012-03-26?10:35??dtw\dtw\dtw\Debug\li
?????文件??????????2??2012-03-26?10:35??dtw\dtw\dtw\Debug\li
?????文件??????????2??2012-03-26?10:35??dtw\dtw\dtw\Debug\li
?????文件??????????2??2012-03-26?10:35??dtw\dtw\dtw\Debug\li
?????文件??????????2??2012-03-26?10:35??dtw\dtw\dtw\Debug\li
?????文件??????????2??2012-03-26?10:35??dtw\dtw\dtw\Debug\li
............此處省略47個文件信息
評論
共有 條評論