-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmels_a_file.cc
54 lines (45 loc) · 1.22 KB
/
mels_a_file.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* mfcc_a_file.cc
* Copyright (C) 2019 xiaominfc(武汉鸣鸾信息科技有限公司) <[email protected]>
*
* Distributed under terms of the MIT license.
*/
#include "base/kaldi-common.h"
#include "util/common-utils.h"
#include "feat/wave-reader.h"
#include "feat/feature-spectrogram.h"
#include "feat/feature-fbank.h"
#include "matrix/matrix-lib.h"
#include "matrix/matrix-functions.h"
#include "fft.h"
#include "mels_utils.h"
using namespace kaldi;
int main(int argc, char* argv[]){
try{
using namespace kaldi;
//test_hanning_w();
const char *usage = "compute mels feature for a wav file\n"
"Usage: mels_a_file [options...] <wav-path>\n";
ParseOptions po(usage);
po.Read(argc, argv);
if (po.NumArgs() != 1) {
po.PrintUsage();
exit(1);
}
std::string wavpath = po.GetArg(1);
std::ifstream is(wavpath, std::ios_base::binary);
WaveData wave;
wave.Read(is);
SubVector<BaseFloat> waveform(wave.Data(), 0);
float sr = wave.SampFreq();
Matrix<double64> result;
//const uint N = 1024;
const uint N = 800;
melspectrogram(waveform,sr,N,512,80,result);
//只打印第一行
for(int i = 0; i < 80; i++) {
printf("%0.10e\n",result(0,i));
}
}catch(const std::exception &e) {
}
}