Skip to content

Commit

Permalink
* support speech command
Browse files Browse the repository at this point in the history
  • Loading branch information
lxowalle committed Jan 15, 2025
1 parent c703fbd commit 3c729b8
Show file tree
Hide file tree
Showing 12 changed files with 420 additions and 45 deletions.
64 changes: 64 additions & 0 deletions components/3rd_party/kaldi-native-fbank/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
set(kaldi_native_fbank_unzip_path "${DL_EXTRACTED_PATH}/kaldi-native-fbank_srcs")
set(src_path "${kaldi_native_fbank_unzip_path}")
################# Add include #################
list(APPEND ADD_INCLUDE "${src_path}/kaldi-native-fbank"
)
# list(APPEND ADD_PRIVATE_INCLUDE "include_private")
###############################################

############## Add source files ###############
# list(APPEND ADD_SRCS "src/lib1.c"
# )
append_srcs_dir(ADD_SRCS "${src_path}/kaldi-native-fbank/kaldi-native-fbank/csrc"
)
list(REMOVE_ITEM ADD_SRCS "${src_path}/kaldi-native-fbank/kaldi-native-fbank/csrc/test-log.cc"
"${src_path}/kaldi-native-fbank/kaldi-native-fbank/csrc/test-online-fbank.cc"
"${src_path}/kaldi-native-fbank/kaldi-native-fbank/csrc/test-online-feature.cc"
"${src_path}/kaldi-native-fbank/kaldi-native-fbank/csrc/test-rfft.cc")

# aux_source_directory("inifile2/src" ADD_SRCS) # collect all source file in src dir, will set var ADD_SRCS
# append_srcs_dir(ADD_SRCS "src") # append source file in src dir to var ADD_SRCS
# list(REMOVE_ITEM COMPONENT_SRCS "src/test.c")
###############################################

###### Add required/dependent components ######
# list(APPEND ADD_REQUIREMENTS component1)
###############################################

###### Add link search path for requirements/libs ######
# list(APPEND ADD_LINK_SEARCH_PATH "${CONFIG_TOOLCHAIN_PATH}/lib")
# list(APPEND ADD_REQUIREMENTS m) # add system libs, pthread or m(math) lib for example
###############################################

############ Add static libs ##################
# if(CONFIG_COMPONENT1_INCLUDE_STATIC_LIB)
# list(APPEND ADD_STATIC_LIB "lib/libtest.a")
# endif()
###############################################

############ Add dynamic libs ##################
# list(APPEND ADD_DYNAMIC_LIB "lib/arch/v831/libmaix_nn.so"
# "lib/arch/v831/libmaix_cam.so"
# )
###############################################

#### Add compile option for this component ####
#### Just for this component, won't affect other
#### modules, including component that depend
#### on this component
# list(APPEND ADD_DEFINITIONS_PRIVATE -DAAAAA=1)

#### Add compile option for this component
#### Add components that depend on this component
# list(APPEND ADD_DEFINITIONS -DAAAAA222=1
# -DAAAAA333=1)
###############################################

############ Add static libs ##################
#### Update parent's variables like CMAKE_C_LINK_FLAGS
# set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--start-group libmaix/libtest.a -ltest2 -Wl,--end-group" PARENT_SCOPE)
###############################################

# register component, DYNAMIC or SHARED flags will make component compiled to dynamic(shared) lib
register_component()

Empty file.
34 changes: 34 additions & 0 deletions components/3rd_party/kaldi-native-fbank/component.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

def add_file_downloads(confs : dict) -> list:
'''
@param confs kconfig vars, dict type
@return list type, items is dict type
'''
version = "1.20.1"
url = "/~https://github.com/csukuangfj/kaldi-native-fbank/archive/refs/tags/v1.20.1.tar.gz"
if version == "1.20.1":
sha256sum = "170cb8c6b8b96891ebb2e3ddaa427cd5d81e40efc48501ac0bd9b24301c09856"
else:
raise Exception(f"version {version} not support")
sites = ["/~https://github.com/sipeed/MaixCDK/releases/tag/v0.0.0"]
filename = f"kaldi-native-fbank-{version}.tar.gz"
path = "kaldi-native-fbank_srcs"
check_file = f'kaldi-native-fbank'
rename = {f'kaldi-native-fbank-{version}': 'kaldi-native-fbank'}

return [
{
'url': f'{url}',
'urls': [],
'sites': sites,
'sha256sum': sha256sum,
'filename': filename,
'path': path,
'check_files': [
check_file
],
'rename': rename
}
]


Binary file added examples/onnxruntime_demo/kws_hibela.onnx
Binary file not shown.
3 changes: 2 additions & 1 deletion examples/onnxruntime_demo/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ append_srcs_dir(ADD_SRCS "src"
"core/kws"
) # append source file in src dir to var ADD_SRCS

list(APPEND ADD_DYNAMIC_LIB "onnxruntime-src/lib/libonnxruntime.so")
list(APPEND ADD_DYNAMIC_LIB "onnxruntime-src/lib/libonnxruntime.so.1")

# FILE(GLOB_RECURSE EXTRA_SRC "src/*.c")
# FILE(GLOB EXTRA_SRC "src/*.c")
Expand All @@ -31,6 +31,7 @@ list(APPEND ADD_DYNAMIC_LIB "onnxruntime-src/lib/libonnxruntime.so")
###############################################

###### Add required/dependent components ######
list(APPEND ADD_REQUIREMENTS basic vision kaldi-native-fbank)

###############################################

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ bool FeaturePipeline::Read(int num_frames,
std::vector<std::vector<float>>* feats) {
feats->clear();
std::vector<float> feat;
while (feats->size() < num_frames) {
while (feats->size() < (size_t)num_frames) {
if (ReadOne(&feat)) {
feats->push_back(std::move(feat));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class FeaturePipeline {
// in feature_queue_ and the input is not finished.
bool Read(int num_frames, std::vector<std::vector<float>>* feats);

bool Empty() { return feature_queue_.Empty(); }
size_t Size() { return feature_queue_.Size(); }
void Reset();
bool IsLastFrame(int frame) const {
return input_finished_ && (frame == num_frames_ - 1);
Expand Down
2 changes: 2 additions & 0 deletions examples/onnxruntime_demo/main/core/frontend/wav.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class WavReader {
explicit WavReader(const std::string& filename) { Open(filename); }

bool Open(const std::string& filename) {
num_samples_ = 16000;
data_ = nullptr;
FILE* fp = fopen(filename.c_str(), "rb");
if (NULL == fp) {
LOG(WARNING) << "Error in read " << filename;
Expand Down
4 changes: 2 additions & 2 deletions examples/onnxruntime_demo/main/core/kws/keyword_spotting.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void KeywordSpotting::Forward(
int num_frames = feats.size();
int feature_dim = feats[0].size();
std::vector<float> slice_feats;
for (int i = 0; i < feats.size(); i++) {
for (size_t i = 0; i < feats.size(); i++) {
slice_feats.insert(slice_feats.end(), feats[i].begin(), feats[i].end());
}
const int64_t feats_shape[3] = {1, num_frames, feature_dim};
Expand Down Expand Up @@ -102,7 +102,7 @@ void KeywordSpotting::Forward(
num_outputs = type_info.GetShape()[1];
output_dim = type_info.GetShape()[2];
} else {
printf("unknowdn shape size:%d", shape.size());
printf("unknowdn shape size:%ld", shape.size());
return;
}

Expand Down
Loading

0 comments on commit 3c729b8

Please sign in to comment.