From c402b971d6ccd14e70c55536ce2d165923940044 Mon Sep 17 00:00:00 2001 From: Reuben Morais Date: Mon, 9 Sep 2019 11:33:01 +0200 Subject: [PATCH] Remove unused params and make function names more consistent --- native_client/deepspeech.cc | 33 ++++++++++++++----------------- native_client/deepspeech.h | 31 ++++++++++++----------------- native_client/modelstate.cc | 4 ---- native_client/modelstate.h | 2 -- native_client/tflitemodelstate.cc | 4 +--- native_client/tflitemodelstate.h | 2 -- native_client/tfmodelstate.cc | 4 +--- native_client/tfmodelstate.h | 2 -- 8 files changed, 30 insertions(+), 52 deletions(-) diff --git a/native_client/deepspeech.cc b/native_client/deepspeech.cc index 97883c74..39b661db 100644 --- a/native_client/deepspeech.cc +++ b/native_client/deepspeech.cc @@ -257,8 +257,6 @@ StreamingState::processBatch(const vector& buf, unsigned int n_steps) int DS_CreateModel(const char* aModelPath, - unsigned int aNCep, - unsigned int aNContext, const char* aAlphabetConfigPath, unsigned int aBeamWidth, ModelState** retval) @@ -285,7 +283,7 @@ DS_CreateModel(const char* aModelPath, return DS_ERR_FAIL_CREATE_MODEL; } - int err = model->init(aModelPath, aNCep, aNContext, aAlphabetConfigPath, aBeamWidth); + int err = model->init(aModelPath, aAlphabetConfigPath, aBeamWidth); if (err != DS_ERR_OK) { return err; } @@ -295,14 +293,13 @@ DS_CreateModel(const char* aModelPath, } void -DS_DestroyModel(ModelState* ctx) +DS_FreeModel(ModelState* ctx) { delete ctx; } int DS_EnableDecoderWithLM(ModelState* aCtx, - const char* aAlphabetConfigPath, const char* aLMPath, const char* aTriePath, float aLMAlpha, @@ -320,9 +317,9 @@ DS_EnableDecoderWithLM(ModelState* aCtx, } int -DS_SetupStream(ModelState* aCtx, - unsigned int aSampleRate, - StreamingState** retval) +DS_CreateStream(ModelState* aCtx, + unsigned int aSampleRate, + StreamingState** retval) { *retval = nullptr; @@ -371,7 +368,7 @@ char* DS_FinishStream(StreamingState* aSctx) { char* str = aSctx->finishStream(); - DS_DiscardStream(aSctx); + DS_FreeStream(aSctx); return str; } @@ -379,18 +376,18 @@ Metadata* DS_FinishStreamWithMetadata(StreamingState* aSctx) { Metadata* metadata = aSctx->finishStreamWithMetadata(); - DS_DiscardStream(aSctx); + DS_FreeStream(aSctx); return metadata; } StreamingState* -SetupStreamAndFeedAudioContent(ModelState* aCtx, - const short* aBuffer, - unsigned int aBufferSize, - unsigned int aSampleRate) +CreateStreamAndFeedAudioContent(ModelState* aCtx, + const short* aBuffer, + unsigned int aBufferSize, + unsigned int aSampleRate) { StreamingState* ctx; - int status = DS_SetupStream(aCtx, aSampleRate, &ctx); + int status = DS_CreateStream(aCtx, aSampleRate, &ctx); if (status != DS_ERR_OK) { return nullptr; } @@ -404,7 +401,7 @@ DS_SpeechToText(ModelState* aCtx, unsigned int aBufferSize, unsigned int aSampleRate) { - StreamingState* ctx = SetupStreamAndFeedAudioContent(aCtx, aBuffer, aBufferSize, aSampleRate); + StreamingState* ctx = CreateStreamAndFeedAudioContent(aCtx, aBuffer, aBufferSize, aSampleRate); return DS_FinishStream(ctx); } @@ -414,12 +411,12 @@ DS_SpeechToTextWithMetadata(ModelState* aCtx, unsigned int aBufferSize, unsigned int aSampleRate) { - StreamingState* ctx = SetupStreamAndFeedAudioContent(aCtx, aBuffer, aBufferSize, aSampleRate); + StreamingState* ctx = CreateStreamAndFeedAudioContent(aCtx, aBuffer, aBufferSize, aSampleRate); return DS_FinishStreamWithMetadata(ctx); } void -DS_DiscardStream(StreamingState* aSctx) +DS_FreeStream(StreamingState* aSctx) { delete aSctx; } diff --git a/native_client/deepspeech.h b/native_client/deepspeech.h index 9e459440..cf0c4508 100644 --- a/native_client/deepspeech.h +++ b/native_client/deepspeech.h @@ -63,8 +63,6 @@ enum DeepSpeech_Error_Codes * @brief An object providing an interface to a trained DeepSpeech model. * * @param aModelPath The path to the frozen model graph. - * @param aNCep The number of cepstrum the model was trained with. - * @param aNContext The context window the model was trained with. * @param aAlphabetConfigPath The path to the configuration file specifying * the alphabet used by the network. See alphabet.h. * @param aBeamWidth The beam width used by the decoder. A larger beam @@ -76,8 +74,6 @@ enum DeepSpeech_Error_Codes */ DEEPSPEECH_EXPORT int DS_CreateModel(const char* aModelPath, - unsigned int aNCep, - unsigned int aNContext, const char* aAlphabetConfigPath, unsigned int aBeamWidth, ModelState** retval); @@ -86,7 +82,7 @@ int DS_CreateModel(const char* aModelPath, * @brief Frees associated resources and destroys model object. */ DEEPSPEECH_EXPORT -void DS_DestroyModel(ModelState* ctx); +void DS_FreeModel(ModelState* ctx); /** * @brief Enable decoding using beam scoring with a KenLM language model. @@ -106,7 +102,6 @@ void DS_DestroyModel(ModelState* ctx); */ DEEPSPEECH_EXPORT int DS_EnableDecoderWithLM(ModelState* aCtx, - const char* aAlphabetConfigPath, const char* aLMPath, const char* aTriePath, float aLMAlpha, @@ -145,9 +140,9 @@ char* DS_SpeechToText(ModelState* aCtx, */ DEEPSPEECH_EXPORT Metadata* DS_SpeechToTextWithMetadata(ModelState* aCtx, - const short* aBuffer, - unsigned int aBufferSize, - unsigned int aSampleRate); + const short* aBuffer, + unsigned int aBufferSize, + unsigned int aSampleRate); /** * @brief Create a new streaming inference state. The streaming state returned @@ -162,14 +157,14 @@ Metadata* DS_SpeechToTextWithMetadata(ModelState* aCtx, * @return Zero for success, non-zero on failure. */ DEEPSPEECH_EXPORT -int DS_SetupStream(ModelState* aCtx, - unsigned int aSampleRate, - StreamingState** retval); +int DS_CreateStream(ModelState* aCtx, + unsigned int aSampleRate, + StreamingState** retval); /** * @brief Feed audio samples to an ongoing streaming inference. * - * @param aSctx A streaming state pointer returned by {@link DS_SetupStream()}. + * @param aSctx A streaming state pointer returned by {@link DS_CreateStream()}. * @param aBuffer An array of 16-bit, mono raw audio samples at the * appropriate sample rate. * @param aBufferSize The number of samples in @p aBuffer. @@ -185,7 +180,7 @@ void DS_FeedAudioContent(StreamingState* aSctx, * currently capable of streaming, so it always starts from the beginning * of the audio. * - * @param aSctx A streaming state pointer returned by {@link DS_SetupStream()}. + * @param aSctx A streaming state pointer returned by {@link DS_CreateStream()}. * * @return The STT intermediate result. The user is responsible for freeing the * string using {@link DS_FreeString()}. @@ -197,7 +192,7 @@ char* DS_IntermediateDecode(StreamingState* aSctx); * @brief Signal the end of an audio signal to an ongoing streaming * inference, returns the STT result over the whole audio signal. * - * @param aSctx A streaming state pointer returned by {@link DS_SetupStream()}. + * @param aSctx A streaming state pointer returned by {@link DS_CreateStream()}. * * @return The STT result. The user is responsible for freeing the string using * {@link DS_FreeString()}. @@ -211,7 +206,7 @@ char* DS_FinishStream(StreamingState* aSctx); * @brief Signal the end of an audio signal to an ongoing streaming * inference, returns per-letter metadata. * - * @param aSctx A streaming state pointer returned by {@link DS_SetupStream()}. + * @param aSctx A streaming state pointer returned by {@link DS_CreateStream()}. * * @return Outputs a struct of individual letters along with their timing information. * The user is responsible for freeing Metadata by calling {@link DS_FreeMetadata()}. Returns NULL on error. @@ -226,12 +221,12 @@ Metadata* DS_FinishStreamWithMetadata(StreamingState* aSctx); * can be used if you no longer need the result of an ongoing streaming * inference and don't want to perform a costly decode operation. * - * @param aSctx A streaming state pointer returned by {@link DS_SetupStream()}. + * @param aSctx A streaming state pointer returned by {@link DS_CreateStream()}. * * @note This method will free the state pointer (@p aSctx). */ DEEPSPEECH_EXPORT -void DS_DiscardStream(StreamingState* aSctx); +void DS_FreeStream(StreamingState* aSctx); /** * @brief Free memory allocated for metadata information. diff --git a/native_client/modelstate.cc b/native_client/modelstate.cc index bd80367a..6bf346a0 100644 --- a/native_client/modelstate.cc +++ b/native_client/modelstate.cc @@ -25,13 +25,9 @@ ModelState::~ModelState() int ModelState::init(const char* model_path, - unsigned int n_features, - unsigned int n_context, const char* alphabet_path, unsigned int beam_width) { - n_features_ = n_features; - n_context_ = n_context; if (alphabet_.init(alphabet_path)) { return DS_ERR_INVALID_ALPHABET; } diff --git a/native_client/modelstate.h b/native_client/modelstate.h index 4b60f838..645e0f2a 100644 --- a/native_client/modelstate.h +++ b/native_client/modelstate.h @@ -35,8 +35,6 @@ struct ModelState { virtual ~ModelState(); virtual int init(const char* model_path, - unsigned int n_features, - unsigned int n_context, const char* alphabet_path, unsigned int beam_width); diff --git a/native_client/tflitemodelstate.cc b/native_client/tflitemodelstate.cc index 026b333d..9c7f13de 100644 --- a/native_client/tflitemodelstate.cc +++ b/native_client/tflitemodelstate.cc @@ -89,12 +89,10 @@ TFLiteModelState::~TFLiteModelState() int TFLiteModelState::init(const char* model_path, - unsigned int n_features, - unsigned int n_context, const char* alphabet_path, unsigned int beam_width) { - int err = ModelState::init(model_path, n_features, n_context, alphabet_path, beam_width); + int err = ModelState::init(model_path, alphabet_path, beam_width); if (err != DS_ERR_OK) { return err; } diff --git a/native_client/tflitemodelstate.h b/native_client/tflitemodelstate.h index 3a6d4971..cd876895 100644 --- a/native_client/tflitemodelstate.h +++ b/native_client/tflitemodelstate.h @@ -31,8 +31,6 @@ struct TFLiteModelState : public ModelState virtual ~TFLiteModelState(); virtual int init(const char* model_path, - unsigned int n_features, - unsigned int n_context, const char* alphabet_path, unsigned int beam_width) override; diff --git a/native_client/tfmodelstate.cc b/native_client/tfmodelstate.cc index 2f26b142..49570fb6 100644 --- a/native_client/tfmodelstate.cc +++ b/native_client/tfmodelstate.cc @@ -25,12 +25,10 @@ TFModelState::~TFModelState() int TFModelState::init(const char* model_path, - unsigned int n_features, - unsigned int n_context, const char* alphabet_path, unsigned int beam_width) { - int err = ModelState::init(model_path, n_features, n_context, alphabet_path, beam_width); + int err = ModelState::init(model_path, alphabet_path, beam_width); if (err != DS_ERR_OK) { return err; } diff --git a/native_client/tfmodelstate.h b/native_client/tfmodelstate.h index 0ef7dcfe..39acbc59 100644 --- a/native_client/tfmodelstate.h +++ b/native_client/tfmodelstate.h @@ -19,8 +19,6 @@ struct TFModelState : public ModelState virtual ~TFModelState(); virtual int init(const char* model_path, - unsigned int n_features, - unsigned int n_context, const char* alphabet_path, unsigned int beam_width) override;