Merge pull request #3135 from mozilla/java-inconsistencies

Fix some style inconsistencies in Java bindings (Fixes #3121)
This commit is contained in:
Reuben Morais 2020-07-07 17:13:05 +02:00 committed by GitHub
commit d412b86b0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 29 additions and 110 deletions

View File

@ -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``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -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

View File

@ -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"

View File

@ -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;

View File

@ -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);
}
/**

View File

@ -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),

View File

@ -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);
}
/**

View File

@ -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);
}
}

View File

@ -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);
}
}