From 417b8e4fe3238fbc33570c8b0600ca23c88aedca Mon Sep 17 00:00:00 2001 From: Reuben Morais Date: Tue, 7 Jul 2020 15:18:23 +0200 Subject: [PATCH 1/3] Fix style inconsistencies in Java bindings --- doc/BUILDING.rst | 4 ++-- native_client/java/jni/deepspeech.i | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/BUILDING.rst b/doc/BUILDING.rst index 3c20cb29..16c5734a 100644 --- a/doc/BUILDING.rst +++ b/doc/BUILDING.rst @@ -198,13 +198,13 @@ You can build the ``libdeepspeech.so`` using (ARMv7): .. code-block:: - bazel build --workspace_status_command="bash native_client/bazel_workspace_status_cmd.sh" --config=monolithic --config=android --config=android_arm --define=runtime=tflite --action_env ANDROID_NDK_API_LEVEL=21 --cxxopt=-std=c++11 --copt=-D_GLIBCXX_USE_C99 //native_client:libdeepspeech.so + bazel build --workspace_status_command="bash native_client/bazel_workspace_status_cmd.sh" --config=monolithic --config=android --config=android_arm --define=runtime=tflite --action_env ANDROID_NDK_API_LEVEL=21 --cxxopt=-std=c++14 --copt=-D_GLIBCXX_USE_C99 //native_client:libdeepspeech.so Or (ARM64): .. code-block:: - bazel build --workspace_status_command="bash native_client/bazel_workspace_status_cmd.sh" --config=monolithic --config=android --config=android_arm64 --define=runtime=tflite --action_env ANDROID_NDK_API_LEVEL=21 --cxxopt=-std=c++11 --copt=-D_GLIBCXX_USE_C99 //native_client:libdeepspeech.so + bazel build --workspace_status_command="bash native_client/bazel_workspace_status_cmd.sh" --config=monolithic --config=android --config=android_arm64 --define=runtime=tflite --action_env ANDROID_NDK_API_LEVEL=21 --cxxopt=-std=c++14 --copt=-D_GLIBCXX_USE_C99 //native_client:libdeepspeech.so Building ``libdeepspeech.aar`` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/native_client/java/jni/deepspeech.i b/native_client/java/jni/deepspeech.i index c028714c..cd5a97a5 100644 --- a/native_client/java/jni/deepspeech.i +++ b/native_client/java/jni/deepspeech.i @@ -62,4 +62,13 @@ %rename ("%(strip:[DS_])s") ""; +// make struct members camel case to suit Java conventions +%rename ("%(camelcase)s", %$ismember) ""; + +// ignore automatically generated getTokens and getTranscripts since they don't +// do anything useful and we have already provided getToken(int i) and +// getTranscript(int i) above. +%ignore "Metadata::transcripts"; +%ignore "CandidateTranscript::tokens"; + %include "../deepspeech.h" From 16f89dff9e5a999475d5096569a263fcc40d65da Mon Sep 17 00:00:00 2001 From: Reuben Morais Date: Tue, 7 Jul 2020 15:18:30 +0200 Subject: [PATCH 2/3] Update Java docs --- doc/Java-API.rst | 6 +- .../CandidateTranscript.java | 14 +--- .../DeepSpeech_Error_Codes.java | 5 ++ .../libdeepspeech_doc/Metadata.java | 12 +-- .../libdeepspeech_doc/MetadataItem.java | 79 ------------------- .../libdeepspeech_doc/TokenMetadata.java | 8 +- 6 files changed, 17 insertions(+), 107 deletions(-) delete mode 100644 native_client/java/libdeepspeech/src/main/java/org/mozilla/deepspeech/libdeepspeech_doc/MetadataItem.java diff --git a/doc/Java-API.rst b/doc/Java-API.rst index 2986ca97..e0c6a7dd 100644 --- a/doc/Java-API.rst +++ b/doc/Java-API.rst @@ -13,17 +13,17 @@ Metadata .. doxygenclass:: org::mozilla::deepspeech::libdeepspeech::Metadata :project: deepspeech-java - :members: getTranscripts, getNum_transcripts, getTranscript + :members: getNumTranscripts, getTranscript CandidateTranscript ------------------- .. doxygenclass:: org::mozilla::deepspeech::libdeepspeech::CandidateTranscript :project: deepspeech-java - :members: getTokens, getNum_tokens, getConfidence, getToken + :members: getNumTokens, getConfidence, getToken TokenMetadata ------------- .. doxygenclass:: org::mozilla::deepspeech::libdeepspeech::TokenMetadata :project: deepspeech-java - :members: getText, getTimestep, getStart_time + :members: getText, getTimestep, getStartTime diff --git a/native_client/java/libdeepspeech/src/main/java/org/mozilla/deepspeech/libdeepspeech_doc/CandidateTranscript.java b/native_client/java/libdeepspeech/src/main/java/org/mozilla/deepspeech/libdeepspeech_doc/CandidateTranscript.java index fa13c474..72dc0f1f 100644 --- a/native_client/java/libdeepspeech/src/main/java/org/mozilla/deepspeech/libdeepspeech_doc/CandidateTranscript.java +++ b/native_client/java/libdeepspeech/src/main/java/org/mozilla/deepspeech/libdeepspeech_doc/CandidateTranscript.java @@ -35,19 +35,11 @@ public class CandidateTranscript { } } - /** - * Array of TokenMetadata objects - */ - public TokenMetadata getTokens() { - long cPtr = implJNI.CandidateTranscript_tokens_get(swigCPtr, this); - return (cPtr == 0) ? null : new TokenMetadata(cPtr, false); - } - /** * Size of the tokens array */ - public long getNum_tokens() { - return implJNI.CandidateTranscript_num_tokens_get(swigCPtr, this); + public long getNumTokens() { + return implJNI.CandidateTranscript_NumTokens_get(swigCPtr, this); } /** @@ -56,7 +48,7 @@ public class CandidateTranscript { * contributed to the creation of this transcript. */ public double getConfidence() { - return implJNI.CandidateTranscript_confidence_get(swigCPtr, this); + return implJNI.CandidateTranscript_Confidence_get(swigCPtr, this); } /** diff --git a/native_client/java/libdeepspeech/src/main/java/org/mozilla/deepspeech/libdeepspeech_doc/DeepSpeech_Error_Codes.java b/native_client/java/libdeepspeech/src/main/java/org/mozilla/deepspeech/libdeepspeech_doc/DeepSpeech_Error_Codes.java index ed47183e..f93f3e8c 100644 --- a/native_client/java/libdeepspeech/src/main/java/org/mozilla/deepspeech/libdeepspeech_doc/DeepSpeech_Error_Codes.java +++ b/native_client/java/libdeepspeech/src/main/java/org/mozilla/deepspeech/libdeepspeech_doc/DeepSpeech_Error_Codes.java @@ -16,6 +16,11 @@ public enum DeepSpeech_Error_Codes { ERR_INVALID_SCORER(0x2002), ERR_MODEL_INCOMPATIBLE(0x2003), ERR_SCORER_NOT_ENABLED(0x2004), + ERR_SCORER_UNREADABLE(0x2005), + ERR_SCORER_INVALID_LM(0x2006), + ERR_SCORER_NO_TRIE(0x2007), + ERR_SCORER_INVALID_TRIE(0x2008), + ERR_SCORER_VERSION_MISMATCH(0x2009), ERR_FAIL_INIT_MMAP(0x3000), ERR_FAIL_INIT_SESS(0x3001), ERR_FAIL_INTERPRETER(0x3002), diff --git a/native_client/java/libdeepspeech/src/main/java/org/mozilla/deepspeech/libdeepspeech_doc/Metadata.java b/native_client/java/libdeepspeech/src/main/java/org/mozilla/deepspeech/libdeepspeech_doc/Metadata.java index d2831bc4..9ef25e1e 100644 --- a/native_client/java/libdeepspeech/src/main/java/org/mozilla/deepspeech/libdeepspeech_doc/Metadata.java +++ b/native_client/java/libdeepspeech/src/main/java/org/mozilla/deepspeech/libdeepspeech_doc/Metadata.java @@ -39,19 +39,11 @@ public class Metadata { } } - /** - * Array of CandidateTranscript objects - */ - public CandidateTranscript getTranscripts() { - long cPtr = implJNI.Metadata_transcripts_get(swigCPtr, this); - return (cPtr == 0) ? null : new CandidateTranscript(cPtr, false); - } - /** * Size of the transcripts array */ - public long getNum_transcripts() { - return implJNI.Metadata_num_transcripts_get(swigCPtr, this); + public long getNumTranscripts() { + return implJNI.Metadata_NumTranscripts_get(swigCPtr, this); } /** diff --git a/native_client/java/libdeepspeech/src/main/java/org/mozilla/deepspeech/libdeepspeech_doc/MetadataItem.java b/native_client/java/libdeepspeech/src/main/java/org/mozilla/deepspeech/libdeepspeech_doc/MetadataItem.java deleted file mode 100644 index 9322f23a..00000000 --- a/native_client/java/libdeepspeech/src/main/java/org/mozilla/deepspeech/libdeepspeech_doc/MetadataItem.java +++ /dev/null @@ -1,79 +0,0 @@ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 4.0.2 - * - * Do not make changes to this file unless you know what you are doing--modify - * the SWIG interface file instead. - * ----------------------------------------------------------------------------- */ - -package org.mozilla.deepspeech.libdeepspeech; - -/** - * Stores each individual character, along with its timing information - */ -public class MetadataItem { - private transient long swigCPtr; - protected transient boolean swigCMemOwn; - - protected MetadataItem(long cPtr, boolean cMemoryOwn) { - swigCMemOwn = cMemoryOwn; - swigCPtr = cPtr; - } - - protected static long getCPtr(MetadataItem obj) { - return (obj == null) ? 0 : obj.swigCPtr; - } - - public synchronized void delete() { - if (swigCPtr != 0) { - if (swigCMemOwn) { - swigCMemOwn = false; - throw new UnsupportedOperationException("C++ destructor does not have public access"); - } - swigCPtr = 0; - } - } - - /** - * The character generated for transcription - */ - public void setCharacter(String value) { - implJNI.MetadataItem_character_set(swigCPtr, this, value); - } - - /** - * The character generated for transcription - */ - public String getCharacter() { - return implJNI.MetadataItem_character_get(swigCPtr, this); - } - - /** - * Position of the character in units of 20ms - */ - public void setTimestep(int value) { - implJNI.MetadataItem_timestep_set(swigCPtr, this, value); - } - - /** - * Position of the character in units of 20ms - */ - public int getTimestep() { - return implJNI.MetadataItem_timestep_get(swigCPtr, this); - } - - /** - * Position of the character in seconds - */ - public void setStart_time(float value) { - implJNI.MetadataItem_start_time_set(swigCPtr, this, value); - } - - /** - * Position of the character in seconds - */ - public float getStart_time() { - return implJNI.MetadataItem_start_time_get(swigCPtr, this); - } - -} diff --git a/native_client/java/libdeepspeech/src/main/java/org/mozilla/deepspeech/libdeepspeech_doc/TokenMetadata.java b/native_client/java/libdeepspeech/src/main/java/org/mozilla/deepspeech/libdeepspeech_doc/TokenMetadata.java index d14fc161..6f976f21 100644 --- a/native_client/java/libdeepspeech/src/main/java/org/mozilla/deepspeech/libdeepspeech_doc/TokenMetadata.java +++ b/native_client/java/libdeepspeech/src/main/java/org/mozilla/deepspeech/libdeepspeech_doc/TokenMetadata.java @@ -38,21 +38,21 @@ public class TokenMetadata { * The text corresponding to this token */ public String getText() { - return implJNI.TokenMetadata_text_get(swigCPtr, this); + return implJNI.TokenMetadata_Text_get(swigCPtr, this); } /** * Position of the token in units of 20ms */ public long getTimestep() { - return implJNI.TokenMetadata_timestep_get(swigCPtr, this); + return implJNI.TokenMetadata_Timestep_get(swigCPtr, this); } /** * Position of the token in seconds */ - public float getStart_time() { - return implJNI.TokenMetadata_start_time_get(swigCPtr, this); + public float getStartTime() { + return implJNI.TokenMetadata_StartTime_get(swigCPtr, this); } } From 2471b10c27d06765fa8446a872c594cb159e144c Mon Sep 17 00:00:00 2001 From: Reuben Morais Date: Tue, 7 Jul 2020 15:24:15 +0200 Subject: [PATCH 3/3] Update Java tests --- .../org/mozilla/deepspeech/libdeepspeech/test/BasicTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native_client/java/libdeepspeech/src/androidTest/java/org/mozilla/deepspeech/libdeepspeech/test/BasicTest.java b/native_client/java/libdeepspeech/src/androidTest/java/org/mozilla/deepspeech/libdeepspeech/test/BasicTest.java index f7eccf00..08fce905 100644 --- a/native_client/java/libdeepspeech/src/androidTest/java/org/mozilla/deepspeech/libdeepspeech/test/BasicTest.java +++ b/native_client/java/libdeepspeech/src/androidTest/java/org/mozilla/deepspeech/libdeepspeech/test/BasicTest.java @@ -63,7 +63,7 @@ public class BasicTest { private String candidateTranscriptToString(CandidateTranscript t) { String retval = ""; - for (int i = 0; i < t.getNum_tokens(); ++i) { + for (int i = 0; i < t.getNumTokens(); ++i) { retval += t.getToken(i).getText(); } return retval;