index
int64
repo_id
string
file_path
string
content
string
0
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra/CobraNative.java
/* 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 limitations under the License. */ package ai.picovoice.cobra; class CobraNative { static native String getVersion(); static native int getFrameLength(); static native int getSampleRate(); static native void setSdk(String sdk); static native long init(String accessKey) throws CobraException; static native void delete(long object); static native float process(long object, short[] pcm) throws CobraException; }
0
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra/exception/CobraActivationException.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.cobra; public class CobraActivationException extends CobraException { public CobraActivationException(Throwable cause) { super(cause); } public CobraActivationException(String message) { super(message); } public CobraActivationException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra/exception/CobraActivationLimitException.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.cobra; public class CobraActivationLimitException extends CobraException { public CobraActivationLimitException(Throwable cause) { super(cause); } public CobraActivationLimitException(String message) { super(message); } public CobraActivationLimitException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra/exception/CobraActivationRefusedException.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.cobra; public class CobraActivationRefusedException extends CobraException { public CobraActivationRefusedException(Throwable cause) { super(cause); } public CobraActivationRefusedException(String message) { super(message); } public CobraActivationRefusedException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra/exception/CobraActivationThrottledException.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.cobra; public class CobraActivationThrottledException extends CobraException { public CobraActivationThrottledException(Throwable cause) { super(cause); } public CobraActivationThrottledException(String message) { super(message); } public CobraActivationThrottledException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra/exception/CobraException.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.cobra; import android.annotation.SuppressLint; public class CobraException extends Exception { private final String message; private final String[] messageStack; public CobraException(Throwable cause) { super(cause); this.message = cause.getMessage(); this.messageStack = null; } public CobraException(String message) { super(message); this.message = message; this.messageStack = null; } public CobraException(String message, String[] messageStack) { super(message); this.message = message; this.messageStack = messageStack; } public String[] getMessageStack() { return this.messageStack; } @SuppressLint("DefaultLocale") @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(); } }
0
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra/exception/CobraIOException.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.cobra; public class CobraIOException extends CobraException { public CobraIOException(Throwable cause) { super(cause); } public CobraIOException(String message) { super(message); } public CobraIOException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra/exception/CobraInvalidArgumentException.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.cobra; public class CobraInvalidArgumentException extends CobraException { public CobraInvalidArgumentException(Throwable cause) { super(cause); } public CobraInvalidArgumentException(String message) { super(message); } public CobraInvalidArgumentException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra/exception/CobraInvalidStateException.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.cobra; public class CobraInvalidStateException extends CobraException { public CobraInvalidStateException(Throwable cause) { super(cause); } public CobraInvalidStateException(String message) { super(message); } public CobraInvalidStateException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra/exception/CobraKeyException.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.cobra; public class CobraKeyException extends CobraException { public CobraKeyException(Throwable cause) { super(cause); } public CobraKeyException(String message) { super(message); } public CobraKeyException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra/exception/CobraMemoryException.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.cobra; public class CobraMemoryException extends CobraException { public CobraMemoryException(Throwable cause) { super(cause); } public CobraMemoryException(String message) { super(message); } public CobraMemoryException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra/exception/CobraRuntimeException.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.cobra; public class CobraRuntimeException extends CobraException { public CobraRuntimeException(Throwable cause) { super(cause); } public CobraRuntimeException(String message) { super(message); } public CobraRuntimeException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra
java-sources/ai/picovoice/cobra-android/2.1.0/ai/picovoice/cobra/exception/CobraStopIterationException.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.cobra; public class CobraStopIterationException extends CobraException { public CobraStopIterationException(Throwable cause) { super(cause); } public CobraStopIterationException(String message) { super(message); } public CobraStopIterationException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle/Eagle.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.eagle; import android.content.Context; import android.content.res.Resources; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; /** * Android binding for Eagle speaker recognition engine. */ public class Eagle { private static String defaultModelPath; private static String _sdk = "android"; static { System.loadLibrary("pv_eagle"); } private long handle; private int numSpeakers; public static void setSdk(String sdk) { Eagle._sdk = sdk; } /** * Constructor. * * @param accessKey AccessKey obtained from Picovoice Console * @param modelPath Absolute path to the file containing Eagle model parameters. * @param speakerProfiles A list of EagleProfile objects. This can be constructed using `EagleProfiler`. * @throws EagleException if there is an error while initializing Eagle. */ private Eagle( String accessKey, String modelPath, EagleProfile[] speakerProfiles) throws EagleException { long[] profileHandles = new long[speakerProfiles.length]; for (int i = 0; i < speakerProfiles.length; i++) { profileHandles[i] = speakerProfiles[i].profileNative.handle; } EagleNative.setSdk(Eagle._sdk); handle = EagleNative.init( accessKey, modelPath, speakerProfiles.length, profileHandles); numSpeakers = speakerProfiles.length; } /** * Releases resources acquired by Eagle. */ public void delete() { if (handle != 0) { EagleNative.delete(handle); handle = 0; } } /** * Processes a frame of audio and returns a list of similarity scores for each speaker profile. * * @param pcm A frame of audio samples. The number of samples per frame can be attained by calling * `.getFrameLength()`. The incoming audio needs to have a sample rate equal * to `.getSampleRate()` and be 16-bit linearly-encoded. Eagle operates on single-channel audio. * @return A list of similarity scores for each speaker profile. A higher score indicates that the voice * belongs to the corresponding speaker. The range is [0, 1] with 1.0 representing a perfect match. * @throws EagleException if there is an error while processing audio frames. */ public float[] process(short[] pcm) throws EagleException { if (handle == 0) { throw new EagleInvalidStateException("Attempted to call eagle process after delete."); } if (pcm.length != this.getFrameLength()) { throw new EagleInvalidArgumentException( String.format("Length of input frame %d does not match required frame length %d", pcm.length, this.getSampleRate())); } return EagleNative.process(handle, pcm, numSpeakers); } /** * Resets the internal state of Eagle Profiler. * It should be called before starting a new enrollment session. * * @throws EagleException if there is an error while resetting Eagle. */ public void reset() throws EagleException { if (handle == 0) { throw new EagleInvalidStateException("Attempted to call eagle reset after delete."); } EagleNative.reset(handle); } /** * Getter for version. * * @return Version. */ public String getVersion() { return EagleNative.getVersion(); } /** * Getter for number of audio samples per frame. * * @return Number of audio samples per frame. */ public int getFrameLength() { return EagleNative.getFrameLength(); } /** * Getter for audio sample rate accepted by Picovoice. * * @return Audio sample rate accepted by Picovoice. */ public int getSampleRate() { return EagleNative.getSampleRate(); } /** * Builder for creating instance of Eagle. */ public static class Builder { private String accessKey = null; private String modelPath = null; private EagleProfile[] speakerProfiles = null; public Builder setAccessKey(String accessKey) { this.accessKey = accessKey; return this; } public Builder setModelPath(String modelPath) { this.modelPath = modelPath; return this; } public Builder setSpeakerProfiles(EagleProfile[] speakerProfiles) { this.speakerProfiles = speakerProfiles; return this; } public Builder setSpeakerProfile(EagleProfile speakerProfile) { this.speakerProfiles = new EagleProfile[]{ speakerProfile }; return this; } private static void extractPackageResources(Context context) throws EagleIOException { final Resources resources = context.getResources(); try { defaultModelPath = extractResource(context, resources.openRawResource(R.raw.eagle_params), resources.getResourceEntryName(R.raw.eagle_params) + ".pv"); } catch (IOException ex) { throw new EagleIOException(ex); } } private static String extractResource( Context context, InputStream srcFileStream, String dstFilename ) throws IOException { InputStream is = new BufferedInputStream(srcFileStream, 256); OutputStream os = new BufferedOutputStream(context.openFileOutput(dstFilename, Context.MODE_PRIVATE), 256); int r; while ((r = is.read()) != -1) { os.write(r); } os.flush(); is.close(); os.close(); return new File(context.getFilesDir(), dstFilename).getAbsolutePath(); } /** * Validates properties and creates an instance of the Eagle speaker recognition engine. * * @param context Android app context (for extracting Eagle resources) * @return An instance Eagle speaker recognition engine * @throws EagleException if there is an error while initializing Eagle. */ public Eagle build(Context context) throws EagleException { if (accessKey == null || this.accessKey.equals("")) { throw new EagleInvalidArgumentException("No AccessKey was provided to Eagle"); } if (modelPath == null) { if (defaultModelPath == null) { extractPackageResources(context); } modelPath = defaultModelPath; } else { File modelFile = new File(modelPath); String modelFilename = modelFile.getName(); if (!modelFile.exists() && !modelFilename.equals("")) { try { modelPath = extractResource(context, context.getAssets().open(modelPath), modelFilename); } catch (IOException ex) { throw new EagleIOException(ex); } } } if (speakerProfiles == null || this.speakerProfiles.length == 0) { throw new EagleInvalidArgumentException("No speaker profiles provided to Eagle"); } return new Eagle(accessKey, modelPath, speakerProfiles); } } }
0
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle/EagleNative.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.eagle; import java.util.HashMap; class EagleNative { static native String getVersion(); static native int getFrameLength(); static native int getSampleRate(); static native void setSdk(String sdk); static native long init( String accessKey, String modelPath, int numSpeakers, long[] speakerProfiles) throws EagleException; static native void delete(long object); static native float[] process(long object, short[] pcm, int numSpeakers) throws EagleException; static native void reset(long object) throws EagleException; }
0
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle/EagleProfile.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.eagle; /** * Representation of an Eagle speaker profile. */ public class EagleProfile { static { System.loadLibrary("pv_eagle"); } final EagleProfileNative profileNative; EagleProfile(EagleProfileNative profileNative) { this.profileNative = profileNative; } /** * Constructor. * * @param profileBytes a byte array previously obtained via {@link #getBytes()}. */ public EagleProfile(byte[] profileBytes) { profileNative = new EagleProfileNative(profileBytes); } /** * Gets the speaker profile in the form of a byte array. * * @return the speaker profile in the form of a byte array. */ public byte[] getBytes() { return profileNative.getBytes(); } /** * Releases resources acquired by EagleProfile. */ public void delete() { profileNative.delete(); } }
0
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle/EagleProfileNative.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.eagle; class EagleProfileNative { final long handle; final int numBytes; public EagleProfileNative(long handle, int numBytes) { this.handle = handle; this.numBytes = numBytes; } public EagleProfileNative(byte[] profileBytes) { this.handle = setBytesNative(profileBytes, profileBytes.length); this.numBytes = profileBytes.length; } public byte[] getBytes() { return getBytesNative(this.handle, this.numBytes); } public void delete() { deleteNative(this.handle); } private native void deleteNative(long handle); private native byte[] getBytesNative(long handle, int numBytes); private native long setBytesNative(byte[] profileBytes, int numBytes); }
0
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle/EagleProfiler.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.eagle; import android.content.Context; import android.content.res.Resources; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; /** * Android binding for the profiler of the Eagle speaker recognition engine. * It enrolls a speaker given a set of utterances and then constructs a profile for the enrolled speaker. */ public class EagleProfiler { private static String defaultModelPath; private static String _sdk = "android"; private final int minEnrollSamples; static { System.loadLibrary("pv_eagle"); } private long handle; public static void setSdk(String sdk) { EagleProfiler._sdk = sdk; } /** * Constructor. * * @param accessKey AccessKey obtained from Picovoice Console * @param modelPath Absolute path to the file containing Eagle model parameters. * @throws EagleException if there is an error while initializing EagleProfiler. */ private EagleProfiler(String accessKey, String modelPath) throws EagleException { EagleNative.setSdk(EagleProfiler._sdk); handle = EagleProfilerNative.init(accessKey, modelPath); minEnrollSamples = EagleProfilerNative.minEnrollSamples(handle); } /** * Releases resources acquired by Eagle. */ public void delete() { if (handle != 0) { EagleProfilerNative.delete(handle); handle = 0; } } /** * Enrolls a speaker. This function should be called multiple times with different utterances of the same speaker * until `percentage` reaches `100.0`. Any further enrollment can be used to improve the speaker voice profile. * The minimum number of required samples can be obtained by calling `.getMinEnrollSamples()`. * The audio data used for enrollment should satisfy the following requirements: * - only one speaker should be present in the audio * - the speaker should be speaking in a normal voice * - the audio should contain no speech from other speakers and no other sounds (e.g. music) * - it should be captured in a quiet environment with no background noise * * @param pcm The audio needs to have a sample rate equal to `.getSampleRate()` and be * 16-bit linearly-encoded. EagleProfiler operates on single-channel audio. * @return The percentage of completeness of the speaker enrollment process along with the feedback code * corresponding to the last enrollment attempt. * @throws EagleException if there is an error while enrolling speaker. */ public EagleProfilerEnrollResult enroll(short[] pcm) throws EagleException { if (handle == 0) { throw new EagleInvalidStateException("Attempted to call eagle enroll after delete."); } return EagleProfilerNative.enroll(handle, pcm, pcm.length); } /** * Exports the speaker profile of the current session. Will raise an exception if the profile is not ready. * * @return An EagleProfile object. */ public EagleProfile export() throws EagleException { if (handle == 0) { throw new EagleInvalidStateException("Attempted to call eagle profile export after delete."); } return new EagleProfile(EagleProfilerNative.export(handle)); } /** * Resets the internal state of Eagle Profiler. It should be called before starting a new enrollment session. */ public void reset() throws EagleException { if (handle == 0) { throw new EagleInvalidStateException("Attempted to call eagle reset after delete."); } EagleProfilerNative.reset(handle); } /** * Getter for version. * * @return Version. */ public String getVersion() { return EagleProfilerNative.getVersion(); } /** * Getter for audio sample rate accepted by Picovoice. * * @return Audio sample rate accepted by Picovoice. */ public int getSampleRate() { return EagleProfilerNative.getSampleRate(); } /** * Getter for minimum length of the input pcm required by `.enroll()`. * * @return minimum length of the input pcm. */ public int getMinEnrollSamples() { return this.minEnrollSamples; } /** * Builder for creating instance of EagleProfiler. */ public static class Builder { private String accessKey = null; private String modelPath = null; public Builder setAccessKey(String accessKey) { this.accessKey = accessKey; return this; } public Builder setModelPath(String modelPath) { this.modelPath = modelPath; return this; } private static void extractPackageResources(Context context) throws EagleIOException { final Resources resources = context.getResources(); try { defaultModelPath = extractResource(context, resources.openRawResource(R.raw.eagle_params), resources.getResourceEntryName(R.raw.eagle_params) + ".pv"); } catch (IOException ex) { throw new EagleIOException(ex); } } private static String extractResource( Context context, InputStream srcFileStream, String dstFilename ) throws IOException { InputStream is = new BufferedInputStream(srcFileStream, 256); OutputStream os = new BufferedOutputStream(context.openFileOutput(dstFilename, Context.MODE_PRIVATE), 256); int r; while ((r = is.read()) != -1) { os.write(r); } os.flush(); is.close(); os.close(); return new File(context.getFilesDir(), dstFilename).getAbsolutePath(); } /** * Validates properties and creates an instance of the Eagle profiler. * * @param context Android app context (for extracting Eagle resources) * @return An instance Eagle profiler * @throws EagleException if there is an error while initializing Eagle profiler. */ public EagleProfiler build(Context context) throws EagleException { if (accessKey == null || this.accessKey.equals("")) { throw new EagleInvalidArgumentException("No AccessKey was provided to Eagle"); } if (modelPath == null) { if (defaultModelPath == null) { extractPackageResources(context); } modelPath = defaultModelPath; } else { File modelFile = new File(modelPath); String modelFilename = modelFile.getName(); if (!modelFile.exists() && !modelFilename.equals("")) { try { modelPath = extractResource(context, context.getAssets().open(modelPath), modelFilename); } catch (IOException ex) { throw new EagleIOException(ex); } } } return new EagleProfiler(accessKey, modelPath); } } }
0
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle/EagleProfilerEnrollFeedback.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.eagle; /** * Enumeration of possible enrollment feedback codes: * - `AUDIO_OK`: The audio is good for enrollment. * - `AUDIO_TOO_SHORT`: Audio length is insufficient for enrollment, * i.e. it is shorter than`EagleProfiler.getMinEnrollSamples()`. * - `UNKNOWN_SPEAKER`: There is another speaker in the audio that is different from the speaker * being enrolled. Too much background noise may cause this error as well. * - `NO_VOICE_FOUND`: The audio does not contain any voice, i.e. it is silent or * has a low signal-to-noise ratio. * - `QUALITY_ISSUE`: The audio quality is too low for enrollment due to a bad microphone * or recording environment. */ public enum EagleProfilerEnrollFeedback { AUDIO_OK, AUDIO_TOO_SHORT, UNKNOWN_SPEAKER, NO_VOICE_FOUND, QUALITY_ISSUE; }
0
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle/EagleProfilerEnrollResult.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.eagle; /** * Representation of the feedback, given percentage and code. */ public class EagleProfilerEnrollResult { private final float percentage; private final EagleProfilerEnrollFeedback feedback; public EagleProfilerEnrollResult(float percentage, int feedbackIdx) { this.percentage = percentage; this.feedback = EagleProfilerEnrollFeedback.values()[feedbackIdx]; } public float getPercentage() { return this.percentage; } public EagleProfilerEnrollFeedback getFeedback() { return this.feedback; } }
0
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle/EagleProfilerNative.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.eagle; class EagleProfilerNative { static native int getSampleRate(); static native String getVersion(); static native long init( String accessKey, String modelPath) throws EagleException; static native void delete(long object); static native EagleProfilerEnrollResult enroll( long handle, short[] pcm, int numSamples) throws EagleException; static native EagleProfileNative export(long handle) throws EagleException; static native void reset(long handle) throws EagleException; static native int minEnrollSamples(long handle) throws EagleException; }
0
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle/exception/EagleActivationException.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.eagle; public class EagleActivationException extends EagleException { public EagleActivationException(Throwable cause) { super(cause); } public EagleActivationException(String message) { super(message); } public EagleActivationException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle/exception/EagleActivationLimitException.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.eagle; public class EagleActivationLimitException extends EagleException { public EagleActivationLimitException(Throwable cause) { super(cause); } public EagleActivationLimitException(String message) { super(message); } public EagleActivationLimitException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle/exception/EagleActivationRefusedException.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.eagle; public class EagleActivationRefusedException extends EagleException { public EagleActivationRefusedException(Throwable cause) { super(cause); } public EagleActivationRefusedException(String message) { super(message); } public EagleActivationRefusedException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle/exception/EagleActivationThrottledException.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.eagle; public class EagleActivationThrottledException extends EagleException { public EagleActivationThrottledException(Throwable cause) { super(cause); } public EagleActivationThrottledException(String message) { super(message); } public EagleActivationThrottledException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle/exception/EagleException.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.eagle; public class EagleException extends Exception { private final String message; private final String[] messageStack; public EagleException(Throwable cause) { super(cause); this.message = cause.getMessage(); this.messageStack = null; } public EagleException(String message) { super(message); this.message = message; this.messageStack = null; } public EagleException(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(); } }
0
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle/exception/EagleIOException.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.eagle; public class EagleIOException extends EagleException { public EagleIOException(Throwable cause) { super(cause); } public EagleIOException(String message) { super(message); } public EagleIOException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle/exception/EagleInvalidArgumentException.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.eagle; public class EagleInvalidArgumentException extends EagleException { public EagleInvalidArgumentException(Throwable cause) { super(cause); } public EagleInvalidArgumentException(String message) { super(message); } public EagleInvalidArgumentException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle/exception/EagleInvalidStateException.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.eagle; public class EagleInvalidStateException extends EagleException { public EagleInvalidStateException(Throwable cause) { super(cause); } public EagleInvalidStateException(String message) { super(message); } public EagleInvalidStateException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle/exception/EagleKeyException.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.eagle; public class EagleKeyException extends EagleException { public EagleKeyException(Throwable cause) { super(cause); } public EagleKeyException(String message) { super(message); } public EagleKeyException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle/exception/EagleMemoryException.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.eagle; public class EagleMemoryException extends EagleException { public EagleMemoryException(Throwable cause) { super(cause); } public EagleMemoryException(String message) { super(message); } public EagleMemoryException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle/exception/EagleRuntimeException.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.eagle; public class EagleRuntimeException extends EagleException { public EagleRuntimeException(Throwable cause) { super(cause); } public EagleRuntimeException(String message) { super(message); } public EagleRuntimeException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle
java-sources/ai/picovoice/eagle-android/1.0.1/ai/picovoice/eagle/exception/EagleStopIterationException.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.eagle; public class EagleStopIterationException extends EagleException { public EagleStopIterationException(Throwable cause) { super(cause); } public EagleStopIterationException(String message) { super(message); } public EagleStopIterationException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon/Falcon.java
/* Copyright 2024 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 limitations under the License. */ package ai.picovoice.falcon; import android.content.Context; import android.content.res.Resources; import android.text.TextUtils; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; /** * Android binding for Falcon Speaker Diarization engine. */ public class Falcon { private static String defaultModelPath; private static String _sdk = "android"; static { System.loadLibrary("pv_falcon"); } private long handle; private static final String[] VALID_EXTENSIONS = { "3gp", "flac", "m4a", "mp3", "mp4", "ogg", "opus", "vorbis", "wav", "webm" }; public static void setSdk(String sdk) { Falcon._sdk = sdk; } /** * Constructor. * * @param accessKey AccessKey obtained from Picovoice Console * @param modelPath Absolute path to the file containing Falcon model parameters. * @throws FalconException if there is an error while initializing Falcon. */ private Falcon( String accessKey, String modelPath) throws FalconException { FalconNative.setSdk(Falcon._sdk); handle = FalconNative.init( accessKey, modelPath); } /** * Releases resources acquired by Falcon. */ public void delete() { if (handle != 0) { FalconNative.delete(handle); handle = 0; } } /** * Processes given audio data and returns diarized speaker segments. * * @param pcm A frame of audio samples. The incoming audio needs to have a sample rate * equal to {@link #getSampleRate()} and be 16-bit linearly-encoded. Furthermore, * Falcon operates on single channel audio. If you wish to process data in a different * sample rate or format, consider using {@link #processFile(String)}. * @return FalconSegment[] object which contains the diarization results of the engine. * @throws FalconException if there is an error while processing the audio frame. */ public FalconSegment[] process(short[] pcm) throws FalconException { if (handle == 0) { throw new FalconInvalidStateException("Attempted to call Falcon process after delete."); } if (pcm == null) { throw new FalconInvalidArgumentException("Passed null frame to Falcon process."); } return FalconNative.process(handle, pcm, pcm.length); } /** * Processes given audio data and returns diarized speaker segments. * * @param path Absolute path to the audio file. The supported formats are: * `3gp (AMR)`, `FLAC`, `MP3`, `MP4/m4a (AAC)`, `Ogg`, `WAV` and `WebM`. * @return FalconSegment[] object which contains the diarization results of the engine. * @throws FalconException if there is an error while processing the audio frame. */ public FalconSegment[] processFile(String path) throws FalconException { if (handle == 0) { throw new FalconInvalidStateException("Attempted to call Falcon processFile after delete."); } if (path == null || path.equals("")) { throw new FalconInvalidArgumentException("Passed null path to Falcon processFile."); } try { return FalconNative.processFile(handle, path); } catch (FalconInvalidArgumentException e) { boolean endsWithValidExt = false; for (String ext : VALID_EXTENSIONS) { if (path.endsWith(ext)) { endsWithValidExt = true; break; } } if (!endsWithValidExt) { throw new FalconInvalidArgumentException( String.format( "Specified file '%s' does not have an accepted file extension. " + "Valid extensions are: %s", path, TextUtils.join(", ", VALID_EXTENSIONS))); } throw e; } } /** * Getter for required audio sample rate for PCM data. * * @return Required audio sample rate for PCM data. */ public int getSampleRate() { return FalconNative.getSampleRate(); } /** * Getter for Falcon version. * * @return Falcon version. */ public String getVersion() { return FalconNative.getVersion(); } /** * Builder for creating an instance of Falcon. */ public static class Builder { private String accessKey = null; private String modelPath = null; /** * Setter the AccessKey. * * @param accessKey AccessKey obtained from Picovoice Console */ public Builder setAccessKey(String accessKey) { this.accessKey = accessKey; return this; } /** * Setter for the absolute path to the file containing Falcon model parameters. * * @param modelPath Absolute path to the file containing Falcon model parameters. */ public Builder setModelPath(String modelPath) { this.modelPath = modelPath; return this; } private static void extractPackageResources(Context context) throws FalconIOException { final Resources resources = context.getResources(); try { defaultModelPath = extractResource(context, resources.openRawResource(R.raw.falcon_params), resources.getResourceEntryName(R.raw.falcon_params) + ".pv"); } catch (IOException ex) { throw new FalconIOException(ex); } } private static String extractResource( Context context, InputStream srcFileStream, String dstFilename ) throws IOException { InputStream is = new BufferedInputStream(srcFileStream, 512); OutputStream os = new BufferedOutputStream(context.openFileOutput(dstFilename, Context.MODE_PRIVATE), 512); int r; while ((r = is.read()) != -1) { os.write(r); } os.flush(); is.close(); os.close(); return new File(context.getFilesDir(), dstFilename).getAbsolutePath(); } /** * Creates an instance of Falcon Speaker Diarization engine. */ public Falcon build(Context context) throws FalconException { if (accessKey == null || this.accessKey.equals("")) { throw new FalconInvalidArgumentException("No AccessKey was provided to Falcon"); } if (modelPath == null) { if (defaultModelPath == null) { extractPackageResources(context); } modelPath = defaultModelPath; } else { File modelFile = new File(modelPath); String modelFilename = modelFile.getName(); if (!modelFile.exists() && !modelFilename.equals("")) { try { modelPath = extractResource(context, context.getAssets().open(modelPath), modelFilename); } catch (IOException ex) { throw new FalconIOException(ex); } } } return new Falcon( accessKey, modelPath); } } }
0
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon/FalconNative.java
/* Copyright 2024 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 limitations under the License. */ package ai.picovoice.falcon; class FalconNative { static native String getVersion(); static native int getSampleRate(); static native void setSdk(String sdk); static native long init( String accessKey, String modelPath) throws FalconException; static native void delete(long object); static native FalconSegment[] process( long object, short[] pcm, int numSamples) throws FalconException; static native FalconSegment[] processFile( long object, String path) throws FalconException; }
0
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon/FalconSegment.java
/* Copyright 2024 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 limitations under the License. */ package ai.picovoice.falcon; /** * FalconSegment class. */ public class FalconSegment { private final float startSec; private final float endSec; private final int speakerTag; /** * Constructor. * * @param startSec Start of segment in seconds. * @param endSec End of segment in seconds. * @param speakerTag A non-negative integer that identifies unique speakers. */ public FalconSegment( float startSec, float endSec, int speakerTag ) { this.startSec = startSec; this.endSec = endSec; this.speakerTag = speakerTag; } /** * Getter for the start of segment in seconds. * * @return Start of segment in seconds. */ public float getStartSec() { return startSec; } /** * Getter for the end of segment in seconds. * * @return End of segment in seconds. */ public float getEndSec() { return endSec; } /** * Getter for the speaker tag. * * @return Speaker tag. */ public int getSpeakerTag() { return speakerTag; } }
0
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon/exception/FalconActivationException.java
/* Copyright 2024 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 limitations under the License. */ package ai.picovoice.falcon; public class FalconActivationException extends FalconException { public FalconActivationException(Throwable cause) { super(cause); } public FalconActivationException(String message) { super(message); } public FalconActivationException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon/exception/FalconActivationLimitException.java
/* Copyright 2024 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 limitations under the License. */ package ai.picovoice.falcon; public class FalconActivationLimitException extends FalconException { public FalconActivationLimitException(Throwable cause) { super(cause); } public FalconActivationLimitException(String message) { super(message); } public FalconActivationLimitException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon/exception/FalconActivationRefusedException.java
/* Copyright 2024 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 limitations under the License. */ package ai.picovoice.falcon; public class FalconActivationRefusedException extends FalconException { public FalconActivationRefusedException(Throwable cause) { super(cause); } public FalconActivationRefusedException(String message) { super(message); } public FalconActivationRefusedException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon/exception/FalconActivationThrottledException.java
/* Copyright 2024 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 limitations under the License. */ package ai.picovoice.falcon; public class FalconActivationThrottledException extends FalconException { public FalconActivationThrottledException(Throwable cause) { super(cause); } public FalconActivationThrottledException(String message) { super(message); } public FalconActivationThrottledException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon/exception/FalconException.java
/* Copyright 2024 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 limitations under the License. */ package ai.picovoice.falcon; public class FalconException extends Exception { private final String message; private final String[] messageStack; public FalconException(Throwable cause) { super(cause); this.message = cause.getMessage(); this.messageStack = null; } public FalconException(String message) { super(message); this.message = message; this.messageStack = null; } public FalconException(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(); } }
0
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon/exception/FalconIOException.java
/* Copyright 2024 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 limitations under the License. */ package ai.picovoice.falcon; public class FalconIOException extends FalconException { public FalconIOException(Throwable cause) { super(cause); } public FalconIOException(String message) { super(message); } public FalconIOException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon/exception/FalconInvalidArgumentException.java
/* Copyright 2024 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 limitations under the License. */ package ai.picovoice.falcon; public class FalconInvalidArgumentException extends FalconException { public FalconInvalidArgumentException(Throwable cause) { super(cause); } public FalconInvalidArgumentException(String message) { super(message); } public FalconInvalidArgumentException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon/exception/FalconInvalidStateException.java
/* Copyright 2024 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 limitations under the License. */ package ai.picovoice.falcon; public class FalconInvalidStateException extends FalconException { public FalconInvalidStateException(Throwable cause) { super(cause); } public FalconInvalidStateException(String message) { super(message); } public FalconInvalidStateException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon/exception/FalconKeyException.java
/* Copyright 2024 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 limitations under the License. */ package ai.picovoice.falcon; public class FalconKeyException extends FalconException { public FalconKeyException(Throwable cause) { super(cause); } public FalconKeyException(String message) { super(message); } public FalconKeyException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon/exception/FalconMemoryException.java
/* Copyright 2024 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 limitations under the License. */ package ai.picovoice.falcon; public class FalconMemoryException extends FalconException { public FalconMemoryException(Throwable cause) { super(cause); } public FalconMemoryException(String message) { super(message); } public FalconMemoryException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon/exception/FalconRuntimeException.java
/* Copyright 2024 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 limitations under the License. */ package ai.picovoice.falcon; public class FalconRuntimeException extends FalconException { public FalconRuntimeException(Throwable cause) { super(cause); } public FalconRuntimeException(String message) { super(message); } public FalconRuntimeException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon
java-sources/ai/picovoice/falcon-android/1.0.2/ai/picovoice/falcon/exception/FalconStopIterationException.java
/* Copyright 2024 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 limitations under the License. */ package ai.picovoice.falcon; public class FalconStopIterationException extends FalconException { public FalconStopIterationException(Throwable cause) { super(cause); } public FalconStopIterationException(String message) { super(message); } public FalconStopIterationException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala/Koala.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.koala; import android.content.Context; import android.content.res.Resources; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; /** * Android binding for Koala Noise Suppression engine. */ public class Koala { private static String defaultModelPath; private static String _sdk = "android"; static { System.loadLibrary("pv_koala"); } private long handle; public static void setSdk(String sdk) { Koala._sdk = sdk; } /** * Constructor. * * @param accessKey AccessKey obtained from Picovoice Console * @param modelPath Absolute path to the file containing Koala model parameters. * * @throws KoalaException if there is an error while initializing Koala. */ private Koala(String accessKey, String modelPath) throws KoalaException { KoalaNative.setSdk(Koala._sdk); handle = KoalaNative.init(accessKey, modelPath); } private static void extractPackageResources(Context context) throws KoalaException { final Resources resources = context.getResources(); try { defaultModelPath = extractResource(context, resources.openRawResource(R.raw.koala_params), resources.getResourceEntryName(R.raw.koala_params) + ".pv"); } catch (IOException ex) { throw new KoalaIOException(ex); } } private static String extractResource( Context context, InputStream srcFileStream, String dstFilename ) throws IOException { InputStream is = new BufferedInputStream(srcFileStream, 256); OutputStream os = new BufferedOutputStream(context.openFileOutput(dstFilename, Context.MODE_PRIVATE), 256); int r; while ((r = is.read()) != -1) { os.write(r); } os.flush(); is.close(); os.close(); return new File(context.getFilesDir(), dstFilename).getAbsolutePath(); } /** * Releases resources acquired by Koala. */ public void delete() { if (handle != 0) { KoalaNative.delete(handle); handle = 0; } } /** * Processes given audio data and returns delayed enhanced audio. * * @param pcm A frame of audio samples. The number of samples per frame can be obtained by * calling {@link #getFrameLength()}. The incoming audio needs to have a sample rate * equal to {@link #getSampleRate()} and be 16-bit linearly-encoded. Koala operates * on single-channel audio. Consecutive calls to {@link #process()} must provide consecutive * frames of audio from the same source, unless {@link #reset()} has been called in between. * * @return A frame of enhanced audio samples, stored as a sequence of 16-bit linearly-encoded integers. * The output is not directly the enhanced version of the input PCM, but corresponds to samples * that were given in previous calls to {@link #process()}. The delay in samples between the start * time of the input frame and the start time of the output frame can be obtained from * {@link #getDelaySample()}. * * @throws KoalaException if there is an error while processing the audio frame. */ public short[] process(short[] pcm) throws KoalaException { if (handle == 0) { throw new KoalaInvalidStateException("Attempted to call Koala process after delete."); } if (pcm == null) { throw new KoalaInvalidArgumentException("Passed null frame to Koala process."); } if (pcm.length != getFrameLength()) { throw new KoalaInvalidArgumentException( String.format("Koala process requires frames of length %d. " + "Received frame of size %d.", getFrameLength(), pcm.length)); } return KoalaNative.process(handle, pcm); } /** * Resets Koala into a state as if it had just been newly created. * Call this function in between calls to {@link #process()} that do not * provide consecutive frames of audio. * * * @throws KoalaException if there is an error while processing the audio frame. */ public void reset() throws KoalaException { if (handle == 0) { throw new KoalaInvalidStateException("Attempted to call Koala reset after delete."); } KoalaNative.reset(handle); } /** * Getter for required number of audio samples per frame. * * @return Required number of audio samples per frame. */ public int getFrameLength() { return KoalaNative.getFrameLength(); } /** * Getter for required audio sample rate for PCM data. * * @return Required audio sample rate for PCM data. */ public int getSampleRate() { return KoalaNative.getSampleRate(); } /** * Getter for Koala version. * * @return Koala version. */ public String getVersion() { return KoalaNative.getVersion(); } /** * Getter for Koala delaySample. * * @return Koala process delay in number of samples. */ public int getDelaySample() throws KoalaException { return KoalaNative.delaySample(handle); } /** * Builder for creating an instance of Koala with a mixture of default arguments. */ public static class Builder { private String accessKey = null; private String modelPath = null; /** * Setter for the AccessKey. * * @param accessKey AccessKey obtained from Picovoice Console */ public Builder setAccessKey(String accessKey) { this.accessKey = accessKey; return this; } /** * Setter for the absolute path to the file containing Koala model parameters. * * @param modelPath Absolute path to the file containing Koala model parameters. */ public Builder setModelPath(String modelPath) { this.modelPath = modelPath; return this; } /** * Creates an instance of Koala noise suppression engine. * * @param context Android app context * @return An instance of Koala noise suppression engine * @throws KoalaException if there is an error while initializing Koala. */ public Koala build(Context context) throws KoalaException { if (accessKey == null || this.accessKey.equals("")) { throw new KoalaInvalidArgumentException("No AccessKey was provided to Koala"); } if (modelPath == null) { if (defaultModelPath == null) { extractPackageResources(context); } modelPath = defaultModelPath; } else { File modelFile = new File(modelPath); String modelFilename = modelFile.getName(); if (!modelFile.exists() && !modelFilename.equals("")) { try { modelPath = extractResource(context, context.getAssets().open(modelPath), modelFilename); } catch (IOException ex) { throw new KoalaIOException(ex); } } } return new Koala(accessKey, modelPath); } } }
0
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala/KoalaNative.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.koala; class KoalaNative { static native String getVersion(); static native int getFrameLength(); static native int getSampleRate(); static native void setSdk(String sdk); static native long init(String accessKey, String modelPath) throws KoalaException; static native void delete(long object); static native short[] process(long object, short[] pcm) throws KoalaException; static native void reset(long object) throws KoalaException; static native int delaySample(long object) throws KoalaException; }
0
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala/exception/KoalaActivationException.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.koala; public class KoalaActivationException extends KoalaException { public KoalaActivationException(Throwable cause) { super(cause); } public KoalaActivationException(String message) { super(message); } public KoalaActivationException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala/exception/KoalaActivationLimitException.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.koala; public class KoalaActivationLimitException extends KoalaException { public KoalaActivationLimitException(Throwable cause) { super(cause); } public KoalaActivationLimitException(String message) { super(message); } public KoalaActivationLimitException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala/exception/KoalaActivationRefusedException.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.koala; public class KoalaActivationRefusedException extends KoalaException { public KoalaActivationRefusedException(Throwable cause) { super(cause); } public KoalaActivationRefusedException(String message) { super(message); } public KoalaActivationRefusedException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala/exception/KoalaActivationThrottledException.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.koala; public class KoalaActivationThrottledException extends KoalaException { public KoalaActivationThrottledException(Throwable cause) { super(cause); } public KoalaActivationThrottledException(String message) { super(message); } public KoalaActivationThrottledException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala/exception/KoalaException.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.koala; public class KoalaException extends Exception { private final String message; private final String[] messageStack; public KoalaException(Throwable cause) { super(cause); this.message = cause.getMessage(); this.messageStack = null; } public KoalaException(String message) { super(message); this.message = message; this.messageStack = null; } public KoalaException(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(); } }
0
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala/exception/KoalaIOException.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.koala; public class KoalaIOException extends KoalaException { public KoalaIOException(Throwable cause) { super(cause); } public KoalaIOException(String message) { super(message); } public KoalaIOException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala/exception/KoalaInvalidArgumentException.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.koala; public class KoalaInvalidArgumentException extends KoalaException { public KoalaInvalidArgumentException(Throwable cause) { super(cause); } public KoalaInvalidArgumentException(String message) { super(message); } public KoalaInvalidArgumentException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala/exception/KoalaInvalidStateException.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.koala; public class KoalaInvalidStateException extends KoalaException { public KoalaInvalidStateException(Throwable cause) { super(cause); } public KoalaInvalidStateException(String message) { super(message); } public KoalaInvalidStateException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala/exception/KoalaKeyException.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.koala; public class KoalaKeyException extends KoalaException { public KoalaKeyException(Throwable cause) { super(cause); } public KoalaKeyException(String message) { super(message); } public KoalaKeyException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala/exception/KoalaMemoryException.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.koala; public class KoalaMemoryException extends KoalaException { public KoalaMemoryException(Throwable cause) { super(cause); } public KoalaMemoryException(String message) { super(message); } public KoalaMemoryException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala/exception/KoalaRuntimeException.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.koala; public class KoalaRuntimeException extends KoalaException { public KoalaRuntimeException(Throwable cause) { super(cause); } public KoalaRuntimeException(String message) { super(message); } public KoalaRuntimeException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala
java-sources/ai/picovoice/koala-android/2.0.1/ai/picovoice/koala/exception/KoalaStopIterationException.java
/* Copyright 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 limitations under the License. */ package ai.picovoice.koala; public class KoalaStopIterationException extends KoalaException { public KoalaStopIterationException(Throwable cause) { super(cause); } public KoalaStopIterationException(String message) { super(message); } public KoalaStopIterationException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard/Leopard.java
/* 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 limitations under the License. */ package ai.picovoice.leopard; import android.content.Context; import android.text.TextUtils; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; /** * Android binding for Leopard Speech-to-Text engine. */ public class Leopard { private static final String[] VALID_EXTENSIONS = { "3gp", "flac", "m4a", "mp3", "mp4", "ogg", "opus", "vorbis", "wav", "webm" }; static { System.loadLibrary("pv_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, boolean enableDiarization) throws LeopardException { LeopardNative.setSdk(Leopard._sdk); handle = LeopardNative.init( accessKey, modelPath, enableAutomaticPunctuation, enableDiarization); } private static String extractResource( Context context, InputStream srcFileStream, String dstFilename) throws IOException { InputStream is = new BufferedInputStream( srcFileStream, 256); OutputStream os = new BufferedOutputStream( context.openFileOutput(dstFilename, Context.MODE_PRIVATE), 256); int r; while ((r = is.read()) != -1) { os.write(r); } os.flush(); is.close(); os.close(); return new File(context.getFilesDir(), dstFilename).getAbsolutePath(); } /** * Releases resources acquired by Leopard. */ public void delete() { if (handle != 0) { LeopardNative.delete(handle); handle = 0; } } /** * Processes given audio data and returns its transcription. * * @param pcm A frame of audio samples. The incoming audio needs to have a sample rate * equal to {@link #getSampleRate()} and be 16-bit linearly-encoded. Furthermore, * Leopard operates on single channel audio. If you wish to process data in a different * sample rate or format consider using `.process_file`. * @return LeopardTranscript object which contains the transcription results of the engine. * @throws LeopardException if there is an error while processing the audio frame. */ public LeopardTranscript process(short[] pcm) throws LeopardException { if (handle == 0) { throw new LeopardInvalidStateException("Attempted to call Leopard process after delete."); } if (pcm == null) { throw new LeopardInvalidArgumentException("Passed null frame to Leopard process."); } return LeopardNative.process(handle, pcm, pcm.length); } /** * Processes given audio data and returns its transcription. * * @param path Absolute path to the audio file. The supported formats are: * `3gp (AMR)`, `FLAC`, `MP3`, `MP4/m4a (AAC)`, `Ogg`, `WAV` and `WebM`. * @return LeopardTranscript object which contains the transcription results of the engine. * @throws LeopardException if there is an error while processing the audio frame. */ public LeopardTranscript processFile(String path) throws LeopardException { if (handle == 0) { throw new LeopardInvalidStateException("Attempted to call Leopard processFile after delete."); } if (path == null || path.equals("")) { throw new LeopardInvalidArgumentException("Passed null path to Leopard processFile."); } try { return LeopardNative.processFile(handle, path); } catch (LeopardInvalidArgumentException e) { boolean endsWithValidExt = false; for (String ext : VALID_EXTENSIONS) { if (path.endsWith(ext)) { endsWithValidExt = true; break; } } if (!endsWithValidExt) { throw new LeopardInvalidArgumentException( String.format( "Specified file '%s' does not have an accepted file extension. " + "Valid extensions are: %s", path, TextUtils.join(", ", VALID_EXTENSIONS))); } throw e; } } /** * Getter for required audio sample rate for PCM data. * * @return Required audio sample rate for PCM data. */ public int getSampleRate() { return LeopardNative.getSampleRate(); } /** * Getter for Leopard version. * * @return Leopard version. */ public String getVersion() { return LeopardNative.getVersion(); } /** * Builder for creating an instance of Leopard with a mixture of default arguments. */ public static class Builder { private String accessKey = null; private String modelPath = null; private boolean enableAutomaticPunctuation = false; private boolean enableDiarization = false; /** * Setter the AccessKey. * * @param accessKey AccessKey obtained from Picovoice Console */ public Builder setAccessKey(String accessKey) { this.accessKey = accessKey; return this; } /** * Setter for the absolute path to the file containing Leopard model parameters. * * @param modelPath Absolute path to the file containing Leopard model parameters. */ public Builder setModelPath(String modelPath) { this.modelPath = modelPath; return this; } /** * Setter for enabling automatic punctuation insertion. * * @param enableAutomaticPunctuation Set to `true` to enable automatic punctuation insertion. */ public Builder setEnableAutomaticPunctuation(boolean enableAutomaticPunctuation) { this.enableAutomaticPunctuation = 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. */ public Leopard build(Context context) throws LeopardException { if (accessKey == null || this.accessKey.equals("")) { throw new LeopardInvalidArgumentException("No AccessKey was provided to Leopard"); } if (modelPath == null) { throw new LeopardInvalidArgumentException("ModelPath must not be null"); } else { File modelFile = new File(modelPath); String modelFilename = modelFile.getName(); if (!modelFile.exists() && !modelFilename.equals("")) { try { modelPath = extractResource(context, context.getAssets().open(modelPath), modelFilename); } catch (IOException ex) { throw new LeopardIOException(ex); } } } return new Leopard( accessKey, modelPath, enableAutomaticPunctuation, enableDiarization); } } }
0
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard/LeopardNative.java
/* 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 limitations under the License. */ package ai.picovoice.leopard; class LeopardNative { static native String getVersion(); static native int getSampleRate(); static native void setSdk(String sdk); static native long init( String accessKey, String modelPath, boolean enableAutomaticPunctuation, boolean enableDiarization) throws LeopardException; static native void delete(long object); static native LeopardTranscript process( long object, short[] pcm, int numSamples) throws LeopardException; static native LeopardTranscript processFile( long object, String path) throws LeopardException; }
0
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard/LeopardTranscript.java
/* 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 limitations under the License. */ package ai.picovoice.leopard; /** * LeopardTranscript Class. */ public class LeopardTranscript { private final String transcriptString; private final Word[] wordArray; /** * Constructor. * * @param transcriptString Inferred transcription. * @param wordArray Transcribed words and their associated metadata. */ public LeopardTranscript(String transcriptString, Word[] wordArray) { this.transcriptString = transcriptString; this.wordArray = wordArray; } /** * Getter for the inferred transcription. * * @return Inferred transcription. */ public String getTranscriptString() { return transcriptString; } /** * Getter for transcribed words and their associated metadata. * * @return Transcribed words and their associated metadata. */ public Word[] getWordArray() { return wordArray; } /** * 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. * * @param word Transcribed 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, int speakerTag ) { this.word = word; this.confidence = confidence; this.startSec = startSec; this.endSec = endSec; this.speakerTag = speakerTag; } /** * Getter for the transcribed word. * * @return Transcribed word. */ public String getWord() { return word; } /** * Getter for the transcription confidence. * * @return Transcription confidence. It is a number within [0, 1]. */ public float getConfidence() { return confidence; } /** * Getter for the start of word in seconds. * * @return Start of word in seconds. */ public float getStartSec() { return startSec; } /** * Getter for the end of word in seconds. * * @return End of word in seconds. */ public float getEndSec() { return endSec; } /** * Getter for the speaker tag. * * @return Speaker tag. */ public int getSpeakerTag() { return speakerTag; } } }
0
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard/exception/LeopardActivationException.java
/* 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 limitations under the License. */ package ai.picovoice.leopard; public class LeopardActivationException extends LeopardException { public LeopardActivationException(Throwable cause) { super(cause); } public LeopardActivationException(String message) { super(message); } public LeopardActivationException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard/exception/LeopardActivationLimitException.java
/* 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 limitations under the License. */ package ai.picovoice.leopard; public class LeopardActivationLimitException extends LeopardException { public LeopardActivationLimitException(Throwable cause) { super(cause); } public LeopardActivationLimitException(String message) { super(message); } public LeopardActivationLimitException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard/exception/LeopardActivationRefusedException.java
/* 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 limitations under the License. */ package ai.picovoice.leopard; public class LeopardActivationRefusedException extends LeopardException { public LeopardActivationRefusedException(Throwable cause) { super(cause); } public LeopardActivationRefusedException(String message) { super(message); } public LeopardActivationRefusedException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard/exception/LeopardActivationThrottledException.java
/* 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 limitations under the License. */ package ai.picovoice.leopard; public class LeopardActivationThrottledException extends LeopardException { public LeopardActivationThrottledException(Throwable cause) { super(cause); } public LeopardActivationThrottledException(String message) { super(message); } public LeopardActivationThrottledException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard/exception/LeopardException.java
/* 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 limitations under the License. */ 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(); } }
0
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard/exception/LeopardIOException.java
/* 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 limitations under the License. */ package ai.picovoice.leopard; public class LeopardIOException extends LeopardException { public LeopardIOException(Throwable cause) { super(cause); } public LeopardIOException(String message) { super(message); } public LeopardIOException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard/exception/LeopardInvalidArgumentException.java
/* 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 limitations under the License. */ package ai.picovoice.leopard; public class LeopardInvalidArgumentException extends LeopardException { public LeopardInvalidArgumentException(Throwable cause) { super(cause); } public LeopardInvalidArgumentException(String message) { super(message); } public LeopardInvalidArgumentException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard/exception/LeopardInvalidStateException.java
/* 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 limitations under the License. */ package ai.picovoice.leopard; public class LeopardInvalidStateException extends LeopardException { public LeopardInvalidStateException(Throwable cause) { super(cause); } public LeopardInvalidStateException(String message) { super(message); } public LeopardInvalidStateException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard/exception/LeopardKeyException.java
/* 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 limitations under the License. */ package ai.picovoice.leopard; public class LeopardKeyException extends LeopardException { public LeopardKeyException(Throwable cause) { super(cause); } public LeopardKeyException(String message) { super(message); } public LeopardKeyException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard/exception/LeopardMemoryException.java
/* 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 limitations under the License. */ package ai.picovoice.leopard; public class LeopardMemoryException extends LeopardException { public LeopardMemoryException(Throwable cause) { super(cause); } public LeopardMemoryException(String message) { super(message); } public LeopardMemoryException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard/exception/LeopardRuntimeException.java
/* 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 limitations under the License. */ package ai.picovoice.leopard; public class LeopardRuntimeException extends LeopardException { public LeopardRuntimeException(Throwable cause) { super(cause); } public LeopardRuntimeException(String message) { super(message); } public LeopardRuntimeException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard
java-sources/ai/picovoice/leopard-android/2.0.2/ai/picovoice/leopard/exception/LeopardStopIterationException.java
/* 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 limitations under the License. */ package ai.picovoice.leopard; public class LeopardStopIterationException extends LeopardException { public LeopardStopIterationException(Throwable cause) { super(cause); } public LeopardStopIterationException(String message) { super(message); } public LeopardStopIterationException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/leopard-java/2.0.4/ai/picovoice
java-sources/ai/picovoice/leopard-java/2.0.4/ai/picovoice/leopard/Leopard.java
/* 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 limitations under the License. */ package ai.picovoice.leopard; import java.io.File; import java.util.List; /** * Class for the Leopard Speech-to-Text engine. */ public class Leopard { public static final String LIBRARY_PATH; public static final String MODEL_PATH; public static final List<String> VALID_EXTENSIONS; private static String sdk = "java"; static { LIBRARY_PATH = Utils.getPackagedLibraryPath(); MODEL_PATH = Utils.getPackagedModelPath(); VALID_EXTENSIONS = Utils.getValidFileExtensions(); } private long handle; /** * Constructor. * * @param accessKey AccessKey obtained from Picovoice Console * @param modelPath Absolute path to the file containing Leopard model parameters. * @param libraryPath Absolute path to the native Leopard library. * @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 `speakerTag` to identify unique speakers. * @throws LeopardException if there is an error while initializing Leopard. */ private Leopard( String accessKey, String modelPath, String libraryPath, boolean enableAutomaticPunctuation, boolean enableDiarization) throws LeopardException { try { System.load(libraryPath); } catch (Exception exception) { throw new LeopardException(exception); } LeopardNative.setSdk(Leopard.sdk); handle = LeopardNative.init( accessKey, modelPath, enableAutomaticPunctuation, enableDiarization); } public static void setSdk(String sdk) { Leopard.sdk = sdk; } /** * Releases resources acquired by Leopard. */ public void delete() { if (handle != 0) { LeopardNative.delete(handle); handle = 0; } } /** * Processes given audio data and returns its transcription. * * @param pcm A frame of audio samples. The incoming audio needs to have a sample rate * equal to {@link #getSampleRate()} and be 16-bit linearly-encoded. Furthermore, * Leopard operates on single channel audio only. * @return LeopardTranscript object which contains the transcription results of the engine. * @throws LeopardException if there is an error while processing the audio frame. */ public LeopardTranscript process(short[] pcm) throws LeopardException { if (handle == 0) { throw new LeopardInvalidStateException("Attempted to call Leopard process after delete."); } if (pcm == null) { throw new LeopardInvalidArgumentException("Passed null frame to Leopard process."); } return LeopardNative.process(handle, pcm, pcm.length); } /** * Processes given audio file and returns its transcription. * * @param path Absolute path to the audio file. The supported formats are: * `3gp (AMR)`, `FLAC`, `MP3`, `MP4/m4a (AAC)`, `Ogg`, `WAV`, `WebM` * @return LeopardTranscript object which contains the transcription results of the engine. * @throws LeopardException if there is an error while processing the audio frame. */ public LeopardTranscript processFile(String path) throws LeopardException { if (handle == 0) { throw new LeopardInvalidStateException("Attempted to call Leopard processFile after delete."); } if (path == null || path.equals("")) { throw new LeopardInvalidArgumentException("Passed null path to Leopard processFile."); } try { return LeopardNative.processFile(handle, path); } catch (LeopardInvalidArgumentException e) { if (path.contains(".")) { String extension = path.substring(path.lastIndexOf(".") + 1).toLowerCase(); if (!VALID_EXTENSIONS.contains(extension)) { throw new LeopardInvalidArgumentException( String.format("Specified file with extension '%s' is not supported", extension)); } } throw e; } } /** * Getter for required audio sample rate for PCM data. * * @return Required audio sample rate for PCM data. */ public int getSampleRate() { return LeopardNative.getSampleRate(); } /** * Getter for Leopard version. * * @return Leopard version. */ public String getVersion() { return LeopardNative.getVersion(); } /** * Builder for creating an instance of Leopard with a mixture of default arguments. */ public static class Builder { private String accessKey = null; private String libraryPath = null; private String modelPath = null; private boolean enableAutomaticPunctuation = false; private boolean enableDiarization = false; /** * Setter the AccessKey. * * @param accessKey AccessKey obtained from Picovoice Console */ public Builder setAccessKey(String accessKey) { this.accessKey = accessKey; return this; } /** * Setter for the absolute path to the file containing Leopard library. * * @param libraryPath Absolute path to the Leopard library. */ public Builder setLibraryPath(String libraryPath) { this.libraryPath = libraryPath; return this; } /** * Setter for the absolute path to the file containing Leopard model parameters. * * @param modelPath Absolute path to the file containing Leopard model parameters. */ public Builder setModelPath(String modelPath) { this.modelPath = modelPath; return this; } /** * Setter for enabling automatic punctuation insertion. * * @param enableAutomaticPunctuation Set to `true` to enable automatic punctuation insertion. */ public Builder setEnableAutomaticPunctuation(boolean enableAutomaticPunctuation) { this.enableAutomaticPunctuation = 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 `speakerTag` to identify unique speakers. */ public Builder setEnableDiarization(boolean enableDiarization) { this.enableDiarization = enableDiarization; return this; } /** * Creates an instance of Leopard Speech-to-Text engine. */ public Leopard build() throws LeopardException { if (!Utils.isEnvironmentSupported()) { throw new LeopardRuntimeException( "Could not initialize Leopard. " + "Execution environment not currently supported by Leopard Java."); } if (accessKey == null) { throw new LeopardInvalidArgumentException("AccessKey must not be null"); } if (libraryPath == null) { if (Utils.isResourcesAvailable()) { libraryPath = LIBRARY_PATH; } else { throw new LeopardInvalidArgumentException( "Default library unavailable. Please " + "provide a native Leopard library path (-l <library_path>)."); } if (libraryPath == null || !new File(libraryPath).exists()) { throw new LeopardIOException( String.format( "Couldn't find library file at " + "'%s'", libraryPath)); } } if (modelPath == null) { if (Utils.isResourcesAvailable()) { modelPath = MODEL_PATH; } else { throw new LeopardInvalidArgumentException( "Default model unavailable. Please provide a " + "valid Leopard model path (-m <model_path>)."); } if (!new File(modelPath).exists()) { throw new LeopardIOException(String.format("Couldn't find model file at " + "'%s'", modelPath)); } } return new Leopard( accessKey, modelPath, libraryPath, enableAutomaticPunctuation, enableDiarization); } } }
0
java-sources/ai/picovoice/leopard-java/2.0.4/ai/picovoice
java-sources/ai/picovoice/leopard-java/2.0.4/ai/picovoice/leopard/LeopardNative.java
/* 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 limitations under the License. */ package ai.picovoice.leopard; class LeopardNative { static native int getSampleRate(); static native String getVersion(); static native void setSdk(String sdk); static native long init( String accessKey, String modelPath, boolean enableAutomaticPunctuation, boolean enableDiarization) throws LeopardException; static native void delete(long object); static native LeopardTranscript process( long object, short[] pcm, int numSamples) throws LeopardException; static native LeopardTranscript processFile( long object, String path) throws LeopardException; }
0
java-sources/ai/picovoice/leopard-java/2.0.4/ai/picovoice
java-sources/ai/picovoice/leopard-java/2.0.4/ai/picovoice/leopard/LeopardTranscript.java
/* 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 limitations under the License. */ package ai.picovoice.leopard; /** * Class that contains transcription results returned from Leopard. */ public class LeopardTranscript { private final String transcriptString; private final Word[] wordArray; /** * Constructor. * * @param transcriptString Inferred transcription. * @param wordArray Transcribed words and their associated metadata. */ public LeopardTranscript(String transcriptString, Word[] wordArray) { this.transcriptString = transcriptString; this.wordArray = wordArray; } /** * Getter for the inferred transcription. * * @return Inferred transcription. */ public String getTranscriptString() { return transcriptString; } /** * Getter for transcribed words and their associated metadata. * * @return Transcribed words and their associated metadata. */ public Word[] getWordArray() { return wordArray; } /** * Class for storing word metadata. */ 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. * * @param word Transcribed 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, int speakerTag) { this.word = word; this.confidence = confidence; this.startSec = startSec; this.endSec = endSec; this.speakerTag = speakerTag; } /** * Getter for the transcribed word. * * @return Transcribed word. */ public String getWord() { return word; } /** * Getter for the transcription confidence. * * @return Transcription confidence. It is a number within [0, 1]. */ public float getConfidence() { return confidence; } /** * Getter for the start of word in seconds. * * @return Start of word in seconds. */ public float getStartSec() { return startSec; } /** * Getter for the end of word in seconds. * * @return End of word in seconds. */ public float getEndSec() { return endSec; } /** * Getter for the speaker tag. * * @return Speaker tag. */ public int getSpeakerTag() { return speakerTag; } } }
0
java-sources/ai/picovoice/leopard-java/2.0.4/ai/picovoice
java-sources/ai/picovoice/leopard-java/2.0.4/ai/picovoice/leopard/Utils.java
/* Copyright 2022-2024 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 limitations under the License. */ package ai.picovoice.leopard; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.Arrays; import java.util.Enumeration; import java.util.List; import java.util.Locale; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.logging.Logger; class Utils { private static final Path RESOURCE_DIRECTORY; private static final String ENVIRONMENT_NAME; private static final String ARCHITECTURE; private static final Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); static { RESOURCE_DIRECTORY = getResourceDirectory(); ENVIRONMENT_NAME = getEnvironmentName(); ARCHITECTURE = getArchitecture(); } public static boolean isResourcesAvailable() { return RESOURCE_DIRECTORY != null; } public static boolean isEnvironmentSupported() { return ENVIRONMENT_NAME != null; } private static Path getResourceDirectory() throws RuntimeException { // location of resources, either a JAR file or a directory final URL resourceURL = Leopard.class.getProtectionDomain().getCodeSource().getLocation(); Path resourcePath; try { resourcePath = Paths.get(resourceURL.toURI()); } catch (URISyntaxException e) { resourcePath = Paths.get(resourceURL.getPath()); } if (resourcePath.toString().endsWith(".jar")) { try { resourcePath = extractResources(resourcePath); } catch (IOException e) { throw new RuntimeException("Failed to extract resources from Leopard jar."); } } return resourcePath.resolve("leopard"); } private static Path extractResources(Path jarPath) throws IOException { // use jar name to create versioned extraction directory String extractionDirName = jarPath.getFileName().toString().replace(".jar", ""); // extract jar resources to temp directory String systemTempDir = System.getProperty("java.io.tmpdir"); Path resourceDirectoryPath = new File(systemTempDir, extractionDirName).toPath(); // try to create tmp dir for extraction if (!Files.exists(resourceDirectoryPath)) { try { Files.createDirectory(resourceDirectoryPath); } catch (IOException e) { logger.severe("Failed to create extraction directory at " + jarPath.toString()); e.printStackTrace(); // default extraction directly to tmp resourceDirectoryPath = new File(systemTempDir).toPath(); } } // read jar file entries JarFile jf = new JarFile(jarPath.toFile()); Enumeration<JarEntry> entries = jf.entries(); while (entries.hasMoreElements()) { JarEntry jarEntry = entries.nextElement(); String jarEntryName = jarEntry.getName(); if (jarEntryName.startsWith("leopard")) { // copy contents into resource directory if (jarEntry.isDirectory()) { Path dstPath = resourceDirectoryPath.resolve(jarEntryName); if (!dstPath.toFile().exists()) { Files.createDirectory(dstPath); } } else { Path file = resourceDirectoryPath.resolve(jarEntryName); try (InputStream is = jf.getInputStream(jarEntry)) { Files.copy(is, file, StandardCopyOption.REPLACE_EXISTING); } } } } return resourceDirectoryPath; } public static String getEnvironmentName() throws RuntimeException { String os = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH); if (os.contains("mac") || os.contains("darwin")) { return "mac"; } else if (os.contains("win")) { return "windows"; } else if (os.contains("linux")) { String arch = System.getProperty("os.arch"); if (arch.equals("arm") || arch.equals("aarch64")) { String cpuPart = getCpuPart(); switch (cpuPart) { case "0xd03": case "0xd08": case "0xd0b": return "raspberry-pi"; default: throw new RuntimeException(String.format("Execution environment not supported. " + "Leopard Java does not support CPU Part (%s).", cpuPart)); } } return "linux"; } else { throw new RuntimeException("Execution environment not supported. " + "Leopard Java is supported on MacOS, Linux and Windows"); } } private static String getArchitecture() throws RuntimeException { String arch = System.getProperty("os.arch"); boolean isArm = arch.equals("arm") || arch.equals("aarch64"); boolean isX86_64 = arch.equals("amd64") || arch.equals("x86_64"); if (ENVIRONMENT_NAME.equals("mac")) { if (isArm) { return "arm64"; } else if (isX86_64) { return "x86_64"; } } else if (ENVIRONMENT_NAME.equals("windows")) { if (isX86_64) { return "amd64"; } else if (isArm) { return "arm64"; } } else if (ENVIRONMENT_NAME.equals("linux")) { if (isX86_64) { return "x86_64"; } } else if (isArm) { // RPI String cpuPart = getCpuPart(); String archInfo = (arch.equals("aarch64")) ? "-aarch64" : ""; switch (cpuPart) { case "0xd03": return "cortex-a53" + archInfo; case "0xd08": return "cortex-a72" + archInfo; case "0xd0b": return "cortex-a76" + archInfo; default: throw new RuntimeException( String.format( "Environment (%s) with CPU Part (%s) is not supported by Leopard.", ENVIRONMENT_NAME, cpuPart) ); } } throw new RuntimeException( String.format( "Environment (%s) with architecture (%s) is not supported by Leopard.", ENVIRONMENT_NAME, arch) ); } private static String getCpuPart() throws RuntimeException { try { return Files.lines(Paths.get("/proc/cpuinfo")) .filter(line -> line.startsWith("CPU part")) .map(line -> line.substring(line.lastIndexOf(" ") + 1)) .findFirst() .orElse(""); } catch (IOException e) { throw new RuntimeException("Leopard failed to get get CPU information."); } } public static String getPackagedModelPath() { return RESOURCE_DIRECTORY.resolve("lib/common/leopard_params.pv").toString(); } public static String getPackagedLibraryPath() { switch (ENVIRONMENT_NAME) { case "windows": return RESOURCE_DIRECTORY.resolve("lib/java/windows") .resolve(ARCHITECTURE) .resolve("libpv_leopard_jni.dll").toString(); case "mac": return RESOURCE_DIRECTORY.resolve("lib/java/mac") .resolve(ARCHITECTURE) .resolve("libpv_leopard_jni.dylib").toString(); case "raspberry-pi": case "linux": return RESOURCE_DIRECTORY.resolve("lib/java") .resolve(ENVIRONMENT_NAME) .resolve(ARCHITECTURE) .resolve("libpv_leopard_jni.so").toString(); default: return null; } } public static List<String> getValidFileExtensions() { return Arrays.asList( "3gp", "flac", "m4a", "mp3", "mp4", "ogg", "opus", "vorbis", "wav", "webm"); } }
0
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus/Octopus.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.octopus; import android.content.Context; import android.content.res.Resources; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.HashMap; import java.util.HashSet; /** * Android binding for Octopus Speech-to-Index engine. It transforms audio into searchable metadata. */ public class Octopus { private static String defaultModelPath; private static String _sdk = "android"; private long handle; static { System.loadLibrary("pv_octopus"); } public static void setSdk(String sdk) { Octopus._sdk = sdk; } /** * Constructor. * * @param accessKey AccessKey obtained from Picovoice Console * @param modelPath Absolute path to the file containing Octopus model parameters. * @throws OctopusException if there is an error while initializing Octopus. */ private Octopus(String accessKey, String modelPath) throws OctopusException { OctopusNative.setSdk(Octopus._sdk); handle = OctopusNative.init(accessKey, modelPath); } private static void extractPackageResources(Context context) throws OctopusException { final Resources resources = context.getResources(); try { defaultModelPath = extractResource(context, resources.openRawResource(R.raw.octopus_params), resources.getResourceEntryName(R.raw.octopus_params) + ".pv"); } catch (IOException ex) { throw new OctopusIOException(ex); } } private static String extractResource( Context context, InputStream srcFileStream, String dstFilename ) throws IOException { InputStream is = new BufferedInputStream(srcFileStream, 256); OutputStream os = new BufferedOutputStream(context.openFileOutput(dstFilename, Context.MODE_PRIVATE), 256); int r; while ((r = is.read()) != -1) { os.write(r); } os.flush(); is.close(); os.close(); return new File(context.getFilesDir(), dstFilename).getAbsolutePath(); } /** * Releases resources acquired by Octopus. */ public void delete() { if (handle != 0) { OctopusNative.delete(handle); handle = 0; } } /** * Indexes raw PCM data. * * @param pcm An array of audio samples. The audio needs to have a sample rate * equal to {@link #getPcmDataSampleRate()} and be single-channel, 16-bit linearly-encoded. * @return OctopusMetadata object that is used to perform searches. * @throws OctopusException if there is an error while processing the audio data. */ public OctopusMetadata indexAudioData(short[] pcm) throws OctopusException { if (handle == 0) { throw new OctopusInvalidStateException("Attempted to call Octopus index after delete."); } if (pcm == null) { throw new OctopusInvalidArgumentException("Passed null frame to Octopus index."); } return new OctopusMetadata(OctopusNative.index(handle, pcm, pcm.length)); } /** * Reads and indexes a given audio file. * * @param path Absolute path to an audio file. * @return OctopusMetadata object that is used to perform searches. * @throws OctopusException if there is an error while processing the audio data. */ public OctopusMetadata indexAudioFile(String path) throws OctopusException { if (handle == 0) { throw new OctopusInvalidStateException("Attempted to call Octopus index after delete."); } if (path == null || path.equals("")) { throw new OctopusInvalidArgumentException("Passed empty path to Octopus index."); } File audioFile = new File(path); if (!audioFile.exists()) { throw new OctopusInvalidArgumentException( String.format("No valid audio file found at '%s'", path)); } return new OctopusMetadata(OctopusNative.indexFile(handle, path)); } /** * Searches metadata for a given set of phrases. * * @param metadata An OctopusMetadata object obtained via {@link #indexAudioData(short[])} or * {@link #indexAudioFile(String)}. * @param phrases A set of phrases to search for in the metadata. * @return a map of phrases and match arrays. Matches are represented by immutable OctopusMatch objects. * @throws OctopusException if there is an error while performing the search query. */ public HashMap<String, OctopusMatch[]> search( OctopusMetadata metadata, HashSet<String> phrases) throws OctopusException { if (handle == 0) { throw new OctopusInvalidStateException("Attempted to call Octopus search after delete."); } HashMap<String, OctopusMatch[]> searchResults = new HashMap<>(); for (String phrase : phrases) { final StringBuilder formattedPhraseBuilder = new StringBuilder(); for (String word : phrase.trim().split("\\s+")) { formattedPhraseBuilder.append(word).append(" "); } final String formattedPhrase = formattedPhraseBuilder.toString().trim(); if (formattedPhrase.isEmpty()) { throw new OctopusInvalidArgumentException("Search phrase cannot be empty"); } OctopusMatch[] searchResult = OctopusNative.search( handle, metadata.metadataNative.handle, metadata.metadataNative.numBytes, formattedPhrase); searchResults.put(formattedPhrase, searchResult); } return searchResults; } /** * Getter for required audio sample rate for PCM data. * * @return Required audio sample rate for PCM data. */ public int getPcmDataSampleRate() { return OctopusNative.getPcmDataSampleRate(); } /** * Getter for Octopus version. * * @return Octopus version. */ public String getVersion() { return OctopusNative.getVersion(); } /** * Builder for creating an instance of Octopus with a mixture of default arguments. */ public static class Builder { private String accessKey = null; private String modelPath = null; public Builder setAccessKey(String accessKey) { this.accessKey = accessKey; return this; } public Builder setModelPath(String modelPath) { this.modelPath = modelPath; return this; } /** * Creates an instance of Octopus Speech-to-Index engine. */ public Octopus build(Context context) throws OctopusException { if (accessKey == null || this.accessKey.equals("")) { throw new OctopusInvalidArgumentException("No AccessKey was provided to Octopus"); } if (modelPath == null) { if (defaultModelPath == null) { extractPackageResources(context); } modelPath = defaultModelPath; } else { File modelFile = new File(modelPath); String modelFilename = modelFile.getName(); if (!modelFile.exists() && !modelFilename.equals("")) { try { modelPath = extractResource(context, context.getAssets().open(modelPath), modelFilename); } catch (IOException ex) { throw new OctopusIOException(ex); } } } return new Octopus(accessKey, modelPath); } } }
0
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus/OctopusMatch.java
/* Copyright 2021 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 limitations under the License. */ package ai.picovoice.octopus; /** * Class that contains match results returned from Octopus search. */ public class OctopusMatch { private final float startSec; private final float endSec; private final float probability; /** * Constructor. * * @param startSec The starting second of the match word. * @param endSec The ending second of the match word. * @param probability Floating-point value between [0, 1]. */ public OctopusMatch(float startSec, float endSec, float probability) { this.startSec = startSec; this.endSec = endSec; this.probability = probability; } public float getStartSec() { return startSec; } public float getEndSec() { return endSec; } public float getProbability() { return probability; } }
0
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus/OctopusMetadata.java
/* Copyright 2021 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 limitations under the License. */ package ai.picovoice.octopus; /** * Class that contains metadata returned from Octopus index. */ public class OctopusMetadata { static { System.loadLibrary("pv_octopus"); } final OctopusMetadataNative metadataNative; OctopusMetadata(OctopusMetadataNative metadataNative) { this.metadataNative = metadataNative; } /** * Constructor. * * @param metadataBytes a byte array previously obtained via {@link #getBytes()}. */ public OctopusMetadata(byte[] metadataBytes) { metadataNative = new OctopusMetadataNative(metadataBytes); } /** * Gets the metadata in the form of a byte array. * * @return the metadata in the form of a byte array. */ public byte[] getBytes() { return metadataNative.getBytes(); } /** * Releases resources acquired by OctopusMetadata. */ public void delete() { metadataNative.delete(); } }
0
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus/OctopusMetadataNative.java
/* Copyright 2022 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 limitations under the License. */ package ai.picovoice.octopus; class OctopusMetadataNative { final long handle; final int numBytes; OctopusMetadataNative(long handle, int numBytes) { this.handle = handle; this.numBytes = numBytes; } public OctopusMetadataNative(byte[] metadataBytes) { this.handle = setBytesNative(metadataBytes, metadataBytes.length); this.numBytes = metadataBytes.length; } public byte[] getBytes() { return getBytesNative(this.handle, this.numBytes); } public void delete() { deleteNative(this.handle); } private native void deleteNative(long handle); private native byte[] getBytesNative(long handle, int numBytes); private native long setBytesNative(byte[] metadataBytes, int numBytes); }
0
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus/OctopusNative.java
/* 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 limitations under the License. */ package ai.picovoice.octopus; class OctopusNative { static native String getVersion(); static native int getPcmDataSampleRate(); static native void setSdk(String sdk); static native long init( String accessKey, String modelPath) throws OctopusException; static native void delete(long object); static native OctopusMetadataNative index( long object, short[] pcm, int numSamples) throws OctopusException; static native OctopusMetadataNative indexFile( long object, String path) throws OctopusException; static native OctopusMatch[] search( long object, long metadataPtr, int numMetadataBytes, String phrase) throws OctopusException; }
0
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus/exception/OctopusActivationException.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.octopus; public class OctopusActivationException extends OctopusException { public OctopusActivationException(Throwable cause) { super(cause); } public OctopusActivationException(String message) { super(message); } public OctopusActivationException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus/exception/OctopusActivationLimitException.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.octopus; public class OctopusActivationLimitException extends OctopusException { public OctopusActivationLimitException(Throwable cause) { super(cause); } public OctopusActivationLimitException(String message) { super(message); } public OctopusActivationLimitException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus/exception/OctopusActivationRefusedException.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.octopus; public class OctopusActivationRefusedException extends OctopusException { public OctopusActivationRefusedException(Throwable cause) { super(cause); } public OctopusActivationRefusedException(String message) { super(message); } public OctopusActivationRefusedException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus/exception/OctopusActivationThrottledException.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.octopus; public class OctopusActivationThrottledException extends OctopusException { public OctopusActivationThrottledException(Throwable cause) { super(cause); } public OctopusActivationThrottledException(String message) { super(message); } public OctopusActivationThrottledException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus/exception/OctopusException.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.octopus; public class OctopusException extends Exception { private final String message; private final String[] messageStack; public OctopusException(Throwable cause) { super(cause); this.message = cause.getMessage(); this.messageStack = null; } public OctopusException(String message) { super(message); this.message = message; this.messageStack = null; } public OctopusException(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(); } }
0
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus/exception/OctopusIOException.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.octopus; public class OctopusIOException extends OctopusException { public OctopusIOException(Throwable cause) { super(cause); } public OctopusIOException(String message) { super(message); } public OctopusIOException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus/exception/OctopusInvalidArgumentException.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.octopus; public class OctopusInvalidArgumentException extends OctopusException { public OctopusInvalidArgumentException(Throwable cause) { super(cause); } public OctopusInvalidArgumentException(String message) { super(message); } public OctopusInvalidArgumentException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus/exception/OctopusInvalidStateException.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.octopus; public class OctopusInvalidStateException extends OctopusException { public OctopusInvalidStateException(Throwable cause) { super(cause); } public OctopusInvalidStateException(String message) { super(message); } public OctopusInvalidStateException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus/exception/OctopusKeyException.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.octopus; public class OctopusKeyException extends OctopusException { public OctopusKeyException(Throwable cause) { super(cause); } public OctopusKeyException(String message) { super(message); } public OctopusKeyException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus/exception/OctopusMemoryException.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.octopus; public class OctopusMemoryException extends OctopusException { public OctopusMemoryException(Throwable cause) { super(cause); } public OctopusMemoryException(String message) { super(message); } public OctopusMemoryException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus/exception/OctopusRuntimeException.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.octopus; public class OctopusRuntimeException extends OctopusException { public OctopusRuntimeException(Throwable cause) { super(cause); } public OctopusRuntimeException(String message) { super(message); } public OctopusRuntimeException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus
java-sources/ai/picovoice/octopus-android/2.0.2/ai/picovoice/octopus/exception/OctopusStopIterationException.java
/* Copyright 2021-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 limitations under the License. */ package ai.picovoice.octopus; public class OctopusStopIterationException extends OctopusException { public OctopusStopIterationException(Throwable cause) { super(cause); } public OctopusStopIterationException(String message) { super(message); } public OctopusStopIterationException(String message, String[] messageStack) { super(message, messageStack); } }
0
java-sources/ai/picovoice/orca-android/1.2.0/ai/picovoice
java-sources/ai/picovoice/orca-android/1.2.0/ai/picovoice/orca/Orca.java
/* Copyright 2024 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 limitations under the License. */ package ai.picovoice.orca; import android.content.Context; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; /** * Android binding for Orca Text-to-Speech engine. Orca converts text to spoken audio * without network latency. */ public class Orca { private static String _sdk = "android"; static { System.loadLibrary("pv_orca"); } private long handle; private int maxCharacterLimit; private int sampleRate; private String[] validCharacters; /** * OrcaStream object that converts a stream of text to a stream of audio. */ public class OrcaStream { private long stream; public OrcaStream(long stream) { this.stream = stream; } /** * Adds a chunk of text to the Stream object and generates audio if enough text has been added. * This function is expected to be called multiple times with consecutive chunks of text from a text stream. * The incoming text is buffered as it arrives until there is enough context to convert a chunk of the * buffered text into audio. The caller needs to use `OrcaStream.flush()` to generate the audio chunk * for the remaining text that has not yet been synthesized. * * @param text A chunk of text from a text input stream, comprised of valid characters. * Valid characters can be retrieved by calling `.getValidCharacters()`. * Custom pronunciations can be embedded in the text via the syntax `{word|pronunciation}`. * They need to be added in a single call to this function. * The pronunciation is expressed in ARPAbet format, e.g.: `I {liv|L IH V} in {Sevilla|S EH V IY Y AH}`. * @return The generated audio as a sequence of 16-bit linearly-encoded integers, `null` if no * audio chunk has been produced. * @throws OrcaException if there is an error while synthesizing audio. */ public short[] synthesize(String text) throws OrcaException { if (handle == 0) { throw new OrcaInvalidStateException( "Attempted to call OrcaStream synthesize after delete." ); } if (stream == 0) { throw new OrcaInvalidStateException( "Attempted to call OrcaStream synthesize without an open stream." ); } short[] pcm = OrcaNative.streamSynthesize(stream, text); return pcm.length == 0 ? null : pcm; } /** * Generates audio for all the buffered text that was added to the OrcaStream object * via `OrcaStream.synthesize()`. * * @return The generated audio as a sequence of 16-bit linearly-encoded integers, `null` if no * audio chunk has been produced. * @throws OrcaException if there is an error while flushing audio. */ public short[] flush() throws OrcaException { if (handle == 0) { throw new OrcaInvalidStateException( "Attempted to call OrcaStream flush after delete." ); } if (stream == 0) { throw new OrcaInvalidStateException( "Attempted to call OrcaStream flush without an open stream." ); } short[] pcm = OrcaNative.streamFlush(stream); return pcm.length == 0 ? null : pcm; } /** * Releases the resources acquired by the OrcaStream object. */ public void close() { if (handle != 0 && stream != 0) { OrcaNative.streamClose(stream); stream = 0; } } } /** * Constructor. * * @param accessKey AccessKey obtained from Picovoice Console (https://console.picovoice.ai/) * @param modelPath Absolute path to the file containing Orca model parameters. * @throws OrcaException if there is an error while initializing Orca. */ private Orca(String accessKey, String modelPath) throws OrcaException { OrcaNative.setSdk(Orca._sdk); handle = OrcaNative.init( accessKey, modelPath); maxCharacterLimit = OrcaNative.getMaxCharacterLimit(handle); sampleRate = OrcaNative.getSampleRate(handle); validCharacters = OrcaNative.getValidCharacters(handle); } public static void setSdk(String sdk) { Orca._sdk = sdk; } private static String extractResource(Context context, InputStream srcFileStream, String dstFilename) throws IOException { InputStream is = new BufferedInputStream( srcFileStream, 256); OutputStream os = new BufferedOutputStream( context.openFileOutput(dstFilename, Context.MODE_PRIVATE), 256); int r; while ((r = is.read()) != -1) { os.write(r); } os.flush(); is.close(); os.close(); return new File( context.getFilesDir(), dstFilename).getAbsolutePath(); } /** * Releases resources acquired by Orca. */ public void delete() { if (handle != 0) { OrcaNative.delete(handle); handle = 0; } } /** * Generates audio from text. The returned audio contains the speech representation of the text. * * @param text Text to be converted to audio. The maximum length can be attained by calling * `getMaxCharacterLimit()`. Allowed characters can be retrieved by calling * `getValidCharacters()`. Custom pronunciations can be embedded in the text via the * syntax `{word|pronunciation}`. The pronunciation is expressed in ARPAbet format, * e.g.: `I {liv|L IH V} in {Sevilla|S EH V IY Y AH}`. * @param params Global parameters for synthesized text. See 'OrcaSynthesizeParams' for details. * @return An object containing the generated audio as a sequence of 16-bit linearly-encoded integers * and an array of OrcaWord objects representing the word alignments. * @throws OrcaException if there is an error while synthesizing audio. */ public OrcaAudio synthesize(String text, OrcaSynthesizeParams params) throws OrcaException { if (handle == 0) { throw new OrcaInvalidStateException( "Attempted to call Orca synthesize after delete." ); } return OrcaNative.synthesize( handle, text, params.getSpeechRate(), params.getRandomState()); } /** * Generates audio from text and saves it to a file. The file contains the speech * representation of the text. * * @param text Text to be converted to audio. The maximum length can be attained by calling * `getMaxCharacterLimit()`. Allowed characters can be retrieved by calling * `getValidCharacters()`. Custom pronunciations can be embedded in the text via the * syntax `{word|pronunciation}`. The pronunciation is expressed in ARPAbet format, * e.g.: `I {liv|L IH V} in {Sevilla|S EH V IY Y AH}`. * @param outputPath Absolute path to the output audio file. The output file is saved as * `WAV (.wav)` and consists of a single mono channel. * @param params Global parameters for synthesized text. See 'OrcaSynthesizeParams' for details. * @return An array of OrcaWord objects representing the word alignments. * @throws OrcaException if there is an error while synthesizing audio to file. */ public OrcaWord[] synthesizeToFile( String text, String outputPath, OrcaSynthesizeParams params) throws OrcaException { if (handle == 0) { throw new OrcaInvalidStateException( "Attempted to call Orca synthesize after delete." ); } OrcaAudio result = OrcaNative.synthesizeToFile( handle, text, outputPath, params.getSpeechRate(), params.getRandomState()); return result.getWordArray(); } /** * @param params Global parameters for synthesized text. See 'OrcaSynthesizeParams' for details. * @return OrcaStream object. * @throws OrcaException if there is an error while opening OrcaStream. */ public OrcaStream streamOpen(OrcaSynthesizeParams params) throws OrcaException { if (handle == 0) { throw new OrcaInvalidStateException( "Attempted to call Orca streamOpen after delete." ); } long stream = OrcaNative.streamOpen( handle, params.getSpeechRate(), params.getRandomState()); return new OrcaStream(stream); } /** * Getter for version. * * @return Version. */ public String getVersion() { return OrcaNative.getVersion(); } /** * Getter for the maximum number of characters that can be synthesized at once. * * @return The maximum number of characters that can be synthesized at once. */ public int getMaxCharacterLimit() { return maxCharacterLimit; } /** * Getter for the audio sampling rate of the audio produced by Orca. * * @return Audio sampling rate of the audio produced by Orca. */ public int getSampleRate() { return sampleRate; } /** * Getter for the set of characters that are accepted as input to Orca synthesize functions. * * @return Array of characters that are accepted as input to Orca synthesize functions. */ public String[] getValidCharacters() { return validCharacters; } /** * Builder for creating instance of Orca. */ public static class Builder { private String accessKey = null; private String modelPath = null; /** * Sets the AccessKey. * * @param accessKey AccessKey obtained from Picovoice Console (https://console.picovoice.ai/) * @return Modified builder object. */ public Builder setAccessKey(String accessKey) { this.accessKey = accessKey; return this; } /** * Sets the path to the model file (`.pv`). * * @param modelPath Absolute path to the file (`.pv`) containing Orca model parameters. * @return Modified builder object. */ public Builder setModelPath(String modelPath) { this.modelPath = modelPath; return this; } /** * Validates properties and creates an instance of the Orca Text-to-Speech engine. * * @return An instance Orca Text-to-Speech engine * @throws OrcaException if there is an error while initializing Orca. */ public Orca build(Context context) throws OrcaException { if (accessKey == null || this.accessKey.equals("")) { throw new OrcaInvalidArgumentException("No AccessKey was provided to Orca"); } if (modelPath == null) { throw new OrcaInvalidArgumentException("ModelPath must not be null"); } else { File modelFile = new File(modelPath); String modelFilename = modelFile.getName(); if (!modelFile.exists() && !modelFilename.equals("")) { try { modelPath = extractResource( context, context.getAssets().open(modelPath), modelFilename); } catch (IOException ex) { throw new OrcaIOException(ex); } } } return new Orca( accessKey, modelPath); } } }
0
java-sources/ai/picovoice/orca-android/1.2.0/ai/picovoice
java-sources/ai/picovoice/orca-android/1.2.0/ai/picovoice/orca/OrcaAudio.java
/* Copyright 2024 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 limitations under the License. */ package ai.picovoice.orca; public class OrcaAudio { private final short[] pcm; private final OrcaWord[] wordArray; /** * Constructor. * * @param pcm Synthesized audio. * @param wordArray Synthesized words and their associated metadata. */ public OrcaAudio(short[] pcm, OrcaWord[] wordArray) { this.pcm = pcm; this.wordArray = wordArray; } /** * Getter for the synthesized audio. * * @return Synthesized audio. */ public short[] getPcm() { return pcm; } /** * Getter for synthesized words and their associated metadata. * * @return Synthesized words and their associated metadata. */ public OrcaWord[] getWordArray() { return wordArray; } }