Remove unused params and make function names more consistent

This commit is contained in:
Reuben Morais 2019-09-09 11:33:01 +02:00
parent 896ac9d6c7
commit c402b971d6
8 changed files with 30 additions and 52 deletions

View File

@ -257,8 +257,6 @@ StreamingState::processBatch(const vector<float>& buf, unsigned int n_steps)
int int
DS_CreateModel(const char* aModelPath, DS_CreateModel(const char* aModelPath,
unsigned int aNCep,
unsigned int aNContext,
const char* aAlphabetConfigPath, const char* aAlphabetConfigPath,
unsigned int aBeamWidth, unsigned int aBeamWidth,
ModelState** retval) ModelState** retval)
@ -285,7 +283,7 @@ DS_CreateModel(const char* aModelPath,
return DS_ERR_FAIL_CREATE_MODEL; 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) { if (err != DS_ERR_OK) {
return err; return err;
} }
@ -295,14 +293,13 @@ DS_CreateModel(const char* aModelPath,
} }
void void
DS_DestroyModel(ModelState* ctx) DS_FreeModel(ModelState* ctx)
{ {
delete ctx; delete ctx;
} }
int int
DS_EnableDecoderWithLM(ModelState* aCtx, DS_EnableDecoderWithLM(ModelState* aCtx,
const char* aAlphabetConfigPath,
const char* aLMPath, const char* aLMPath,
const char* aTriePath, const char* aTriePath,
float aLMAlpha, float aLMAlpha,
@ -320,9 +317,9 @@ DS_EnableDecoderWithLM(ModelState* aCtx,
} }
int int
DS_SetupStream(ModelState* aCtx, DS_CreateStream(ModelState* aCtx,
unsigned int aSampleRate, unsigned int aSampleRate,
StreamingState** retval) StreamingState** retval)
{ {
*retval = nullptr; *retval = nullptr;
@ -371,7 +368,7 @@ char*
DS_FinishStream(StreamingState* aSctx) DS_FinishStream(StreamingState* aSctx)
{ {
char* str = aSctx->finishStream(); char* str = aSctx->finishStream();
DS_DiscardStream(aSctx); DS_FreeStream(aSctx);
return str; return str;
} }
@ -379,18 +376,18 @@ Metadata*
DS_FinishStreamWithMetadata(StreamingState* aSctx) DS_FinishStreamWithMetadata(StreamingState* aSctx)
{ {
Metadata* metadata = aSctx->finishStreamWithMetadata(); Metadata* metadata = aSctx->finishStreamWithMetadata();
DS_DiscardStream(aSctx); DS_FreeStream(aSctx);
return metadata; return metadata;
} }
StreamingState* StreamingState*
SetupStreamAndFeedAudioContent(ModelState* aCtx, CreateStreamAndFeedAudioContent(ModelState* aCtx,
const short* aBuffer, const short* aBuffer,
unsigned int aBufferSize, unsigned int aBufferSize,
unsigned int aSampleRate) unsigned int aSampleRate)
{ {
StreamingState* ctx; StreamingState* ctx;
int status = DS_SetupStream(aCtx, aSampleRate, &ctx); int status = DS_CreateStream(aCtx, aSampleRate, &ctx);
if (status != DS_ERR_OK) { if (status != DS_ERR_OK) {
return nullptr; return nullptr;
} }
@ -404,7 +401,7 @@ DS_SpeechToText(ModelState* aCtx,
unsigned int aBufferSize, unsigned int aBufferSize,
unsigned int aSampleRate) unsigned int aSampleRate)
{ {
StreamingState* ctx = SetupStreamAndFeedAudioContent(aCtx, aBuffer, aBufferSize, aSampleRate); StreamingState* ctx = CreateStreamAndFeedAudioContent(aCtx, aBuffer, aBufferSize, aSampleRate);
return DS_FinishStream(ctx); return DS_FinishStream(ctx);
} }
@ -414,12 +411,12 @@ DS_SpeechToTextWithMetadata(ModelState* aCtx,
unsigned int aBufferSize, unsigned int aBufferSize,
unsigned int aSampleRate) unsigned int aSampleRate)
{ {
StreamingState* ctx = SetupStreamAndFeedAudioContent(aCtx, aBuffer, aBufferSize, aSampleRate); StreamingState* ctx = CreateStreamAndFeedAudioContent(aCtx, aBuffer, aBufferSize, aSampleRate);
return DS_FinishStreamWithMetadata(ctx); return DS_FinishStreamWithMetadata(ctx);
} }
void void
DS_DiscardStream(StreamingState* aSctx) DS_FreeStream(StreamingState* aSctx)
{ {
delete aSctx; delete aSctx;
} }

View File

@ -63,8 +63,6 @@ enum DeepSpeech_Error_Codes
* @brief An object providing an interface to a trained DeepSpeech model. * @brief An object providing an interface to a trained DeepSpeech model.
* *
* @param aModelPath The path to the frozen model graph. * @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 * @param aAlphabetConfigPath The path to the configuration file specifying
* the alphabet used by the network. See alphabet.h. * the alphabet used by the network. See alphabet.h.
* @param aBeamWidth The beam width used by the decoder. A larger beam * @param aBeamWidth The beam width used by the decoder. A larger beam
@ -76,8 +74,6 @@ enum DeepSpeech_Error_Codes
*/ */
DEEPSPEECH_EXPORT DEEPSPEECH_EXPORT
int DS_CreateModel(const char* aModelPath, int DS_CreateModel(const char* aModelPath,
unsigned int aNCep,
unsigned int aNContext,
const char* aAlphabetConfigPath, const char* aAlphabetConfigPath,
unsigned int aBeamWidth, unsigned int aBeamWidth,
ModelState** retval); ModelState** retval);
@ -86,7 +82,7 @@ int DS_CreateModel(const char* aModelPath,
* @brief Frees associated resources and destroys model object. * @brief Frees associated resources and destroys model object.
*/ */
DEEPSPEECH_EXPORT DEEPSPEECH_EXPORT
void DS_DestroyModel(ModelState* ctx); void DS_FreeModel(ModelState* ctx);
/** /**
* @brief Enable decoding using beam scoring with a KenLM language model. * @brief Enable decoding using beam scoring with a KenLM language model.
@ -106,7 +102,6 @@ void DS_DestroyModel(ModelState* ctx);
*/ */
DEEPSPEECH_EXPORT DEEPSPEECH_EXPORT
int DS_EnableDecoderWithLM(ModelState* aCtx, int DS_EnableDecoderWithLM(ModelState* aCtx,
const char* aAlphabetConfigPath,
const char* aLMPath, const char* aLMPath,
const char* aTriePath, const char* aTriePath,
float aLMAlpha, float aLMAlpha,
@ -145,9 +140,9 @@ char* DS_SpeechToText(ModelState* aCtx,
*/ */
DEEPSPEECH_EXPORT DEEPSPEECH_EXPORT
Metadata* DS_SpeechToTextWithMetadata(ModelState* aCtx, Metadata* DS_SpeechToTextWithMetadata(ModelState* aCtx,
const short* aBuffer, const short* aBuffer,
unsigned int aBufferSize, unsigned int aBufferSize,
unsigned int aSampleRate); unsigned int aSampleRate);
/** /**
* @brief Create a new streaming inference state. The streaming state returned * @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. * @return Zero for success, non-zero on failure.
*/ */
DEEPSPEECH_EXPORT DEEPSPEECH_EXPORT
int DS_SetupStream(ModelState* aCtx, int DS_CreateStream(ModelState* aCtx,
unsigned int aSampleRate, unsigned int aSampleRate,
StreamingState** retval); StreamingState** retval);
/** /**
* @brief Feed audio samples to an ongoing streaming inference. * @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 * @param aBuffer An array of 16-bit, mono raw audio samples at the
* appropriate sample rate. * appropriate sample rate.
* @param aBufferSize The number of samples in @p aBuffer. * @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 * currently capable of streaming, so it always starts from the beginning
* of the audio. * 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 * @return The STT intermediate result. The user is responsible for freeing the
* string using {@link DS_FreeString()}. * 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 * @brief Signal the end of an audio signal to an ongoing streaming
* inference, returns the STT result over the whole audio signal. * 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 * @return The STT result. The user is responsible for freeing the string using
* {@link DS_FreeString()}. * {@link DS_FreeString()}.
@ -211,7 +206,7 @@ char* DS_FinishStream(StreamingState* aSctx);
* @brief Signal the end of an audio signal to an ongoing streaming * @brief Signal the end of an audio signal to an ongoing streaming
* inference, returns per-letter metadata. * 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. * @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. * 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 * 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. * 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). * @note This method will free the state pointer (@p aSctx).
*/ */
DEEPSPEECH_EXPORT DEEPSPEECH_EXPORT
void DS_DiscardStream(StreamingState* aSctx); void DS_FreeStream(StreamingState* aSctx);
/** /**
* @brief Free memory allocated for metadata information. * @brief Free memory allocated for metadata information.

View File

@ -25,13 +25,9 @@ ModelState::~ModelState()
int int
ModelState::init(const char* model_path, ModelState::init(const char* model_path,
unsigned int n_features,
unsigned int n_context,
const char* alphabet_path, const char* alphabet_path,
unsigned int beam_width) unsigned int beam_width)
{ {
n_features_ = n_features;
n_context_ = n_context;
if (alphabet_.init(alphabet_path)) { if (alphabet_.init(alphabet_path)) {
return DS_ERR_INVALID_ALPHABET; return DS_ERR_INVALID_ALPHABET;
} }

View File

@ -35,8 +35,6 @@ struct ModelState {
virtual ~ModelState(); virtual ~ModelState();
virtual int init(const char* model_path, virtual int init(const char* model_path,
unsigned int n_features,
unsigned int n_context,
const char* alphabet_path, const char* alphabet_path,
unsigned int beam_width); unsigned int beam_width);

View File

@ -89,12 +89,10 @@ TFLiteModelState::~TFLiteModelState()
int int
TFLiteModelState::init(const char* model_path, TFLiteModelState::init(const char* model_path,
unsigned int n_features,
unsigned int n_context,
const char* alphabet_path, const char* alphabet_path,
unsigned int beam_width) 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) { if (err != DS_ERR_OK) {
return err; return err;
} }

View File

@ -31,8 +31,6 @@ struct TFLiteModelState : public ModelState
virtual ~TFLiteModelState(); virtual ~TFLiteModelState();
virtual int init(const char* model_path, virtual int init(const char* model_path,
unsigned int n_features,
unsigned int n_context,
const char* alphabet_path, const char* alphabet_path,
unsigned int beam_width) override; unsigned int beam_width) override;

View File

@ -25,12 +25,10 @@ TFModelState::~TFModelState()
int int
TFModelState::init(const char* model_path, TFModelState::init(const char* model_path,
unsigned int n_features,
unsigned int n_context,
const char* alphabet_path, const char* alphabet_path,
unsigned int beam_width) 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) { if (err != DS_ERR_OK) {
return err; return err;
} }

View File

@ -19,8 +19,6 @@ struct TFModelState : public ModelState
virtual ~TFModelState(); virtual ~TFModelState();
virtual int init(const char* model_path, virtual int init(const char* model_path,
unsigned int n_features,
unsigned int n_context,
const char* alphabet_path, const char* alphabet_path,
unsigned int beam_width) override; unsigned int beam_width) override;