Refactor the JNI interface to make it more modular and maintainable (#802)
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
android:theme="@style/Theme.SherpaOnnxVadAsr"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:name=".vad.asr.MainActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../../../../../../sherpa-onnx/kotlin-api/FeatureConfig.kt
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.k2fsa.sherpa.onnx
|
||||
package com.k2fsa.sherpa.onnx.vad.asr
|
||||
|
||||
import android.Manifest
|
||||
import android.content.pm.PackageManager
|
||||
@@ -13,6 +13,13 @@ import android.widget.Button
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.app.ActivityCompat
|
||||
import com.k2fsa.sherpa.onnx.OfflineRecognizer
|
||||
import com.k2fsa.sherpa.onnx.OfflineRecognizerConfig
|
||||
import com.k2fsa.sherpa.onnx.R
|
||||
import com.k2fsa.sherpa.onnx.Vad
|
||||
import com.k2fsa.sherpa.onnx.getFeatureConfig
|
||||
import com.k2fsa.sherpa.onnx.getOfflineModelConfig
|
||||
import com.k2fsa.sherpa.onnx.getVadModelConfig
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
|
||||
@@ -40,7 +47,7 @@ class MainActivity : AppCompatActivity() {
|
||||
private val permissions: Array<String> = arrayOf(Manifest.permission.RECORD_AUDIO)
|
||||
|
||||
// Non-streaming ASR
|
||||
private lateinit var offlineRecognizer: SherpaOnnxOffline
|
||||
private lateinit var offlineRecognizer: OfflineRecognizer
|
||||
|
||||
private var idx: Int = 0
|
||||
private var lastText: String = ""
|
||||
@@ -122,7 +129,7 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
private fun initVadModel() {
|
||||
val type = 0
|
||||
println("Select VAD model type ${type}")
|
||||
Log.i(TAG, "Select VAD model type ${type}")
|
||||
val config = getVadModelConfig(type)
|
||||
|
||||
vad = Vad(
|
||||
@@ -194,20 +201,25 @@ class MainActivity : AppCompatActivity() {
|
||||
// See https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html
|
||||
// for a list of available models
|
||||
val secondType = 0
|
||||
println("Select model type ${secondType} for the second pass")
|
||||
Log.i(TAG, "Select model type ${secondType} for the second pass")
|
||||
|
||||
val config = OfflineRecognizerConfig(
|
||||
featConfig = getFeatureConfig(sampleRate = sampleRateInHz, featureDim = 80),
|
||||
modelConfig = getOfflineModelConfig(type = secondType)!!,
|
||||
)
|
||||
|
||||
offlineRecognizer = SherpaOnnxOffline(
|
||||
offlineRecognizer = OfflineRecognizer(
|
||||
assetManager = application.assets,
|
||||
config = config,
|
||||
)
|
||||
}
|
||||
|
||||
private fun runSecondPass(samples: FloatArray): String {
|
||||
return offlineRecognizer.decode(samples, sampleRateInHz)
|
||||
val stream = offlineRecognizer.createStream()
|
||||
stream.acceptWaveform(samples, sampleRateInHz)
|
||||
offlineRecognizer.decode(stream)
|
||||
val result = offlineRecognizer.getResult(stream)
|
||||
stream.release()
|
||||
return result.text
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../../../../../../sherpa-onnx/kotlin-api/OfflineRecognizer.kt
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../../../../../../sherpa-onnx/kotlin-api/OfflineStream.kt
|
||||
@@ -1 +0,0 @@
|
||||
../../../../../../../../../SherpaOnnx2Pass/app/src/main/java/com/k2fsa/sherpa/onnx/SherpaOnnx.kt
|
||||
@@ -1 +1 @@
|
||||
../../../../../../../../../SherpaOnnxVad/app/src/main/java/com/k2fsa/sherpa/onnx/Vad.kt
|
||||
../../../../../../../../../../sherpa-onnx/kotlin-api/Vad.kt
|
||||
@@ -4,7 +4,7 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
tools:context=".vad.asr.MainActivity">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<resources>
|
||||
<string name="app_name">VAD-ASR</string>
|
||||
<string name="app_name">VAD+ASR</string>
|
||||
<string name="hint">Click the Start button to play speech-to-text with Next-gen Kaldi.
|
||||
\n
|
||||
\n\n\n
|
||||
|
||||
Reference in New Issue
Block a user