Code refactoring (#74)
* Don't reset model state and feature extractor on endpointing * support passing decoding_method from commandline * Add modified_beam_search to Python API * fix C API example * Fix style issues
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "sherpa-onnx/csrc/display.h"
|
||||
#include "sherpa-onnx/csrc/online-recognizer.h"
|
||||
|
||||
struct SherpaOnnxOnlineRecognizer {
|
||||
@@ -21,6 +22,10 @@ struct SherpaOnnxOnlineStream {
|
||||
: impl(std::move(p)) {}
|
||||
};
|
||||
|
||||
struct SherpaOnnxDisplay {
|
||||
std::unique_ptr<sherpa_onnx::Display> impl;
|
||||
};
|
||||
|
||||
SherpaOnnxOnlineRecognizer *CreateOnlineRecognizer(
|
||||
const SherpaOnnxOnlineRecognizerConfig *config) {
|
||||
sherpa_onnx::OnlineRecognizerConfig recognizer_config;
|
||||
@@ -37,6 +42,9 @@ SherpaOnnxOnlineRecognizer *CreateOnlineRecognizer(
|
||||
recognizer_config.model_config.num_threads = config->model_config.num_threads;
|
||||
recognizer_config.model_config.debug = config->model_config.debug;
|
||||
|
||||
recognizer_config.decoding_method = config->decoding_method;
|
||||
recognizer_config.max_active_paths = config->max_active_paths;
|
||||
|
||||
recognizer_config.enable_endpoint = config->enable_endpoint;
|
||||
|
||||
recognizer_config.endpoint_config.rule1.min_trailing_silence =
|
||||
@@ -124,3 +132,15 @@ int32_t IsEndpoint(SherpaOnnxOnlineRecognizer *recognizer,
|
||||
SherpaOnnxOnlineStream *stream) {
|
||||
return recognizer->impl->IsEndpoint(stream->impl.get());
|
||||
}
|
||||
|
||||
SherpaOnnxDisplay *CreateDisplay(int32_t max_word_per_line) {
|
||||
SherpaOnnxDisplay *ans = new SherpaOnnxDisplay;
|
||||
ans->impl = std::make_unique<sherpa_onnx::Display>(max_word_per_line);
|
||||
return ans;
|
||||
}
|
||||
|
||||
void DestroyDisplay(SherpaOnnxDisplay *display) { delete display; }
|
||||
|
||||
void SherpaOnnxPrint(SherpaOnnxDisplay *display, int32_t idx, const char *s) {
|
||||
display->impl->Print(idx, s);
|
||||
}
|
||||
|
||||
@@ -48,6 +48,13 @@ typedef struct SherpaOnnxOnlineRecognizerConfig {
|
||||
SherpaOnnxFeatureConfig feat_config;
|
||||
SherpaOnnxOnlineTransducerModelConfig model_config;
|
||||
|
||||
/// Possible values are: greedy_search, modified_beam_search
|
||||
const char *decoding_method;
|
||||
|
||||
/// Used only when decoding_method is modified_beam_search
|
||||
/// Example value: 4
|
||||
int32_t max_active_paths;
|
||||
|
||||
/// 0 to disable endpoint detection.
|
||||
/// A non-zero value to enable endpoint detection.
|
||||
int32_t enable_endpoint;
|
||||
@@ -187,6 +194,18 @@ void InputFinished(SherpaOnnxOnlineStream *stream);
|
||||
int32_t IsEndpoint(SherpaOnnxOnlineRecognizer *recognizer,
|
||||
SherpaOnnxOnlineStream *stream);
|
||||
|
||||
// for displaying results on Linux/macOS.
|
||||
typedef struct SherpaOnnxDisplay SherpaOnnxDisplay;
|
||||
|
||||
/// Create a display object. Must be freed using DestroyDisplay to avoid
|
||||
/// memory leak.
|
||||
SherpaOnnxDisplay *CreateDisplay(int32_t max_word_per_line);
|
||||
|
||||
void DestroyDisplay(SherpaOnnxDisplay *display);
|
||||
|
||||
/// Print the result.
|
||||
void SherpaOnnxPrint(SherpaOnnxDisplay *display, int32_t idx, const char *s);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user