Comments (10)
Win x64
libjni.zip
from porcupine.
this should work across different platforms ...
https://github.com/Picovoice/Porcupine/tree/master/demo/android
from porcupine.
But the binary files it uses are .so, I need .dll files in order to work with windows. Problem is, you can even see that those .so files in that android demo aren't regular, that .so is modified from the original in order to meet the required wrapping, you can see that in the next picture
As you can see, the methods were changed into Java_ai_picovoice_porcupine_Porcupine_method, along with JNICALL, JNIExport, JNIEnv*, etc etc.
In that same sense, I need those binaries but in dll form
from porcupine.
Got it. You don't want an Android build. Just want a JNI interface. I think you can use the ".a" files under lib/windows with your own JNI file and then build a ".dll" from them. Apologies for the confusion.
from porcupine.
I can't seem to modify them in any way, I'll try linking them to another c++ "wrapper program", with the wrapping methods and just a call inside.
from porcupine.
Alright, so after finally being able to build a succesful .dll with a JNI interface, I am encountering this error, which is directly linked to the dll.
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000067641f65, pid=1040, tid=0x0000000000000ee8
#
# JRE version: Java(TM) SE Runtime Environment (8.0_161-b12) (build 1.8.0_161-b12)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.161-b12 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C [libpv_porcupine.dll+0x1f65]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# D:\Programming\Game Development\PorcupineManager\hs_err_pid1040.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
This is how it is being called from Java:
public Porcupine(
String modelFilePath,
String keywordFilePath,
float sensitivity) throws PorcupineException {
numberKeywords = 1;
System.out.println("Sensitivity: "+sensitivity);
System.out.println("Modelfilepath: "+modelFilePath);
System.out.println(keywordFilePath);
System.out.println("==================");
try {
object = init(modelFilePath, new String[]{keywordFilePath}, new float[]{sensitivity});
} catch (Exception e) {
throw new PorcupineException(e);
}
}
And this is in C:
JNIEXPORT jlong JNICALL Java_ai_picovoice_porcupine_Porcupine_init(JNIEnv *env, jobject thisObj, jstring str, jobjectArray objArray, jfloatArray floatArray){
jfloat *body = (*env)->GetFloatArrayElements(env, floatArray, 0);
const char *modelFilePath = (*env)->GetStringUTFChars(env, str, 0);
int modelCount = (*env)->GetArrayLength(env, objArray);
printf("Sensitivity: ");
printf("%f \n", body[0]);
printf("Modelfilepath: %s \n", modelFilePath);
const char *keyfilepaths[modelCount];
for (int i=0; i<modelCount; i++) {
jstring string = (jstring) (*env)->GetObjectArrayElement(env, objArray, i);
const char *keyfilepath = (*env)->GetStringUTFChars(env, string, 0);
keyfilepaths[i] = keyfilepath;
(*env)->ReleaseStringUTFChars(env, string, keyfilepath);
printf("KeywordFile: %s", keyfilepaths[i]);
}
pv_porcupine_multiple_keywords_init(modelFilePath, modelCount, keyfilepaths, body, object);
(*env)->ReleaseFloatArrayElements(env, floatArray, body, 0);
(*env)->ReleaseStringUTFChars(env, str, modelFilePath);
return object;
}
Please help, I seriously don't know anymore.
Here's the error file: https://pastebin.com/kEZ5JA0k
from porcupine.
I put this together, without any knowledge of c/c++. It works, but there is no error handling and there are probably some other mistakes.
It would be nice if Porcupine team shared their implementation of native JNI functions from the Android demo project.
#include "ai_picovoice_porcupine_Porcupine.h"
#include "../include/picovoice.h"
#include "../include/pv_porcupine.h"
#include <jni.h>
#include <string.h>
#include <iostream>
using namespace std;
//TODO: error handling
JNIEXPORT jint JNICALL Java_ai_picovoice_porcupine_Porcupine_getFrameLength(JNIEnv *env, jobject obj) {
return pv_porcupine_frame_length();
}
JNIEXPORT jint JNICALL Java_ai_picovoice_porcupine_Porcupine_getSampleRate(JNIEnv *env, jobject obj) {
return pv_sample_rate();
}
JNIEXPORT jlong JNICALL Java_ai_picovoice_porcupine_Porcupine_init(JNIEnv *env, jobject obj, jstring modelFile, jobjectArray keywordFiles, jfloatArray sensitivities) {
long object = 0;
pv_porcupine_object_t *result = (pv_porcupine_object_t *) &object;
jclass thisClass = env->GetObjectClass(obj);
jfieldID fidNumber = env->GetFieldID(thisClass, "numberKeywords", "I");
jint numberKeywords = env->GetIntField(obj, fidNumber);
const char *ckwFiles[numberKeywords];
for (int i=0; i<numberKeywords; i++) {
jstring jkwFile = (jstring) env->GetObjectArrayElement(keywordFiles, i);
const char *ckwFile = env->GetStringUTFChars(jkwFile, NULL);
ckwFiles[i] = strdup(ckwFile);
env->ReleaseStringUTFChars(jkwFile, ckwFile);
env->DeleteLocalRef(jkwFile);
}
const char *modelFileCStr = env->GetStringUTFChars(modelFile, NULL);
jfloat *senBody = env->GetFloatArrayElements(sensitivities, 0);
pv_porcupine_multiple_keywords_init(modelFileCStr, numberKeywords, ckwFiles, senBody, &result);
env->ReleaseFloatArrayElements(sensitivities, senBody, 0);
env->ReleaseStringUTFChars(modelFile, modelFileCStr);
return (jlong) result;
}
JNIEXPORT jint JNICALL Java_ai_picovoice_porcupine_Porcupine_process(JNIEnv *env, jobject obj, jlong porcupineObject, jshortArray pcm) {
int result;
jshort *body = env->GetShortArrayElements(pcm, 0);
pv_porcupine_multiple_keywords_process((pv_porcupine_object_t *) porcupineObject, body, &result);
env->ReleaseShortArrayElements(pcm, body, 0);
return result;
}
JNIEXPORT void JNICALL Java_ai_picovoice_porcupine_Porcupine_delete(JNIEnv *env, jobject obj, jlong porcupineObject) {
pv_porcupine_delete((pv_porcupine_object_t *) porcupineObject);
}
from porcupine.
@zsmaguc Same error is happening, do you think you can provide me the dll you got from that code? AMD64, Windows
from porcupine.
You just saved my life, I love you <3
from porcupine.
@tatanpoker09 and @zsmaguc Please help. I am getting following error
exception in thread "main" java.lang.UnsatisfiedLinkError: C:\xxx\porcupine_java\ai\picovoice\porcupine\jni\libjni.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at ai.picovoice.porcupine.Porcupine.(Porcupine.java:29)
I have following libs in ./jni folder
20-02-2019 10:25
..19-02-2019 23:10 51,330 libjni.dll
19-02-2019 22:49 141,942 libpv_porcupine.dll
19-03-2017 02:27 632,800 msvcrt.dll
from porcupine.
Related Issues (20)
- Porcupine Issue: Provided model (.pv) file belongs to a different version of the library HOT 1
- Not able to download my ppn model from the website HOT 2
- Picovoice Console Issue: HOT 1
- Porcupine Issue: Its Taking the audio from Device Speaker HOT 1
- Porcupine Issue: PICOVOICE_STATUS_TO_EXCEPTION 00000136 HOT 5
- Picovoice Documentation Issue (/docs/quick-start/porcupine-jetson/) HOT 1
- RK3588 (0xd05) is 100% working HOT 3
- PORCUPINE CASUING ERRORS AND NOT RUNNING TRAINED KEYWORD HOT 1
- Porcupine Documentation Issue: HOT 1
- Porcupine Issue: Japanese model params file is actually for English HOT 1
- Porcupine Issue: Are there any plans to support WebGL on the Unity platform HOT 1
- Porcupine Issue: aauthentication issue HOT 2
- Creating a custom wake word in porcupine HOT 2
- Porcupine Documentation Issue: HOT 3
- Porcupine Issue: ios . HOT 1
- Android x86_64 Support HOT 2
- Picovoice Console Issue: Wake word is not working HOT 1
- Passing in multiple wake word files on iOS only listens for the first wake word passed in HOT 3
- Porcupine Issue: Have an issues after changing .ppn file to a new one. HOT 7
- Picovoice Console Issue: HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from porcupine.