[android] add build.gradle and rename model name (#88)
This commit is contained in:
parent
9f29e033aa
commit
508938f537
@ -30,20 +30,20 @@ int offset;
|
||||
void init(JNIEnv* env, jobject, jstring jModelDir) {
|
||||
const char* pModelDir = env->GetStringUTFChars(jModelDir, nullptr);
|
||||
|
||||
std::string modelPath = std::string(pModelDir) + "/wenwen.ort";
|
||||
std::string modelPath = std::string(pModelDir) + "/kws.ort";
|
||||
spotter = std::make_shared<KeywordSpotting>(modelPath);
|
||||
|
||||
feature_config = std::make_shared<wenet::FeaturePipelineConfig>(40, 16000);
|
||||
feature_pipeline = std::make_shared<wenet::FeaturePipeline>(*feature_config);
|
||||
}
|
||||
|
||||
void reset(JNIEnv *env, jobject) {
|
||||
void reset(JNIEnv* env, jobject) {
|
||||
offset = 0;
|
||||
result = "";
|
||||
spotter->Reset();
|
||||
}
|
||||
|
||||
void accept_waveform(JNIEnv *env, jobject, jshortArray jWaveform) {
|
||||
void accept_waveform(JNIEnv* env, jobject, jshortArray jWaveform) {
|
||||
jsize size = env->GetArrayLength(jWaveform);
|
||||
int16_t* waveform = env->GetShortArrayElements(jWaveform, 0);
|
||||
std::vector<int16_t> v(waveform, waveform + size);
|
||||
@ -80,15 +80,15 @@ void start_spot() {
|
||||
decode_thread.detach();
|
||||
}
|
||||
|
||||
jstring get_result(JNIEnv *env, jobject) {
|
||||
jstring get_result(JNIEnv* env, jobject) {
|
||||
LOG(INFO) << "wekws ui result: " << result;
|
||||
return env->NewStringUTF(result.c_str());
|
||||
}
|
||||
} // namespace wekws
|
||||
|
||||
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *) {
|
||||
JNIEnv *env;
|
||||
if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) != JNI_OK) {
|
||||
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void*) {
|
||||
JNIEnv* env;
|
||||
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
@ -99,14 +99,14 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *) {
|
||||
|
||||
static const JNINativeMethod methods[] = {
|
||||
{"init", "(Ljava/lang/String;)V", reinterpret_cast<void*>(wekws::init)},
|
||||
{"reset", "()V", reinterpret_cast<void *>(wekws::reset)},
|
||||
{"reset", "()V", reinterpret_cast<void*>(wekws::reset)},
|
||||
{"acceptWaveform", "([S)V",
|
||||
reinterpret_cast<void *>(wekws::accept_waveform)},
|
||||
reinterpret_cast<void*>(wekws::accept_waveform)},
|
||||
{"setInputFinished", "()V",
|
||||
reinterpret_cast<void *>(wekws::set_input_finished)},
|
||||
{"startSpot", "()V", reinterpret_cast<void *>(wekws::start_spot)},
|
||||
reinterpret_cast<void*>(wekws::set_input_finished)},
|
||||
{"startSpot", "()V", reinterpret_cast<void*>(wekws::start_spot)},
|
||||
{"getResult", "()Ljava/lang/String;",
|
||||
reinterpret_cast<void *>(wekws::get_result)},
|
||||
reinterpret_cast<void*>(wekws::get_result)},
|
||||
};
|
||||
int rc = env->RegisterNatives(c, methods,
|
||||
sizeof(methods) / sizeof(JNINativeMethod));
|
||||
|
||||
@ -34,7 +34,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
private static final String LOG_TAG = "WEKWS";
|
||||
private static final int SAMPLE_RATE = 16000; // The sampling rate
|
||||
private static final int MAX_QUEUE_SIZE = 2500; // 100 seconds audio, 1 / 0.04 * 100
|
||||
private static final List<String> resource = Arrays.asList("wenwen.ort");
|
||||
private static final List<String> resource = Arrays.asList("kws.ort");
|
||||
|
||||
private boolean startRecord = false;
|
||||
private AudioRecord record = null;
|
||||
|
||||
9
runtime/android/build.gradle
Normal file
9
runtime/android/build.gradle
Normal file
@ -0,0 +1,9 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
plugins {
|
||||
id 'com.android.application' version '7.2.2' apply false
|
||||
id 'com.android.library' version '7.2.2' apply false
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user