Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.0 android #299

Merged
merged 11 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions binding/android/Leopard/leopard/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'

ext {
PUBLISH_GROUP_ID = 'ai.picovoice'
PUBLISH_VERSION = '1.2.1'
PUBLISH_VERSION = '2.0.0'
PUBLISH_ARTIFACT_ID = 'leopard-android'
}

Expand Down Expand Up @@ -38,7 +38,7 @@ dependencies {
}

task copyLibs(type: Copy) {
from("${rootDir}/../../lib/android")
from("${rootDir}/../../../lib/android")
into("${rootDir}/leopard/src/main/jniLibs")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,35 @@ public class Leopard {
}

private long handle;
private static String _sdk = "android";

public static void setSdk(String sdk) {
Leopard._sdk = sdk;
}

/**
* Constructor.
*
* @param accessKey AccessKey obtained from Picovoice Console
* @param modelPath Absolute path to the file containing Leopard model parameters.
* @param enableAutomaticPunctuation Set to `true` to enable automatic punctuation insertion.
* @param enableDiarization Set to `true` to enable speaker diarization, which allows Leopard to
* differentiate speakers as part of the transcription process. Word
* metadata will include a `speaker_tag` to identify unique speakers.
* @throws LeopardException if there is an error while initializing Leopard.
*/
private Leopard(
String accessKey,
String modelPath,
boolean enableAutomaticPunctuation) throws LeopardException {
boolean enableAutomaticPunctuation,
boolean enableDiarization) throws LeopardException {
ksyeo1010 marked this conversation as resolved.
Show resolved Hide resolved
LeopardNative.setSdk(Leopard._sdk);

handle = LeopardNative.init(
accessKey,
modelPath,
enableAutomaticPunctuation);
enableAutomaticPunctuation,
enableDiarization);
}

