正在显示
22 个修改的文件
包含
101 行增加
和
211 行删除
android/SherpaOnnxJavaDemo/README.md
0 → 100644
| 1 | +# Introduction | ||
| 2 | + | ||
| 3 | +Please run the following commands to download model files before you run this Android demo: | ||
| 4 | + | ||
| 5 | +```bash | ||
| 6 | +# Assume we are inside | ||
| 7 | +# /Users/fangjun/open-source/sherpa-onnx/android/SherpaOnnxJavaDemo | ||
| 8 | + | ||
| 9 | +cd app/src/main/assets/ | ||
| 10 | +wget https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2 | ||
| 11 | + | ||
| 12 | +tar xvf sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2 | ||
| 13 | +rm sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2 | ||
| 14 | + | ||
| 15 | +mv sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/encoder-epoch-99-avg-1.int8.onnx ./ | ||
| 16 | +mv sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/decoder-epoch-99-avg-1.onnx ./ | ||
| 17 | +mv sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/joiner-epoch-99-avg-1.int8.onnx ./ | ||
| 18 | +mv sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/tokens.txt ./ | ||
| 19 | + | ||
| 20 | +rm -rf sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/* | ||
| 21 | + | ||
| 22 | +mv encoder-epoch-99-avg-1.int8.onnx ./ | ||
| 23 | +mv decoder-epoch-99-avg-1.onnx ./ | ||
| 24 | +mv joiner-epoch-99-avg-1.int8.onnx ./ | ||
| 25 | +mv tokens.txt ./ | ||
| 26 | +``` | ||
| 27 | + | ||
| 28 | +You should have the following directory structure: | ||
| 29 | +``` | ||
| 30 | +(py38) fangjuns-MacBook-Pro:assets fangjun$ pwd | ||
| 31 | +/Users/fangjun/open-source/sherpa-onnx/android/SherpaOnnxJavaDemo/app/src/main/assets | ||
| 32 | + | ||
| 33 | +(py38) fangjuns-MacBook-Pro:assets fangjun$ tree . | ||
| 34 | +. | ||
| 35 | +└── sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20 | ||
| 36 | + ├── decoder-epoch-99-avg-1.onnx | ||
| 37 | + ├── encoder-epoch-99-avg-1.int8.onnx | ||
| 38 | + ├── joiner-epoch-99-avg-1.int8.onnx | ||
| 39 | + └── tokens.txt | ||
| 40 | + | ||
| 41 | +1 directory, 4 files | ||
| 42 | +``` | ||
| 43 | + | ||
| 44 | +Remember to remove unused files to reduce the file size of the final APK. |
| @@ -8,7 +8,7 @@ android { | @@ -8,7 +8,7 @@ android { | ||
| 8 | defaultConfig { | 8 | defaultConfig { |
| 9 | applicationId "com.k2fsa.sherpa.onnx" | 9 | applicationId "com.k2fsa.sherpa.onnx" |
| 10 | minSdk 28 | 10 | minSdk 28 |
| 11 | - targetSdk 32 | 11 | + targetSdk 34 |
| 12 | versionCode 1 | 12 | versionCode 1 |
| 13 | versionName "1.0" | 13 | versionName "1.0" |
| 14 | 14 | ||
| @@ -25,17 +25,14 @@ android { | @@ -25,17 +25,14 @@ android { | ||
| 25 | sourceCompatibility JavaVersion.VERSION_1_8 | 25 | sourceCompatibility JavaVersion.VERSION_1_8 |
| 26 | targetCompatibility JavaVersion.VERSION_1_8 | 26 | targetCompatibility JavaVersion.VERSION_1_8 |
| 27 | } | 27 | } |
| 28 | - sourceSets.main{ | ||
| 29 | - jniLibs.srcDirs = ['jniLibs'] | ||
| 30 | - } | ||
| 31 | } | 28 | } |
| 32 | 29 | ||
| 33 | dependencies { | 30 | dependencies { |
| 34 | - | ||
| 35 | implementation 'androidx.appcompat:appcompat:1.3.1' | 31 | implementation 'androidx.appcompat:appcompat:1.3.1' |
| 36 | implementation 'com.google.android.material:material:1.3.0' | 32 | implementation 'com.google.android.material:material:1.3.0' |
| 37 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' | 33 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' |
| 38 | implementation 'pub.devrel:easypermissions:3.0.0' | 34 | implementation 'pub.devrel:easypermissions:3.0.0' |
| 39 | - implementation project(path: ':sherpa') | ||
| 40 | - | ||
| 41 | -} | ||
| 35 | + implementation 'androidx.core:core-ktx:1.7.0' | ||
| 36 | + // implementation files('/Users/fangjun/open-source/sherpa-onnx/android/SherpaOnnxAar/sherpa_onnx/build/outputs/aar/sherpa_onnx-release.aar') | ||
| 37 | + implementation 'com.github.k2-fsa:sherpa-onnx:master-SNAPSHOT' | ||
| 38 | +} |
android/SherpaOnnxJavaDemo/app/src/main/java/com/k2fsa/sherpa/onnx/OnlineRecognizer.java
已删除
100644 → 0
| 1 | -// Copyright 2022-2023 by zhaoming | ||
| 2 | -// Copyright 2024 Xiaomi Corporation | ||
| 3 | - | ||
| 4 | -package com.k2fsa.sherpa.onnx; | ||
| 5 | - | ||
| 6 | -import android.content.res.AssetManager; | ||
| 7 | - | ||
| 8 | -public class OnlineRecognizer { | ||
| 9 | - static { | ||
| 10 | - System.loadLibrary("sherpa-onnx-jni"); | ||
| 11 | - } | ||
| 12 | - | ||
| 13 | - private long ptr = 0; | ||
| 14 | - | ||
| 15 | - public OnlineRecognizer(OnlineRecognizerConfig config) { | ||
| 16 | - ptr = newFromFile(config); | ||
| 17 | - } | ||
| 18 | - | ||
| 19 | - public OnlineRecognizer(AssetManager assetManager, OnlineRecognizerConfig config) { | ||
| 20 | - ptr = newFromAsset(assetManager, config); | ||
| 21 | - } | ||
| 22 | - | ||
| 23 | - public void decode(OnlineStream s) { | ||
| 24 | - decode(ptr, s.getPtr()); | ||
| 25 | - } | ||
| 26 | - | ||
| 27 | - public boolean isReady(OnlineStream s) { | ||
| 28 | - return isReady(ptr, s.getPtr()); | ||
| 29 | - } | ||
| 30 | - | ||
| 31 | - public boolean isEndpoint(OnlineStream s) { | ||
| 32 | - return isEndpoint(ptr, s.getPtr()); | ||
| 33 | - } | ||
| 34 | - | ||
| 35 | - public void reset(OnlineStream s) { | ||
| 36 | - reset(ptr, s.getPtr()); | ||
| 37 | - } | ||
| 38 | - | ||
| 39 | - public OnlineStream createStream() { | ||
| 40 | - long p = createStream(ptr, ""); | ||
| 41 | - return new OnlineStream(p); | ||
| 42 | - } | ||
| 43 | - | ||
| 44 | - @Override | ||
| 45 | - protected void finalize() throws Throwable { | ||
| 46 | - release(); | ||
| 47 | - } | ||
| 48 | - | ||
| 49 | - // You'd better call it manually if it is not used anymore | ||
| 50 | - public void release() { | ||
| 51 | - if (this.ptr == 0) { | ||
| 52 | - return; | ||
| 53 | - } | ||
| 54 | - delete(this.ptr); | ||
| 55 | - this.ptr = 0; | ||
| 56 | - } | ||
| 57 | - | ||
| 58 | - public OnlineRecognizerResult getResult(OnlineStream s) { | ||
| 59 | - Object[] arr = getResult(ptr, s.getPtr()); | ||
| 60 | - String text = (String) arr[0]; | ||
| 61 | - String[] tokens = (String[]) arr[1]; | ||
| 62 | - float[] timestamps = (float[]) arr[2]; | ||
| 63 | - return new OnlineRecognizerResult(text, tokens, timestamps); | ||
| 64 | - } | ||
| 65 | - | ||
| 66 | - | ||
| 67 | - private native void delete(long ptr); | ||
| 68 | - | ||
| 69 | - private native long newFromFile(OnlineRecognizerConfig config); | ||
| 70 | - | ||
| 71 | - private native long newFromAsset(AssetManager assetManager, OnlineRecognizerConfig config); | ||
| 72 | - | ||
| 73 | - private native long createStream(long ptr, String hotwords); | ||
| 74 | - | ||
| 75 | - private native void reset(long ptr, long streamPtr); | ||
| 76 | - | ||
| 77 | - private native void decode(long ptr, long streamPtr); | ||
| 78 | - | ||
| 79 | - private native boolean isEndpoint(long ptr, long streamPtr); | ||
| 80 | - | ||
| 81 | - private native boolean isReady(long ptr, long streamPtr); | ||
| 82 | - | ||
| 83 | - private native Object[] getResult(long ptr, long streamPtr); | ||
| 84 | -} |
| 1 | package com.k2fsa.sherpa.onnx.service; | 1 | package com.k2fsa.sherpa.onnx.service; |
| 2 | 2 | ||
| 3 | import android.Manifest; | 3 | import android.Manifest; |
| 4 | +import android.annotation.SuppressLint; | ||
| 4 | import android.app.Notification; | 5 | import android.app.Notification; |
| 5 | import android.app.NotificationChannel; | 6 | import android.app.NotificationChannel; |
| 6 | import android.app.NotificationManager; | 7 | import android.app.NotificationManager; |
| @@ -67,6 +68,16 @@ public class SpeechSherpaRecognitionService extends Service { | @@ -67,6 +68,16 @@ public class SpeechSherpaRecognitionService extends Service { | ||
| 67 | appViewModel = Application.getInstance().getViewModel(); | 68 | appViewModel = Application.getInstance().getViewModel(); |
| 68 | int numBytes = AudioRecord.getMinBufferSize(sampleRateInHz, channelConfig, audioFormat); | 69 | int numBytes = AudioRecord.getMinBufferSize(sampleRateInHz, channelConfig, audioFormat); |
| 69 | 70 | ||
| 71 | + if (ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) { | ||
| 72 | + // TODO: Consider calling | ||
| 73 | + // ActivityCompat#requestPermissions | ||
| 74 | + // here to request the missing permissions, and then overriding | ||
| 75 | + // public void onRequestPermissionsResult(int requestCode, String[] permissions, | ||
| 76 | + // int[] grantResults) | ||
| 77 | + // to handle the case where the user grants the permission. See the documentation | ||
| 78 | + // for ActivityCompat#requestPermissions for more details. | ||
| 79 | + return; | ||
| 80 | + } | ||
| 70 | audioRecord = new AudioRecord( | 81 | audioRecord = new AudioRecord( |
| 71 | audioSource, | 82 | audioSource, |
| 72 | sampleRateInHz, | 83 | sampleRateInHz, |
| @@ -81,22 +92,21 @@ public class SpeechSherpaRecognitionService extends Service { | @@ -81,22 +92,21 @@ public class SpeechSherpaRecognitionService extends Service { | ||
| 81 | 92 | ||
| 82 | private void initializeSherpa() { | 93 | private void initializeSherpa() { |
| 83 | Log.d("Current Directory", System.getProperty("user.dir")); | 94 | Log.d("Current Directory", System.getProperty("user.dir")); |
| 84 | - String modelDir = "sherpa-onnx-streaming-zipformer-zh-14M-2023-02-23"; | 95 | + String modelDir = "sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20"; |
| 85 | initializeSherpaDir(modelDir, modelDir); | 96 | initializeSherpaDir(modelDir, modelDir); |
| 86 | - OnlineTransducerModelConfig onlineTransducerModelConfig = OnlineTransducerModelConfig.builder() | ||
| 87 | - .setEncoder(modelDir + "/encoder-epoch-99-avg-1.int8.onnx") | ||
| 88 | - .setDecoder(modelDir + "/decoder-epoch-99-avg-1.onnx") | ||
| 89 | - .setJoiner(modelDir + "/joiner-epoch-99-avg-1.int8.onnx") | ||
| 90 | - .build(); | ||
| 91 | - | ||
| 92 | - OnlineModelConfig onlineModelConfig = OnlineModelConfig.builder() | ||
| 93 | - .setTransducer(onlineTransducerModelConfig) | ||
| 94 | - .setTokens(modelDir + "/tokens.txt") | ||
| 95 | - .setModelType("zipformer") | ||
| 96 | - .build(); | ||
| 97 | - OnlineRecognizerConfig config = OnlineRecognizerConfig.builder() | ||
| 98 | - .setOnlineModelConfig(onlineModelConfig) | ||
| 99 | - .build(); | 97 | + OnlineTransducerModelConfig onlineTransducerModelConfig = new OnlineTransducerModelConfig(); |
| 98 | + onlineTransducerModelConfig.setEncoder(modelDir + "/encoder-epoch-99-avg-1.int8.onnx"); | ||
| 99 | + onlineTransducerModelConfig.setDecoder(modelDir + "/decoder-epoch-99-avg-1.onnx"); | ||
| 100 | + onlineTransducerModelConfig.setJoiner(modelDir + "/joiner-epoch-99-avg-1.int8.onnx"); | ||
| 101 | + | ||
| 102 | + OnlineModelConfig onlineModelConfig = new OnlineModelConfig(); | ||
| 103 | + onlineModelConfig.setTransducer(onlineTransducerModelConfig); | ||
| 104 | + onlineModelConfig.setTokens(modelDir + "/tokens.txt"); | ||
| 105 | + onlineModelConfig.setModelType("zipformer"); | ||
| 106 | + onlineModelConfig.setDebug(true); | ||
| 107 | + | ||
| 108 | + OnlineRecognizerConfig config = new OnlineRecognizerConfig(); | ||
| 109 | + config.setModelConfig(onlineModelConfig); | ||
| 100 | recognizer = new OnlineRecognizer(getAssets(), config); | 110 | recognizer = new OnlineRecognizer(getAssets(), config); |
| 101 | 111 | ||
| 102 | audioRecord.startRecording(); | 112 | audioRecord.startRecording(); |
| @@ -110,7 +120,7 @@ public class SpeechSherpaRecognitionService extends Service { | @@ -110,7 +120,7 @@ public class SpeechSherpaRecognitionService extends Service { | ||
| 110 | } | 120 | } |
| 111 | 121 | ||
| 112 | private void processSamples() { | 122 | private void processSamples() { |
| 113 | - OnlineStream stream = recognizer.createStream(); | 123 | + OnlineStream stream = recognizer.createStream(""); |
| 114 | double interval = 0.1; | 124 | double interval = 0.1; |
| 115 | int bufferSize = (int) (interval * sampleRateInHz); | 125 | int bufferSize = (int) (interval * sampleRateInHz); |
| 116 | short[] buffer = new short[bufferSize]; | 126 | short[] buffer = new short[bufferSize]; |
| @@ -182,6 +192,7 @@ public class SpeechSherpaRecognitionService extends Service { | @@ -182,6 +192,7 @@ public class SpeechSherpaRecognitionService extends Service { | ||
| 182 | } | 192 | } |
| 183 | 193 | ||
| 184 | 194 | ||
| 195 | + @SuppressLint("ForegroundServiceType") | ||
| 185 | private void startForegroundService() { | 196 | private void startForegroundService() { |
| 186 | String channelId = createNotificationChannel(); | 197 | String channelId = createNotificationChannel(); |
| 187 | 198 |
| @@ -10,8 +10,8 @@ dependencyResolutionManagement { | @@ -10,8 +10,8 @@ dependencyResolutionManagement { | ||
| 10 | repositories { | 10 | repositories { |
| 11 | google() | 11 | google() |
| 12 | mavenCentral() | 12 | mavenCentral() |
| 13 | + maven { url 'https://jitpack.io' } | ||
| 13 | } | 14 | } |
| 14 | } | 15 | } |
| 15 | rootProject.name = "SherpaOnnxJavaDemo" | 16 | rootProject.name = "SherpaOnnxJavaDemo" |
| 16 | include ':app' | 17 | include ':app' |
| 17 | -include ':sherpa' |
| 1 | -/build |
| 1 | -plugins { | ||
| 2 | - id 'com.android.library' | ||
| 3 | -} | ||
| 4 | - | ||
| 5 | -android { | ||
| 6 | - namespace 'com.k2fsa.sherpa' | ||
| 7 | - compileSdk 34 | ||
| 8 | - | ||
| 9 | - defaultConfig { | ||
| 10 | - minSdk 26 | ||
| 11 | - targetSdk 27 | ||
| 12 | - versionCode 1 | ||
| 13 | - versionName "1.0" | ||
| 14 | - missingDimensionStrategy 'base', 'feature1' | ||
| 15 | - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
| 16 | - } | ||
| 17 | - | ||
| 18 | - buildTypes { | ||
| 19 | - release { | ||
| 20 | - minifyEnabled false | ||
| 21 | - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
| 22 | - } | ||
| 23 | - } | ||
| 24 | - compileOptions { | ||
| 25 | - sourceCompatibility JavaVersion.VERSION_1_8 | ||
| 26 | - targetCompatibility JavaVersion.VERSION_1_8 | ||
| 27 | - } | ||
| 28 | -} | ||
| 29 | - | ||
| 30 | -dependencies { | ||
| 31 | - | ||
| 32 | -// implementation "androidx.appcompat" | ||
| 33 | -// implementation libs.material | ||
| 34 | -// testImplementation libs.junit | ||
| 35 | -// androidTestImplementation libs.androidx.test.ext.junit | ||
| 36 | -// androidTestImplementation libs.espresso.core | ||
| 37 | - implementation 'androidx.appcompat:appcompat:1.6.1' | ||
| 38 | - implementation 'com.google.android.material:material:1.9.0' | ||
| 39 | - testImplementation 'junit:junit:4.13.2' | ||
| 40 | - androidTestImplementation 'androidx.test.ext:junit:1.1.5' | ||
| 41 | - androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' | ||
| 42 | - | ||
| 43 | -} |
| 1 | -# Add project specific ProGuard rules here. | ||
| 2 | -# You can control the set of applied configuration files using the | ||
| 3 | -# proguardFiles setting in build.gradle. | ||
| 4 | -# | ||
| 5 | -# For more details, see | ||
| 6 | -# http://developer.android.com/guide/developing/tools/proguard.html | ||
| 7 | - | ||
| 8 | -# If your project uses WebView with JS, uncomment the following | ||
| 9 | -# and specify the fully qualified class name to the JavaScript interface | ||
| 10 | -# class: | ||
| 11 | -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
| 12 | -# public *; | ||
| 13 | -#} | ||
| 14 | - | ||
| 15 | -# Uncomment this to preserve the line number information for | ||
| 16 | -# debugging stack traces. | ||
| 17 | -#-keepattributes SourceFile,LineNumberTable | ||
| 18 | - | ||
| 19 | -# If you keep the line number information, uncomment this to | ||
| 20 | -# hide the original source file name. | ||
| 21 | -#-renamesourcefileattribute SourceFile |
| 1 | -../../../../../../../sherpa-onnx/sherpa-onnx/java-api/src/com |
| @@ -15,8 +15,8 @@ data class AudioTaggingModelConfig( | @@ -15,8 +15,8 @@ data class AudioTaggingModelConfig( | ||
| 15 | ) | 15 | ) |
| 16 | 16 | ||
| 17 | data class AudioTaggingConfig( | 17 | data class AudioTaggingConfig( |
| 18 | - var model: AudioTaggingModelConfig, | ||
| 19 | - var labels: String, | 18 | + var model: AudioTaggingModelConfig = AudioTaggingModelConfig(), |
| 19 | + var labels: String = "", | ||
| 20 | var topK: Int = 5, | 20 | var topK: Int = 5, |
| 21 | ) | 21 | ) |
| 22 | 22 |
| @@ -5,7 +5,7 @@ import android.content.res.AssetManager | @@ -5,7 +5,7 @@ import android.content.res.AssetManager | ||
| 5 | 5 | ||
| 6 | data class KeywordSpotterConfig( | 6 | data class KeywordSpotterConfig( |
| 7 | var featConfig: FeatureConfig = FeatureConfig(), | 7 | var featConfig: FeatureConfig = FeatureConfig(), |
| 8 | - var modelConfig: OnlineModelConfig, | 8 | + var modelConfig: OnlineModelConfig = OnlineModelConfig(), |
| 9 | var maxActivePaths: Int = 4, | 9 | var maxActivePaths: Int = 4, |
| 10 | var keywordsFile: String = "keywords.txt", | 10 | var keywordsFile: String = "keywords.txt", |
| 11 | var keywordsScore: Float = 1.5f, | 11 | var keywordsScore: Float = 1.5f, |
| @@ -3,7 +3,7 @@ package com.k2fsa.sherpa.onnx | @@ -3,7 +3,7 @@ package com.k2fsa.sherpa.onnx | ||
| 3 | import android.content.res.AssetManager | 3 | import android.content.res.AssetManager |
| 4 | 4 | ||
| 5 | data class OfflinePunctuationModelConfig( | 5 | data class OfflinePunctuationModelConfig( |
| 6 | - var ctTransformer: String, | 6 | + var ctTransformer: String = "", |
| 7 | var numThreads: Int = 1, | 7 | var numThreads: Int = 1, |
| 8 | var debug: Boolean = false, | 8 | var debug: Boolean = false, |
| 9 | var provider: String = "cpu", | 9 | var provider: String = "cpu", |
| @@ -58,14 +58,14 @@ data class OfflineModelConfig( | @@ -58,14 +58,14 @@ data class OfflineModelConfig( | ||
| 58 | var debug: Boolean = false, | 58 | var debug: Boolean = false, |
| 59 | var provider: String = "cpu", | 59 | var provider: String = "cpu", |
| 60 | var modelType: String = "", | 60 | var modelType: String = "", |
| 61 | - var tokens: String, | 61 | + var tokens: String = "", |
| 62 | var modelingUnit: String = "", | 62 | var modelingUnit: String = "", |
| 63 | var bpeVocab: String = "", | 63 | var bpeVocab: String = "", |
| 64 | ) | 64 | ) |
| 65 | 65 | ||
| 66 | data class OfflineRecognizerConfig( | 66 | data class OfflineRecognizerConfig( |
| 67 | var featConfig: FeatureConfig = FeatureConfig(), | 67 | var featConfig: FeatureConfig = FeatureConfig(), |
| 68 | - var modelConfig: OfflineModelConfig, | 68 | + var modelConfig: OfflineModelConfig = OfflineModelConfig(), |
| 69 | // var lmConfig: OfflineLMConfig(), // TODO(fangjun): enable it | 69 | // var lmConfig: OfflineLMConfig(), // TODO(fangjun): enable it |
| 70 | var decodingMethod: String = "greedy_search", | 70 | var decodingMethod: String = "greedy_search", |
| 71 | var maxActivePaths: Int = 4, | 71 | var maxActivePaths: Int = 4, |
| @@ -3,11 +3,11 @@ package com.k2fsa.sherpa.onnx | @@ -3,11 +3,11 @@ package com.k2fsa.sherpa.onnx | ||
| 3 | import android.content.res.AssetManager | 3 | import android.content.res.AssetManager |
| 4 | 4 | ||
| 5 | data class OfflineSpeakerSegmentationPyannoteModelConfig( | 5 | data class OfflineSpeakerSegmentationPyannoteModelConfig( |
| 6 | - var model: String, | 6 | + var model: String = "", |
| 7 | ) | 7 | ) |
| 8 | 8 | ||
| 9 | data class OfflineSpeakerSegmentationModelConfig( | 9 | data class OfflineSpeakerSegmentationModelConfig( |
| 10 | - var pyannote: OfflineSpeakerSegmentationPyannoteModelConfig, | 10 | + var pyannote: OfflineSpeakerSegmentationPyannoteModelConfig = OfflineSpeakerSegmentationPyannoteModelConfig(), |
| 11 | var numThreads: Int = 1, | 11 | var numThreads: Int = 1, |
| 12 | var debug: Boolean = false, | 12 | var debug: Boolean = false, |
| 13 | var provider: String = "cpu", | 13 | var provider: String = "cpu", |
| @@ -19,9 +19,9 @@ data class FastClusteringConfig( | @@ -19,9 +19,9 @@ data class FastClusteringConfig( | ||
| 19 | ) | 19 | ) |
| 20 | 20 | ||
| 21 | data class OfflineSpeakerDiarizationConfig( | 21 | data class OfflineSpeakerDiarizationConfig( |
| 22 | - var segmentation: OfflineSpeakerSegmentationModelConfig, | ||
| 23 | - var embedding: SpeakerEmbeddingExtractorConfig, | ||
| 24 | - var clustering: FastClusteringConfig, | 22 | + var segmentation: OfflineSpeakerSegmentationModelConfig = OfflineSpeakerSegmentationModelConfig(), |
| 23 | + var embedding: SpeakerEmbeddingExtractorConfig = SpeakerEmbeddingExtractorConfig(), | ||
| 24 | + var clustering: FastClusteringConfig = FastClusteringConfig(), | ||
| 25 | var minDurationOn: Float = 0.2f, | 25 | var minDurationOn: Float = 0.2f, |
| 26 | var minDurationOff: Float = 0.5f, | 26 | var minDurationOff: Float = 0.5f, |
| 27 | ) | 27 | ) |
| @@ -38,7 +38,7 @@ data class OnlineModelConfig( | @@ -38,7 +38,7 @@ data class OnlineModelConfig( | ||
| 38 | var paraformer: OnlineParaformerModelConfig = OnlineParaformerModelConfig(), | 38 | var paraformer: OnlineParaformerModelConfig = OnlineParaformerModelConfig(), |
| 39 | var zipformer2Ctc: OnlineZipformer2CtcModelConfig = OnlineZipformer2CtcModelConfig(), | 39 | var zipformer2Ctc: OnlineZipformer2CtcModelConfig = OnlineZipformer2CtcModelConfig(), |
| 40 | var neMoCtc: OnlineNeMoCtcModelConfig = OnlineNeMoCtcModelConfig(), | 40 | var neMoCtc: OnlineNeMoCtcModelConfig = OnlineNeMoCtcModelConfig(), |
| 41 | - var tokens: String, | 41 | + var tokens: String = "", |
| 42 | var numThreads: Int = 1, | 42 | var numThreads: Int = 1, |
| 43 | var debug: Boolean = false, | 43 | var debug: Boolean = false, |
| 44 | var provider: String = "cpu", | 44 | var provider: String = "cpu", |
| @@ -60,7 +60,7 @@ data class OnlineCtcFstDecoderConfig( | @@ -60,7 +60,7 @@ data class OnlineCtcFstDecoderConfig( | ||
| 60 | 60 | ||
| 61 | data class OnlineRecognizerConfig( | 61 | data class OnlineRecognizerConfig( |
| 62 | var featConfig: FeatureConfig = FeatureConfig(), | 62 | var featConfig: FeatureConfig = FeatureConfig(), |
| 63 | - var modelConfig: OnlineModelConfig, | 63 | + var modelConfig: OnlineModelConfig = OnlineModelConfig(), |
| 64 | var lmConfig: OnlineLMConfig = OnlineLMConfig(), | 64 | var lmConfig: OnlineLMConfig = OnlineLMConfig(), |
| 65 | var ctcFstDecoderConfig: OnlineCtcFstDecoderConfig = OnlineCtcFstDecoderConfig(), | 65 | var ctcFstDecoderConfig: OnlineCtcFstDecoderConfig = OnlineCtcFstDecoderConfig(), |
| 66 | var endpointConfig: EndpointConfig = EndpointConfig(), | 66 | var endpointConfig: EndpointConfig = EndpointConfig(), |
| 1 | package com.k2fsa.sherpa.onnx | 1 | package com.k2fsa.sherpa.onnx |
| 2 | 2 | ||
| 3 | data class SpeakerEmbeddingExtractorConfig( | 3 | data class SpeakerEmbeddingExtractorConfig( |
| 4 | - val model: String, | 4 | + val model: String = "", |
| 5 | var numThreads: Int = 1, | 5 | var numThreads: Int = 1, |
| 6 | var debug: Boolean = false, | 6 | var debug: Boolean = false, |
| 7 | var provider: String = "cpu", | 7 | var provider: String = "cpu", |
| @@ -3,13 +3,13 @@ package com.k2fsa.sherpa.onnx | @@ -3,13 +3,13 @@ package com.k2fsa.sherpa.onnx | ||
| 3 | import android.content.res.AssetManager | 3 | import android.content.res.AssetManager |
| 4 | 4 | ||
| 5 | data class SpokenLanguageIdentificationWhisperConfig( | 5 | data class SpokenLanguageIdentificationWhisperConfig( |
| 6 | - var encoder: String, | ||
| 7 | - var decoder: String, | 6 | + var encoder: String = "", |
| 7 | + var decoder: String = "", | ||
| 8 | var tailPaddings: Int = -1, | 8 | var tailPaddings: Int = -1, |
| 9 | ) | 9 | ) |
| 10 | 10 | ||
| 11 | data class SpokenLanguageIdentificationConfig( | 11 | data class SpokenLanguageIdentificationConfig( |
| 12 | - var whisper: SpokenLanguageIdentificationWhisperConfig, | 12 | + var whisper: SpokenLanguageIdentificationWhisperConfig = SpokenLanguageIdentificationWhisperConfig(), |
| 13 | var numThreads: Int = 1, | 13 | var numThreads: Int = 1, |
| 14 | var debug: Boolean = false, | 14 | var debug: Boolean = false, |
| 15 | var provider: String = "cpu", | 15 | var provider: String = "cpu", |
| @@ -4,9 +4,9 @@ package com.k2fsa.sherpa.onnx | @@ -4,9 +4,9 @@ package com.k2fsa.sherpa.onnx | ||
| 4 | import android.content.res.AssetManager | 4 | import android.content.res.AssetManager |
| 5 | 5 | ||
| 6 | data class OfflineTtsVitsModelConfig( | 6 | data class OfflineTtsVitsModelConfig( |
| 7 | - var model: String, | 7 | + var model: String = "", |
| 8 | var lexicon: String = "", | 8 | var lexicon: String = "", |
| 9 | - var tokens: String, | 9 | + var tokens: String = "", |
| 10 | var dataDir: String = "", | 10 | var dataDir: String = "", |
| 11 | var dictDir: String = "", | 11 | var dictDir: String = "", |
| 12 | var noiseScale: Float = 0.667f, | 12 | var noiseScale: Float = 0.667f, |
| @@ -15,14 +15,14 @@ data class OfflineTtsVitsModelConfig( | @@ -15,14 +15,14 @@ data class OfflineTtsVitsModelConfig( | ||
| 15 | ) | 15 | ) |
| 16 | 16 | ||
| 17 | data class OfflineTtsModelConfig( | 17 | data class OfflineTtsModelConfig( |
| 18 | - var vits: OfflineTtsVitsModelConfig, | 18 | + var vits: OfflineTtsVitsModelConfig = OfflineTtsVitsModelConfig(), |
| 19 | var numThreads: Int = 1, | 19 | var numThreads: Int = 1, |
| 20 | var debug: Boolean = false, | 20 | var debug: Boolean = false, |
| 21 | var provider: String = "cpu", | 21 | var provider: String = "cpu", |
| 22 | ) | 22 | ) |
| 23 | 23 | ||
| 24 | data class OfflineTtsConfig( | 24 | data class OfflineTtsConfig( |
| 25 | - var model: OfflineTtsModelConfig, | 25 | + var model: OfflineTtsModelConfig = OfflineTtsModelConfig(), |
| 26 | var ruleFsts: String = "", | 26 | var ruleFsts: String = "", |
| 27 | var ruleFars: String = "", | 27 | var ruleFars: String = "", |
| 28 | var maxNumSentences: Int = 1, | 28 | var maxNumSentences: Int = 1, |
| @@ -4,7 +4,7 @@ package com.k2fsa.sherpa.onnx | @@ -4,7 +4,7 @@ package com.k2fsa.sherpa.onnx | ||
| 4 | import android.content.res.AssetManager | 4 | import android.content.res.AssetManager |
| 5 | 5 | ||
| 6 | data class SileroVadModelConfig( | 6 | data class SileroVadModelConfig( |
| 7 | - var model: String, | 7 | + var model: String = "", |
| 8 | var threshold: Float = 0.5F, | 8 | var threshold: Float = 0.5F, |
| 9 | var minSilenceDuration: Float = 0.25F, | 9 | var minSilenceDuration: Float = 0.25F, |
| 10 | var minSpeechDuration: Float = 0.25F, | 10 | var minSpeechDuration: Float = 0.25F, |
| @@ -13,7 +13,7 @@ data class SileroVadModelConfig( | @@ -13,7 +13,7 @@ data class SileroVadModelConfig( | ||
| 13 | ) | 13 | ) |
| 14 | 14 | ||
| 15 | data class VadModelConfig( | 15 | data class VadModelConfig( |
| 16 | - var sileroVadModelConfig: SileroVadModelConfig, | 16 | + var sileroVadModelConfig: SileroVadModelConfig = SileroVadModelConfig(), |
| 17 | var sampleRate: Int = 16000, | 17 | var sampleRate: Int = 16000, |
| 18 | var numThreads: Int = 1, | 18 | var numThreads: Int = 1, |
| 19 | var provider: String = "cpu", | 19 | var provider: String = "cpu", |
| @@ -112,5 +112,5 @@ fun getVadModelConfig(type: Int): VadModelConfig? { | @@ -112,5 +112,5 @@ fun getVadModelConfig(type: Int): VadModelConfig? { | ||
| 112 | ) | 112 | ) |
| 113 | } | 113 | } |
| 114 | } | 114 | } |
| 115 | - return null; | 115 | + return null |
| 116 | } | 116 | } |
-
请 注册 或 登录 后发表评论