Merge pull request #2970 from mozilla/enabledecoder-error-handling
Improve error handling for DS_EnableExternalScorer (Fixes #2969)
This commit is contained in:
commit
d36092cd9b
@ -333,11 +333,12 @@ int
|
|||||||
DS_EnableExternalScorer(ModelState* aCtx,
|
DS_EnableExternalScorer(ModelState* aCtx,
|
||||||
const char* aScorerPath)
|
const char* aScorerPath)
|
||||||
{
|
{
|
||||||
aCtx->scorer_.reset(new Scorer());
|
std::unique_ptr<Scorer> scorer(new Scorer());
|
||||||
int err = aCtx->scorer_->init(aScorerPath, aCtx->alphabet_);
|
int err = scorer->init(aScorerPath, aCtx->alphabet_);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
return DS_ERR_INVALID_SCORER;
|
return DS_ERR_INVALID_SCORER;
|
||||||
}
|
}
|
||||||
|
aCtx->scorer_ = std::move(scorer);
|
||||||
return DS_ERR_OK;
|
return DS_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ function Model(aModelPath) {
|
|||||||
const status = rets[0];
|
const status = rets[0];
|
||||||
const impl = rets[1];
|
const impl = rets[1];
|
||||||
if (status !== 0) {
|
if (status !== 0) {
|
||||||
throw "CreateModel failed "+binding.ErrorCodeToErrorMessage(status)+" 0x" + status.toString(16);
|
throw "CreateModel failed with '"+binding.ErrorCodeToErrorMessage(status)+"' (0x" + status.toString(16) + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
this._impl = impl;
|
this._impl = impl;
|
||||||
@ -76,10 +76,13 @@ Model.prototype.sampleRate = function() {
|
|||||||
*
|
*
|
||||||
* @param {string} aScorerPath The path to the external scorer file.
|
* @param {string} aScorerPath The path to the external scorer file.
|
||||||
*
|
*
|
||||||
* @return {number} Zero on success, non-zero on failure (invalid arguments).
|
* @throws on error
|
||||||
*/
|
*/
|
||||||
Model.prototype.enableExternalScorer = function(aScorerPath) {
|
Model.prototype.enableExternalScorer = function(aScorerPath) {
|
||||||
return binding.EnableExternalScorer(this._impl, aScorerPath);
|
const status = binding.EnableExternalScorer(this._impl, aScorerPath);
|
||||||
|
if (status !== 0) {
|
||||||
|
throw "EnableExternalScorer failed with '"+binding.ErrorCodeToErrorMessage(status)+"' (0x" + status.toString(16) + ")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -139,7 +142,7 @@ Model.prototype.createStream = function() {
|
|||||||
const status = rets[0];
|
const status = rets[0];
|
||||||
const ctx = rets[1];
|
const ctx = rets[1];
|
||||||
if (status !== 0) {
|
if (status !== 0) {
|
||||||
throw "CreateStream failed "+binding.ErrorCodeToErrorMessage(status)+" 0x" + status.toString(16);
|
throw "CreateStream failed with '"+binding.ErrorCodeToErrorMessage(status)+"' (0x" + status.toString(16) + ")";
|
||||||
}
|
}
|
||||||
return new Stream(ctx);
|
return new Stream(ctx);
|
||||||
}
|
}
|
||||||
|
@ -81,10 +81,11 @@ class Model(object):
|
|||||||
:param scorer_path: The path to the external scorer file.
|
:param scorer_path: The path to the external scorer file.
|
||||||
:type scorer_path: str
|
:type scorer_path: str
|
||||||
|
|
||||||
:return: Zero on success, non-zero on failure.
|
:throws: RuntimeError on error
|
||||||
:type: int
|
|
||||||
"""
|
"""
|
||||||
return deepspeech.impl.EnableExternalScorer(self._impl, scorer_path)
|
status = deepspeech.impl.EnableExternalScorer(self._impl, scorer_path)
|
||||||
|
if status != 0:
|
||||||
|
raise RuntimeError("EnableExternalScorer failed with '{}' (0x{:X})".format(deepspeech.impl.ErrorCodeToErrorMessage(status),status))
|
||||||
|
|
||||||
def disableExternalScorer(self):
|
def disableExternalScorer(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user