Add C++ runtime for non-streaming faster conformer transducer from NeMo. (#854)
This commit is contained in:
@@ -14,10 +14,10 @@ namespace sherpa_onnx {
|
||||
static void PybindOfflineRecognizerConfig(py::module *m) {
|
||||
using PyClass = OfflineRecognizerConfig;
|
||||
py::class_<PyClass>(*m, "OfflineRecognizerConfig")
|
||||
.def(py::init<const OfflineFeatureExtractorConfig &,
|
||||
const OfflineModelConfig &, const OfflineLMConfig &,
|
||||
const OfflineCtcFstDecoderConfig &, const std::string &,
|
||||
int32_t, const std::string &, float, float>(),
|
||||
.def(py::init<const FeatureExtractorConfig &, const OfflineModelConfig &,
|
||||
const OfflineLMConfig &, const OfflineCtcFstDecoderConfig &,
|
||||
const std::string &, int32_t, const std::string &, float,
|
||||
float>(),
|
||||
py::arg("feat_config"), py::arg("model_config"),
|
||||
py::arg("lm_config") = OfflineLMConfig(),
|
||||
py::arg("ctc_fst_decoder_config") = OfflineCtcFstDecoderConfig(),
|
||||
|
||||
@@ -25,6 +25,7 @@ Args:
|
||||
static void PybindOfflineRecognitionResult(py::module *m) { // NOLINT
|
||||
using PyClass = OfflineRecognitionResult;
|
||||
py::class_<PyClass>(*m, "OfflineRecognitionResult")
|
||||
.def("__str__", &PyClass::AsJsonString)
|
||||
.def_property_readonly(
|
||||
"text",
|
||||
[](const PyClass &self) -> py::str {
|
||||
@@ -37,18 +38,7 @@ static void PybindOfflineRecognitionResult(py::module *m) { // NOLINT
|
||||
"timestamps", [](const PyClass &self) { return self.timestamps; });
|
||||
}
|
||||
|
||||
static void PybindOfflineFeatureExtractorConfig(py::module *m) {
|
||||
using PyClass = OfflineFeatureExtractorConfig;
|
||||
py::class_<PyClass>(*m, "OfflineFeatureExtractorConfig")
|
||||
.def(py::init<int32_t, int32_t>(), py::arg("sampling_rate") = 16000,
|
||||
py::arg("feature_dim") = 80)
|
||||
.def_readwrite("sampling_rate", &PyClass::sampling_rate)
|
||||
.def_readwrite("feature_dim", &PyClass::feature_dim)
|
||||
.def("__str__", &PyClass::ToString);
|
||||
}
|
||||
|
||||
void PybindOfflineStream(py::module *m) {
|
||||
PybindOfflineFeatureExtractorConfig(m);
|
||||
PybindOfflineRecognitionResult(m);
|
||||
|
||||
using PyClass = OfflineStream;
|
||||
|
||||
@@ -4,8 +4,8 @@ from pathlib import Path
|
||||
from typing import List, Optional
|
||||
|
||||
from _sherpa_onnx import (
|
||||
FeatureExtractorConfig,
|
||||
OfflineCtcFstDecoderConfig,
|
||||
OfflineFeatureExtractorConfig,
|
||||
OfflineModelConfig,
|
||||
OfflineNemoEncDecCtcModelConfig,
|
||||
OfflineParaformerModelConfig,
|
||||
@@ -51,6 +51,7 @@ class OfflineRecognizer(object):
|
||||
blank_penalty: float = 0.0,
|
||||
debug: bool = False,
|
||||
provider: str = "cpu",
|
||||
model_type: str = "transducer",
|
||||
):
|
||||
"""
|
||||
Please refer to
|
||||
@@ -106,10 +107,10 @@ class OfflineRecognizer(object):
|
||||
num_threads=num_threads,
|
||||
debug=debug,
|
||||
provider=provider,
|
||||
model_type="transducer",
|
||||
model_type=model_type,
|
||||
)
|
||||
|
||||
feat_config = OfflineFeatureExtractorConfig(
|
||||
feat_config = FeatureExtractorConfig(
|
||||
sampling_rate=sample_rate,
|
||||
feature_dim=feature_dim,
|
||||
)
|
||||
@@ -182,7 +183,7 @@ class OfflineRecognizer(object):
|
||||
model_type="paraformer",
|
||||
)
|
||||
|
||||
feat_config = OfflineFeatureExtractorConfig(
|
||||
feat_config = FeatureExtractorConfig(
|
||||
sampling_rate=sample_rate,
|
||||
feature_dim=feature_dim,
|
||||
)
|
||||
@@ -246,7 +247,7 @@ class OfflineRecognizer(object):
|
||||
model_type="nemo_ctc",
|
||||
)
|
||||
|
||||
feat_config = OfflineFeatureExtractorConfig(
|
||||
feat_config = FeatureExtractorConfig(
|
||||
sampling_rate=sample_rate,
|
||||
feature_dim=feature_dim,
|
||||
)
|
||||
@@ -326,7 +327,7 @@ class OfflineRecognizer(object):
|
||||
model_type="whisper",
|
||||
)
|
||||
|
||||
feat_config = OfflineFeatureExtractorConfig(
|
||||
feat_config = FeatureExtractorConfig(
|
||||
sampling_rate=16000,
|
||||
feature_dim=80,
|
||||
)
|
||||
@@ -389,7 +390,7 @@ class OfflineRecognizer(object):
|
||||
model_type="tdnn",
|
||||
)
|
||||
|
||||
feat_config = OfflineFeatureExtractorConfig(
|
||||
feat_config = FeatureExtractorConfig(
|
||||
sampling_rate=sample_rate,
|
||||
feature_dim=feature_dim,
|
||||
)
|
||||
@@ -453,7 +454,7 @@ class OfflineRecognizer(object):
|
||||
model_type="wenet_ctc",
|
||||
)
|
||||
|
||||
feat_config = OfflineFeatureExtractorConfig(
|
||||
feat_config = FeatureExtractorConfig(
|
||||
sampling_rate=sample_rate,
|
||||
feature_dim=feature_dim,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user