From 84ef8d592af3c08dfc10d5136554f970129a6099 Mon Sep 17 00:00:00 2001 From: Manuinder Sekhon Date: Fri, 20 May 2022 17:32:14 +0530 Subject: [PATCH] add scorer functions in src files --- libc_deepspeech/libc_deepspeech.cpp | 21 +++++++++++++++++++++ libc_deepspeech/libc_deepspeech.h | 14 +++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/libc_deepspeech/libc_deepspeech.cpp b/libc_deepspeech/libc_deepspeech.cpp index a96a7ce..c94766d 100644 --- a/libc_deepspeech/libc_deepspeech.cpp +++ b/libc_deepspeech/libc_deepspeech.cpp @@ -72,3 +72,24 @@ char *speech_to_text(void *model_state, char *buffer, uint64_t buffer_size) return encoded; } + +int enable_external_scorer(void *model_state, char *model_path) +{ + ModelState *ptr = (ModelState *)model_state; + int status = DS_EnableExternalScorer(ptr, model_path); + return status; +} + +int disable_external_scorer(void *model_state) +{ + ModelState *ptr = (ModelState *)model_state; + int status = DS_DisableExternalScorer(ptr); + return status; +} + +int set_scorer_alpha_beta(void *model_state, float alpha, float beta) +{ + ModelState *ptr = (ModelState *)model_state; + int status = DS_SetScorerAlphaBeta(ptr, alpha, beta); + return status; +} \ No newline at end of file diff --git a/libc_deepspeech/libc_deepspeech.h b/libc_deepspeech/libc_deepspeech.h index b2db290..8debcf2 100644 --- a/libc_deepspeech/libc_deepspeech.h +++ b/libc_deepspeech/libc_deepspeech.h @@ -28,7 +28,19 @@ extern "C" // Returns json output from speech to text engine. EXPORTED char *speech_to_text(void *model_state, char *buffer, uint64_t buffer_size); -// Closing bracket for extern "C" + // Enable decoding using external scorer. Returns zero on success, non-zero on failure. + EXPORTED int enable_external_scorer(void *model_state, char *scorer_file_path); + + // Disable decoding using external scorer. Returns zero on success, non-zero on failure. + EXPORTED int disable_external_scorer(void *model_state); + + // Set hyperparameters alpha and beta of the external scorer. Returns zero on success, non-zero on failure. + // @param alpha: The alpha hyperparameter of the decoder. Language model weight. + // @param beta: The beta hyperparameter of the decoder. Word insertion weight. + EXPORTED int set_scorer_alpha_beta(void *model_state, float alpha, float beta); + + + // Closing bracket for extern "C" #ifdef __cplusplus } #endif \ No newline at end of file