From 4db20b3cd648bb2d33b18e9a0018b30f724ec4b1 Mon Sep 17 00:00:00 2001 From: Reuben Morais Date: Mon, 18 May 2020 17:28:02 +0200 Subject: [PATCH] Expose DS error codes in ds_ctcdecoder package --- native_client/ctcdecode/__init__.py | 6 ++++++ native_client/ctcdecode/swigwrapper.i | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/native_client/ctcdecode/__init__.py b/native_client/ctcdecode/__init__.py index e0282ca5..faacea9e 100644 --- a/native_client/ctcdecode/__init__.py +++ b/native_client/ctcdecode/__init__.py @@ -5,6 +5,12 @@ from .swigwrapper import Alphabet __version__ = swigwrapper.__version__ +# Hack: import error codes by matching on their names, as SWIG unfortunately +# does not support binding enums to Python in a scoped manner yet. +for symbol in dir(swigwrapper): + if symbol.startswith('DS_ERR_'): + globals()[symbol] = getattr(swigwrapper, symbol) + class Scorer(swigwrapper.Scorer): """Wrapper for Scorer. diff --git a/native_client/ctcdecode/swigwrapper.i b/native_client/ctcdecode/swigwrapper.i index fd0f4f08..64ed5f5a 100644 --- a/native_client/ctcdecode/swigwrapper.i +++ b/native_client/ctcdecode/swigwrapper.i @@ -41,3 +41,9 @@ namespace std { %template(IntVector) std::vector; %template(OutputVector) std::vector; %template(OutputVectorVector) std::vector>; + +// Import only the error code enum definitions from deepspeech.h +%ignore ""; +%rename("%s", regexmatch$name="DS_ERR_") ""; +%rename("%s", regexmatch$name="DeepSpeech_Error_Codes") ""; +%include "../deepspeech.h"