12 package ai.picovoice.rhino;
14 import android.content.Context;
15 import android.content.res.Resources;
17 import java.io.BufferedInputStream;
18 import java.io.BufferedOutputStream;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.io.OutputStream;
23 import java.util.LinkedHashMap;
41 System.loadLibrary(
"pv_rhino");
64 boolean requireEndpoint) {
65 handle =
init(accessKey, modelPath, contextPath, sensitivity, requireEndpoint);
71 public void delete() {
100 String.format(
"Rhino process requires frames of length %d. " +
106 }
catch (Exception e) {
128 String[] parts = intentPacked.split(
",");
129 if (parts.length == 0) {
130 throw new RhinoException(String.format(
"Failed to retrieve intent from '%s'.", intentPacked));
133 Map<String, String> slots =
new LinkedHashMap<>();
134 for (
int i = 1; i < parts.length; i++) {
135 String[] slotAndValue = parts[i].split(
":");
136 if (slotAndValue.length != 2) {
137 throw new RhinoException(String.format(
"Failed to retrieve intent from '%s'.", intentPacked));
139 slots.put(slotAndValue[0], slotAndValue[1]);
182 private native
long init(String accessKey, String modelPath, String contextPath,
float sensitivity,
boolean requireEndpoint);
184 private native
void delete(
long object);
186 private native
boolean process(
long object,
short[] pcm);
190 private native String
getIntent(
long object);
192 private native
boolean reset(
long object);
232 final Resources resources =
context.getResources();
236 resources.openRawResource(
R.raw.rhino_params),
237 resources.getResourceEntryName(
R.raw.rhino_params) +
".pv");
240 }
catch (IOException ex) {
246 InputStream is =
new BufferedInputStream(srcFileStream, 256);
247 OutputStream os =
new BufferedOutputStream(
context.openFileOutput(dstFilename, Context.MODE_PRIVATE), 256);
249 while ((r = is.read()) != -1) {
256 return new File(
context.getFilesDir(), dstFilename).getAbsolutePath();
280 String modelFilename = modelFile.getName();
281 if (!modelFile.exists() && !modelFilename.equals(
"")) {
286 }
catch (IOException ex) {
292 if (this.contextPath ==
null) {
297 String contextFilename = contextFile.getName();
298 if (!contextFile.exists() && !contextFilename.equals(
"")) {
303 }
catch (IOException ex) {
308 if (sensitivity < 0 || sensitivity > 1) {