private static String extractResource(
Expand Down Expand Up @@ -180,6 +192,7 @@ public static class Builder {
private String accessKey = null;
private String modelPath = null;
private boolean enableAutomaticPunctuation = false;
private boolean enableDiarization = false;

/**
* Setter the AccessKey.
Expand Down Expand Up @@ -211,6 +224,18 @@ public Builder setEnableAutomaticPunctuation(boolean enableAutomaticPunctuation)
return this;
}

/**
* Setter for enabling speaker diarization.
*
* @param enableDiarization Set to `true` to enable speaker diarization, which allows Leopard to
* differentiate speakers as part of the transcription process. Word
* metadata will include a `speaker_tag` to identify unique speakers.
*/
public Builder setEnableDiarization(boolean enableDiarization) {
this.enableDiarization = enableDiarization;
return this;
}

/**
* Creates an instance of Leopard Speech-to-Text engine.
*/
Expand Down Expand Up @@ -238,7 +263,8 @@ public Leopard build(Context context) throws LeopardException {
return new Leopard(
accessKey,
modelPath,
enableAutomaticPunctuation);
enableAutomaticPunctuation,
enableDiarization);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-2023 Picovoice Inc.

You may not use this file except in compliance with the license. A copy of the license is
located in the "LICENSE" file accompanying this source.
Expand All @@ -14,14 +14,17 @@

class LeopardNative {

static native String getVersion();

static native int getSampleRate();

static native String getVersion();
static native void setSdk(String sdk);

static native long init(
String accessKey,
String modelPath,
boolean enableAutomaticPunctuation) throws LeopardException;
boolean enableAutomaticPunctuation,
boolean enableDiarization) throws LeopardException;

static native void delete(long object);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*
Copyright 2022-2023 Picovoice Inc.

You may not use this file except in compliance with the license. A copy of the license is
located in the "LICENSE" file accompanying this source.

Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
Expand All @@ -11,7 +13,7 @@
package ai.picovoice.leopard;

/**
* Class that contains transcription results returned from Leopard.
* LeopardTranscript Class.
*/
public class LeopardTranscript {

Expand Down Expand Up @@ -48,13 +50,14 @@ public Word[] getWordArray() {
}

/**
* Class for storing word metadata from Leopard.
* LeopardTranscript.Word class
*/
public static class Word {
private final String word;
private final float confidence;
private final float startSec;
private final float endSec;
private final int speakerTag;

/**
* Constructor.
Expand All @@ -63,12 +66,22 @@ public static class Word {
* @param confidence Transcription confidence. It is a number within [0, 1].
* @param startSec Start of word in seconds.
* @param endSec End of word in seconds.
* @param speakerTag The speaker tag is `-1` if diarization is not enabled during initialization;
* otherwise, it's a non-negative integer identifying unique speakers, with `0` reserved for
* unknown speakers.
*/
public Word(String word, float confidence, float startSec, float endSec) {
public Word(
String word,
float confidence,
float startSec,
float endSec,
int speakerTag
) {
this.word = word;
this.confidence = confidence;
this.startSec = startSec;
this.endSec = endSec;
this.speakerTag = speakerTag;
}

/**
Expand Down Expand Up @@ -106,5 +119,14 @@ public float getStartSec() {
public float getEndSec() {
return endSec;
}

/**
* Getter for the speaker tag.
*
* @return Speaker tag.
*/
public int getSpeakerTag() {
return speakerTag;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-2023 Picovoice Inc.

You may not use this file except in compliance with the license. A copy of the license is
located in the "LICENSE" file accompanying this source.

Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
Expand All @@ -18,5 +20,8 @@ public LeopardActivationException(Throwable cause) {
public LeopardActivationException(String message) {
super(message);
}
}

public LeopardActivationException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-2023 Picovoice Inc.

You may not use this file except in compliance with the license. A copy of the license is
located in the "LICENSE" file accompanying this source.

Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
Expand All @@ -18,5 +20,8 @@ public LeopardActivationLimitException(Throwable cause) {
public LeopardActivationLimitException(String message) {
super(message);
}
}

public LeopardActivationLimitException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-2023 Picovoice Inc.

You may not use this file except in compliance with the license. A copy of the license is
located in the "LICENSE" file accompanying this source.

Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
Expand All @@ -18,5 +20,8 @@ public LeopardActivationRefusedException(Throwable cause) {
public LeopardActivationRefusedException(String message) {
super(message);
}
}

public LeopardActivationRefusedException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-2023 Picovoice Inc.

You may not use this file except in compliance with the license. A copy of the license is
located in the "LICENSE" file accompanying this source.

Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
Expand All @@ -18,5 +20,8 @@ public LeopardActivationThrottledException(Throwable cause) {
public LeopardActivationThrottledException(String message) {
super(message);
}
}

public LeopardActivationThrottledException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-2023 Picovoice Inc.

You may not use this file except in compliance with the license. A copy of the license is
located in the "LICENSE" file accompanying this source.

Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
Expand All @@ -11,12 +13,42 @@
package ai.picovoice.leopard;

public class LeopardException extends Exception {
private final String message;
private final String[] messageStack;

public LeopardException(Throwable cause) {
super(cause);
this.message = cause.getMessage();
this.messageStack = null;
}

public LeopardException(String message) {
super(message);
this.message = message;
this.messageStack = null;
}
}

public LeopardException(String message, String[] messageStack) {
super(message);
this.message = message;
this.messageStack = messageStack;
}

public String[] getMessageStack() {
return this.messageStack;
}

@Override
public String getMessage() {
StringBuilder sb = new StringBuilder(message);
if (messageStack != null) {
if (messageStack.length > 0) {
sb.append(":");
for (int i = 0; i < messageStack.length; i++) {
sb.append(String.format("\n [%d] %s", i, messageStack[i]));
}
}
}
return sb.toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-2023 Picovoice Inc.

You may not use this file except in compliance with the license. A copy of the license is
located in the "LICENSE" file accompanying this source.

Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
Expand All @@ -18,5 +20,8 @@ public LeopardIOException(Throwable cause) {
public LeopardIOException(String message) {
super(message);
}
}

public LeopardIOException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-2023 Picovoice Inc.

You may not use this file except in compliance with the license. A copy of the license is
located in the "LICENSE" file accompanying this source.

Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
Expand All @@ -18,5 +20,8 @@ public LeopardInvalidArgumentException(Throwable cause) {
public LeopardInvalidArgumentException(String message) {
super(message);
}
}

public LeopardInvalidArgumentException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-2023 Picovoice Inc.

You may not use this file except in compliance with the license. A copy of the license is
located in the "LICENSE" file accompanying this source.

Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
Expand All @@ -18,5 +20,8 @@ public LeopardInvalidStateException(Throwable cause) {
public LeopardInvalidStateException(String message) {
super(message);
}
}

public LeopardInvalidStateException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Loading