Skip to content

Commit

Permalink
feat: addition of blank_penalty config in online_recognizer (#1232)
Browse files Browse the repository at this point in the history
  • Loading branch information
parth-khiera authored Aug 8, 2024
1 parent 8a5f5c1 commit ba4cb61
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions scripts/go/sherpa_onnx.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ type OnlineRecognizerConfig struct {
Rule3MinUtteranceLength float32
HotwordsFile string
HotwordsScore float32
BlankPenalty float32
CtcFstDecoderConfig OnlineCtcFstDecoderConfig
RuleFsts string
RuleFars string
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -421,6 +423,7 @@ type OfflineRecognizerConfig struct {
MaxActivePaths int
HotwordsFile string
HotwordsScore float32
BlankPenalty float32
RuleFsts string
RuleFars string
}
Expand Down Expand Up @@ -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))

Expand Down
2 changes: 2 additions & 0 deletions sherpa-onnx/c-api/c-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
1 change: 1 addition & 0 deletions sherpa-onnx/c-api/c-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ba4cb61

Please sign in to comment.