parent
ee24df1023
commit
0e27088c1b
@ -1,20 +0,0 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
add_library(kaldi_feature
|
||||
kaldi_feature.cc
|
||||
kaldi_feature_wrapper.cc
|
||||
)
|
||||
target_link_libraries(kaldi_feature kaldi-fbank)
|
||||
|
||||
pybind11_add_module(kaldi_featurepy kaldi_feature.cc kaldi_feature_wrapper.cc)
|
||||
target_link_libraries(kaldi_featurepy PRIVATE kaldi_feature)
|
||||
|
||||
set(bin_name kaldi_feature_main)
|
||||
add_executable(${bin_name} ${CMAKE_CURRENT_SOURCE_DIR}/${bin_name}.cc)
|
||||
target_include_directories(${bin_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_link_libraries(${bin_name} PUBLIC kaldi_feature python3.7m)
|
@ -1,27 +0,0 @@
|
||||
#include <iostream>
|
||||
#include "kaldi_feature_wrapper.h"
|
||||
#include <vector>
|
||||
#include "wav.h"
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/numpy.h>
|
||||
|
||||
using namespace std;
|
||||
namespace py=pybind11;
|
||||
|
||||
int main() {
|
||||
kaldi::Vector<kaldi::BaseFloat> wav(raw_wav.size());
|
||||
kaldi::Vector<kaldi::BaseFloat> result;
|
||||
for (int idx = 0; idx < raw_wav.size(); ++idx) {
|
||||
wav(idx) = raw_wav[idx];
|
||||
}
|
||||
kaldi::FbankOptions opts;
|
||||
paddleaudio::Fbank fbank(opts);
|
||||
fbank.ComputeFeature(wav, &result);
|
||||
for (int idx = 0; idx < 10; ++idx) {
|
||||
////double val = *((double*)result.data(0, idx));
|
||||
float val = result(idx);
|
||||
cout << val << " ";
|
||||
}
|
||||
cout << endl;
|
||||
fbank.Reset();
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
#include "kaldi_feature_wrapper.h"
|
||||
|
||||
namespace paddleaudio {
|
||||
|
||||
KaldiFeatureWrapper* KaldiFeatureWrapper::GetInstance() {
|
||||
static KaldiFeatureWrapper instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
bool KaldiFeatureWrapper::InitFbank(kaldi::FbankOptions opts) {
|
||||
fbank_.reset(new Fbank(opts));
|
||||
return true;
|
||||
}
|
||||
|
||||
py::array_t<double> KaldiFeatureWrapper::ComputeFbank(const py::array_t<double> wav) {
|
||||
/*
|
||||
py::buffer_info info = wav.request();
|
||||
kaldi::Vector<kaldi::BaseFloat> input_wav;
|
||||
kaldi::Vector<kaldi::BaseFloat> feats;
|
||||
memcpy(input_wav.Data(), (double*)info.ptr, wav.nbytes());
|
||||
fbank_->ComputeFeature(input_wav, &feats);
|
||||
auto result = py::array_t<double>(feats.Dim());
|
||||
py::buffer_info xs = result.request();
|
||||
memcpy((double*)xs.ptr, feats.Data(), feats.Dim()*sizeof(kaldi::BaseFloat));
|
||||
return result.reshape({ feats.Dim() / Dim(), Dim()});
|
||||
*/
|
||||
py::buffer_info info = wav.request();
|
||||
auto result = py::array_t<double>(info.size);
|
||||
py::buffer_info result_info = result.request();
|
||||
|
||||
double* req_ptr = (double*)info.ptr;
|
||||
double* res_ptr = (double*)result_info.ptr;
|
||||
std::cout << info.itemsize << std::endl;
|
||||
std::cout << info.format<< std::endl;
|
||||
std::cout << info.ndim<< std::endl;
|
||||
std::cout << "shape" << std::endl;
|
||||
for (int i = 0; i < info.shape.size(); ++i) {
|
||||
std::cout << info.shape[i]<< std::endl;
|
||||
}
|
||||
|
||||
std::cout << "strides" << std::endl;
|
||||
for (int i = 0; i < info.strides.size(); ++i) {
|
||||
std::cout << info.strides[i]<< std::endl;
|
||||
}
|
||||
|
||||
std::cout << "result shape" << std::endl;
|
||||
for (int i = 0; i < result_info.shape.size(); ++i) {
|
||||
std::cout << result_info.shape[i]<< std::endl;
|
||||
}
|
||||
|
||||
int max_idx = 1;
|
||||
for (auto dim : info.shape) {
|
||||
max_idx *= dim;
|
||||
}
|
||||
|
||||
for (int i = 0; i < max_idx; i++) {
|
||||
*res_ptr = (*req_ptr) * (*req_ptr);
|
||||
res_ptr++;
|
||||
req_ptr++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
} // namespace paddleaudio
|
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue