Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

Commit 5b11bfb

Browse files
committed
Exposing methods DS_CreateModelFromBuffer and DS_EnableExternalScorerFromBuffer
1 parent b85b03c commit 5b11bfb

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

doc/BUILDING.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ You can now use Bazel to build the main DeepSpeech library, ``libdeepspeech.so``
7373

7474
.. code-block::
7575
76-
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
76+
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
7777
7878
The generated binaries will be saved to ``bazel-bin/native_client/``.
7979

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

8888
.. code-block::
8989
90-
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
90+
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
9191
9292
The generated binaries will be saved to ``bazel-bin/native_client/``.
9393

native_client/client.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ main(int argc, char **argv)
424424
std::ifstream is_model( model, std::ios::binary );
425425
std::stringstream buffer_model;
426426
buffer_model << is_model.rdbuf();
427-
status = DS_CreateModel_(buffer_model.str(), true, &ctx);
427+
status = DS_CreateModelFromBuffer(buffer_model.str(), &ctx);
428428
}else {
429429
// Keep old method due to backwards compatibility
430430
status = DS_CreateModel(model, &ctx);
@@ -451,7 +451,7 @@ main(int argc, char **argv)
451451
std::ifstream is_scorer(scorer, std::ios::binary );
452452
std::stringstream buffer_scorer;
453453
buffer_scorer << is_scorer.rdbuf();
454-
status = DS_EnableExternalScorer_(ctx, buffer_scorer.str(), true);
454+
status = DS_EnableExternalScorerFromBuffer(ctx, buffer_scorer.str());
455455
} else {
456456
// Keep old method due to backwards compatibility
457457
status = DS_EnableExternalScorer(ctx, scorer);

native_client/deepspeech.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,13 @@ DS_CreateModel(const char* aModelPath,
269269
return DS_CreateModel_(aModelPath, false, retval);
270270
}
271271

272+
int
273+
DS_CreateModelFromBuffer(const std::string &aModelBuffer,
274+
ModelState** retval)
275+
{
276+
return DS_CreateModel_(aModelBuffer, true, retval);
277+
}
278+
272279
int
273280
DS_CreateModel_(const std::string &aModelString,
274281
bool init_from_bytes,
@@ -344,6 +351,13 @@ DS_EnableExternalScorer(ModelState* aCtx,
344351
return DS_EnableExternalScorer_(aCtx, aScorerPath, false);
345352
}
346353

354+
int
355+
DS_EnableExternalScorerFromBuffer(ModelState* aCtx,
356+
const std::string &aScorerBuffer)
357+
{
358+
return DS_EnableExternalScorer_(aCtx, aScorerBuffer, true);
359+
}
360+
347361
int
348362
DS_EnableExternalScorer_(ModelState* aCtx,
349363
const std::string &aScorerString,

native_client/deepspeech.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ DEEPSPEECH_EXPORT
109109
int DS_CreateModel(const char* aModelPath,
110110
ModelState** retval);
111111

112+
/**
113+
* @brief An object providing an interface to a trained DeepSpeech model, loaded from buffer.
114+
*
115+
* @param aModelBuffer The buffer containing the content of frozen model graph.
116+
* @param[out] retval a ModelState pointer
117+
*
118+
* @return Zero on success, non-zero on failure.
119+
*/
120+
DEEPSPEECH_EXPORT
121+
int DS_CreateModelFromBuffer(const std::string &aModelBuffer,
122+
ModelState** retval);
123+
124+
112125
/**
113126
* @brief An object providing an interface to a trained DeepSpeech model.
114127
*
@@ -176,6 +189,18 @@ DEEPSPEECH_EXPORT
176189
int DS_EnableExternalScorer(ModelState* aCtx,
177190
const char* aScorerPath);
178191

192+
/**
193+
* @brief Enable decoding using an external scorer loaded from buffer.
194+
*
195+
* @param aCtx The ModelState pointer for the model being changed.
196+
* @param aScorerBuffer The buffer containing the content of an external-scorer file.
197+
*
198+
* @return Zero on success, non-zero on failure (invalid arguments).
199+
*/
200+
DEEPSPEECH_EXPORT
201+
int DS_EnableExternalScorerFromBuffer(ModelState* aCtx,
202+
const std::string &aScorerBuffer);
203+
179204
/**
180205
* @brief Enable decoding using an external scorer.
181206
*

0 commit comments

Comments
 (0)