From ba4cb6169f29efa24c7eef7c3c17897c393c67b3 Mon Sep 17 00:00:00 2001 From: Parth Khiera <83587266+parth-khiera@users.noreply.github.com> Date: Thu, 8 Aug 2024 06:40:17 +0530 Subject: [PATCH] feat: addition of blank_penalty config in online_recognizer (#1232) --- scripts/go/sherpa_onnx.go | 5 +++++ sherpa-onnx/c-api/c-api.cc | 2 ++ sherpa-onnx/c-api/c-api.h | 1 + 3 files changed, 8 insertions(+) diff --git a/scripts/go/sherpa_onnx.go b/scripts/go/sherpa_onnx.go index 0422b3bad..d7d794341 100644 --- a/scripts/go/sherpa_onnx.go +++ b/scripts/go/sherpa_onnx.go @@ -129,6 +129,7 @@ type OnlineRecognizerConfig struct { Rule3MinUtteranceLength float32 HotwordsFile string HotwordsScore float32 + BlankPenalty float32 CtcFstDecoderConfig OnlineCtcFstDecoderConfig RuleFsts string RuleFars string @@ -212,6 +213,7 @@ func NewOnlineRecognizer(config *OnlineRecognizerConfig) *OnlineRecognizer { defer C.free(unsafe.Pointer(c.hotwords_file)) c.hotwords_score = C.float(config.HotwordsScore) + c.blank_penalty = C.float(config.BlankPenalty) c.rule_fsts = C.CString(config.RuleFsts) defer C.free(unsafe.Pointer(c.rule_fsts)) @@ -421,6 +423,7 @@ type OfflineRecognizerConfig struct { MaxActivePaths int HotwordsFile string HotwordsScore float32 + BlankPenalty float32 RuleFsts string RuleFars string } @@ -530,6 +533,8 @@ func NewOfflineRecognizer(config *OfflineRecognizerConfig) *OfflineRecognizer { c.hotwords_score = C.float(config.HotwordsScore) + c.blank_penalty = C.float(config.BlankPenalty) + c.rule_fsts = C.CString(config.RuleFsts) defer C.free(unsafe.Pointer(c.rule_fsts)) diff --git a/sherpa-onnx/c-api/c-api.cc b/sherpa-onnx/c-api/c-api.cc index f6b253065..75885af00 100644 --- a/sherpa-onnx/c-api/c-api.cc +++ b/sherpa-onnx/c-api/c-api.cc @@ -105,6 +105,8 @@ SherpaOnnxOnlineRecognizer *SherpaOnnxCreateOnlineRecognizer( recognizer_config.hotwords_score = SHERPA_ONNX_OR(config->hotwords_score, 1.5); + recognizer_config.blank_penalty = SHERPA_ONNX_OR(config->blank_penalty, 0.0); + recognizer_config.ctc_fst_decoder_config.graph = SHERPA_ONNX_OR(config->ctc_fst_decoder_config.graph, ""); recognizer_config.ctc_fst_decoder_config.max_active = diff --git a/sherpa-onnx/c-api/c-api.h b/sherpa-onnx/c-api/c-api.h index dd86eee1f..17f3d6efe 100644 --- a/sherpa-onnx/c-api/c-api.h +++ b/sherpa-onnx/c-api/c-api.h @@ -142,6 +142,7 @@ SHERPA_ONNX_API typedef struct SherpaOnnxOnlineRecognizerConfig { /// Bonus score for each token in hotwords. float hotwords_score; + float blank_penalty; SherpaOnnxOnlineCtcFstDecoderConfig ctc_fst_decoder_config; const char *rule_fsts;