Refactor offline recognizer. (#94)

* Refactor offline recognizer.

The purpose is to make it easier to support different types of models.
This commit is contained in:
Fangjun Kuang
2023-03-27 14:59:40 +08:00
committed by GitHub
parent 5572246253
commit dffb0fd43c
9 changed files with 283 additions and 134 deletions

View File

@@ -5,6 +5,8 @@
#include "sherpa-onnx/csrc/text-utils.h"
#include <assert.h>
#include <string>
#include <vector>
@@ -27,4 +29,31 @@ void SplitStringToVector(const std::string &full, const char *delim,
}
}
template <class F>
bool SplitStringToFloats(const std::string &full, const char *delim,
bool omit_empty_strings, // typically false
std::vector<F> *out) {
assert(out != nullptr);
if (*(full.c_str()) == '\0') {
out->clear();
return true;
}
std::vector<std::string> split;
SplitStringToVector(full, delim, omit_empty_strings, &split);
out->resize(split.size());
for (size_t i = 0; i < split.size(); ++i) {
// assume atof never fails
(*out)[i] = atof(split[i].c_str());
}
return true;
}
// Instantiate the template above for float and double.
template bool SplitStringToFloats(const std::string &full, const char *delim,
bool omit_empty_strings,
std::vector<float> *out);
template bool SplitStringToFloats(const std::string &full, const char *delim,
bool omit_empty_strings,
std::vector<double> *out);
} // namespace sherpa_onnx