Skip to content

Commit

Permalink
Exposing methods DS_CreateModelFromBuffer and DS_EnableExternalScorer…
Browse files Browse the repository at this point in the history
…FromBuffer
  • Loading branch information
bernardohenz committed Sep 28, 2020
1 parent b85b03c commit 5b11bfb
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
4 changes: 2 additions & 2 deletions doc/BUILDING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ You can now use Bazel to build the main DeepSpeech library, ``libdeepspeech.so``

.. code-block::
bazel build --workspace_status_command="bash native_client/bazel_workspace_status_cmd.sh" --config=monolithic -c opt --copt=-O3 --copt="-D_GLIBCXX_USE_CXX11_ABI=1" --copt=-fvisibility=hidden //native_client:libdeepspeech.so
bazel build --workspace_status_command="bash native_client/bazel_workspace_status_cmd.sh" --config=monolithic -c opt --copt=-O3 --copt="-D_GLIBCXX_USE_CXX11_ABI=0" --copt=-fvisibility=hidden //native_client:libdeepspeech.so
The generated binaries will be saved to ``bazel-bin/native_client/``.

Expand All @@ -87,7 +87,7 @@ Using the example from above you can build the library and that binary at the sa

.. code-block::
bazel build --workspace_status_command="bash native_client/bazel_workspace_status_cmd.sh" --config=monolithic -c opt --copt=-O3 --copt="-D_GLIBCXX_USE_CXX11_ABI=1" --copt=-fvisibility=hidden //native_client:libdeepspeech.so //native_client:generate_scorer_package
bazel build --workspace_status_command="bash native_client/bazel_workspace_status_cmd.sh" --config=monolithic -c opt --copt=-O3 --copt="-D_GLIBCXX_USE_CXX11_ABI=0" --copt=-fvisibility=hidden //native_client:libdeepspeech.so //native_client:generate_scorer_package
The generated binaries will be saved to ``bazel-bin/native_client/``.

Expand Down
4 changes: 2 additions & 2 deletions native_client/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ main(int argc, char **argv)
std::ifstream is_model( model, std::ios::binary );
std::stringstream buffer_model;
buffer_model << is_model.rdbuf();
status = DS_CreateModel_(buffer_model.str(), true, &ctx);
status = DS_CreateModelFromBuffer(buffer_model.str(), &ctx);
}else {
// Keep old method due to backwards compatibility
status = DS_CreateModel(model, &ctx);
Expand All @@ -451,7 +451,7 @@ main(int argc, char **argv)
std::ifstream is_scorer(scorer, std::ios::binary );
std::stringstream buffer_scorer;
buffer_scorer << is_scorer.rdbuf();
status = DS_EnableExternalScorer_(ctx, buffer_scorer.str(), true);
status = DS_EnableExternalScorerFromBuffer(ctx, buffer_scorer.str());
} else {
// Keep old method due to backwards compatibility
status = DS_EnableExternalScorer(ctx, scorer);
Expand Down
14 changes: 14 additions & 0 deletions native_client/deepspeech.cc
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@ DS_CreateModel(const char* aModelPath,
return DS_CreateModel_(aModelPath, false, retval);
}

int
DS_CreateModelFromBuffer(const std::string &aModelBuffer,
ModelState** retval)
{
return DS_CreateModel_(aModelBuffer, true, retval);
}

int
DS_CreateModel_(const std::string &aModelString,
bool init_from_bytes,
Expand Down Expand Up @@ -344,6 +351,13 @@ DS_EnableExternalScorer(ModelState* aCtx,
return DS_EnableExternalScorer_(aCtx, aScorerPath, false);
}

int
DS_EnableExternalScorerFromBuffer(ModelState* aCtx,
const std::string &aScorerBuffer)
{
return DS_EnableExternalScorer_(aCtx, aScorerBuffer, true);
}

int
DS_EnableExternalScorer_(ModelState* aCtx,
const std::string &aScorerString,
Expand Down
25 changes: 25 additions & 0 deletions native_client/deepspeech.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ DEEPSPEECH_EXPORT
int DS_CreateModel(const char* aModelPath,
ModelState** retval);

/**
* @brief An object providing an interface to a trained DeepSpeech model, loaded from buffer.
*
* @param aModelBuffer The buffer containing the content of frozen model graph.
* @param[out] retval a ModelState pointer
*
* @return Zero on success, non-zero on failure.
*/
DEEPSPEECH_EXPORT
int DS_CreateModelFromBuffer(const std::string &aModelBuffer,
ModelState** retval);


/**
* @brief An object providing an interface to a trained DeepSpeech model.
*
Expand Down Expand Up @@ -176,6 +189,18 @@ DEEPSPEECH_EXPORT
int DS_EnableExternalScorer(ModelState* aCtx,
const char* aScorerPath);

/**
* @brief Enable decoding using an external scorer loaded from buffer.
*
* @param aCtx The ModelState pointer for the model being changed.
* @param aScorerBuffer The buffer containing the content of an external-scorer file.
*
* @return Zero on success, non-zero on failure (invalid arguments).
*/
DEEPSPEECH_EXPORT
int DS_EnableExternalScorerFromBuffer(ModelState* aCtx,
const std::string &aScorerBuffer);

/**
* @brief Enable decoding using an external scorer.
*
Expand Down

0 comments on commit 5b11bfb

Please sign in to comment.