From 61ae3f960379dc46d358ae322bb24c7ce4b23af8 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Wed, 24 Apr 2024 09:44:00 +0800 Subject: [PATCH] minor fixes --- .github/workflows/apk-asr.yaml | 4 ++-- .../src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt | 2 +- android/SherpaOnnx2Pass/app/src/main/AndroidManifest.xml | 4 ++-- .../src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt | 4 ++-- .../src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt | 4 ++-- .../app/src/main/java/com/k2fsa/sherpa/onnx/Tts.kt | 7 ++++++- .../java/com/k2fsa/sherpa/onnx/tts/engine/TtsEngine.kt | 4 ++-- .../src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt | 4 ++-- .../src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt | 7 ++++--- kotlin-api-examples/test_language_id.kt | 2 ++ kotlin-api-examples/test_speaker_id.kt | 1 + kotlin-api-examples/test_tts.kt | 1 + sherpa-onnx/jni/keyword-spotter.cc | 2 +- sherpa-onnx/jni/offline-recognizer.cc | 2 +- sherpa-onnx/jni/online-recognizer.cc | 2 +- sherpa-onnx/jni/voice-activity-detector.cc | 2 +- sherpa-onnx/kotlin-api/Speaker.kt | 6 ++++-- 17 files changed, 35 insertions(+), 23 deletions(-) diff --git a/.github/workflows/apk-asr.yaml b/.github/workflows/apk-asr.yaml index b3bc49f08..3fdb2baac 100644 --- a/.github/workflows/apk-asr.yaml +++ b/.github/workflows/apk-asr.yaml @@ -110,13 +110,13 @@ jobs: env: BUILD_TOOLS_VERSION: ${{ env.BUILD_TOOL_VERSION }} - - name: Display APK for audio tagging after signing + - name: Display APK after signing shell: bash run: | ls -lh ./apks/ du -h -d1 . - - name: Rename APK for audio tagging after signing + - name: Rename APK after signing shell: bash run: | cd apks diff --git a/android/SherpaOnnx/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt b/android/SherpaOnnx/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt index eb3f852b4..e4eb5e276 100644 --- a/android/SherpaOnnx/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt +++ b/android/SherpaOnnx/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt @@ -196,7 +196,7 @@ class MainActivity : AppCompatActivity() { // See https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html // for a list of available models val type = 0 - println("Select model type $type") + Log.i(TAG, "Select model type $type") val config = OnlineRecognizerConfig( featConfig = getFeatureConfig(sampleRate = sampleRateInHz, featureDim = 80), modelConfig = getModelConfig(type = type)!!, diff --git a/android/SherpaOnnx2Pass/app/src/main/AndroidManifest.xml b/android/SherpaOnnx2Pass/app/src/main/AndroidManifest.xml index 0e6a6d536..0cbbfafe8 100644 --- a/android/SherpaOnnx2Pass/app/src/main/AndroidManifest.xml +++ b/android/SherpaOnnx2Pass/app/src/main/AndroidManifest.xml @@ -16,7 +16,7 @@ tools:targetApi="31"> @@ -30,4 +30,4 @@ - \ No newline at end of file + diff --git a/android/SherpaOnnx2Pass/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt b/android/SherpaOnnx2Pass/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt index c9dab560f..596d03e09 100644 --- a/android/SherpaOnnx2Pass/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt +++ b/android/SherpaOnnx2Pass/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt @@ -194,7 +194,7 @@ class MainActivity : AppCompatActivity() { // See https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html // for a list of available models val firstType = 9 - println("Select model type $firstType for the first pass") + Log.i(TAG, "Select model type $firstType for the first pass") val config = OnlineRecognizerConfig( featConfig = getFeatureConfig(sampleRate = sampleRateInHz, featureDim = 80), modelConfig = getModelConfig(type = firstType)!!, @@ -213,7 +213,7 @@ 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), diff --git a/android/SherpaOnnxTts/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt b/android/SherpaOnnxTts/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt index b18d153f0..f44bef8eb 100644 --- a/android/SherpaOnnxTts/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt +++ b/android/SherpaOnnxTts/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt @@ -238,11 +238,11 @@ class MainActivity : AppCompatActivity() { private fun copyDataDir(dataDir: String): String { - println("data dir is $dataDir") + Log.i(TAG, "data dir is $dataDir") copyAssets(dataDir) val newDataDir = application.getExternalFilesDir(null)!!.absolutePath - println("newDataDir: $newDataDir") + Log.i(TAG, "newDataDir: $newDataDir") return newDataDir } diff --git a/android/SherpaOnnxTts/app/src/main/java/com/k2fsa/sherpa/onnx/Tts.kt b/android/SherpaOnnxTts/app/src/main/java/com/k2fsa/sherpa/onnx/Tts.kt index c5da04bea..b25869d07 100644 --- a/android/SherpaOnnxTts/app/src/main/java/com/k2fsa/sherpa/onnx/Tts.kt +++ b/android/SherpaOnnxTts/app/src/main/java/com/k2fsa/sherpa/onnx/Tts.kt @@ -109,9 +109,14 @@ class OfflineTts( } protected fun finalize() { - delete(ptr) + if (ptr != 0L) { + delete(ptr) + ptr = 0 + } } + fun release() = finalize() + private external fun newFromAsset( assetManager: AssetManager, config: OfflineTtsConfig, diff --git a/android/SherpaOnnxTtsEngine/app/src/main/java/com/k2fsa/sherpa/onnx/tts/engine/TtsEngine.kt b/android/SherpaOnnxTtsEngine/app/src/main/java/com/k2fsa/sherpa/onnx/tts/engine/TtsEngine.kt index 5a2283e00..1bf92972e 100644 --- a/android/SherpaOnnxTtsEngine/app/src/main/java/com/k2fsa/sherpa/onnx/tts/engine/TtsEngine.kt +++ b/android/SherpaOnnxTtsEngine/app/src/main/java/com/k2fsa/sherpa/onnx/tts/engine/TtsEngine.kt @@ -141,11 +141,11 @@ object TtsEngine { private fun copyDataDir(context: Context, dataDir: String): String { - println("data dir is $dataDir") + Log.i(TAG, "data dir is $dataDir") copyAssets(context, dataDir) val newDataDir = context.getExternalFilesDir(null)!!.absolutePath - println("newDataDir: $newDataDir") + Log.i(TAG, "newDataDir: $newDataDir") return newDataDir } diff --git a/android/SherpaOnnxVad/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt b/android/SherpaOnnxVad/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt index 8f8141b73..2f8e3a95c 100644 --- a/android/SherpaOnnxVad/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt +++ b/android/SherpaOnnxVad/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt @@ -119,7 +119,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( @@ -174,4 +174,4 @@ class MainActivity : AppCompatActivity() { } } } -} \ No newline at end of file +} diff --git a/android/SherpaOnnxVadAsr/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt b/android/SherpaOnnxVadAsr/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt index a0286d86c..a7d051853 100644 --- a/android/SherpaOnnxVadAsr/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt +++ b/android/SherpaOnnxVadAsr/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt @@ -129,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( @@ -201,7 +201,7 @@ 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), @@ -219,6 +219,7 @@ class MainActivity : AppCompatActivity() { stream.acceptWaveform(samples, sampleRateInHz) offlineRecognizer.decode(stream) val result = offlineRecognizer.getResult(stream) + stream.release() return result.text } -} \ No newline at end of file +} diff --git a/kotlin-api-examples/test_language_id.kt b/kotlin-api-examples/test_language_id.kt index 3e3a275b2..7e1dcda1b 100644 --- a/kotlin-api-examples/test_language_id.kt +++ b/kotlin-api-examples/test_language_id.kt @@ -37,5 +37,7 @@ fun testSpokenLanguageIdentifcation() { println(waveFilename) println(lang) } + + slid.release() } diff --git a/kotlin-api-examples/test_speaker_id.kt b/kotlin-api-examples/test_speaker_id.kt index 4e8b01dc9..e7126ae17 100644 --- a/kotlin-api-examples/test_speaker_id.kt +++ b/kotlin-api-examples/test_speaker_id.kt @@ -38,6 +38,7 @@ fun testSpeakerRecognition() { check(name.length == 0) manager.release() + extractor.release() println("Speaker ID test done!") } diff --git a/kotlin-api-examples/test_tts.kt b/kotlin-api-examples/test_tts.kt index 769197348..22bcd8c2a 100644 --- a/kotlin-api-examples/test_tts.kt +++ b/kotlin-api-examples/test_tts.kt @@ -21,6 +21,7 @@ fun testTts() { val tts = OfflineTts(config=config) val audio = tts.generateWithCallback(text="“Today as always, men fall into two groups: slaves and free men. Whoever does not have two-thirds of his day for himself, is a slave, whatever he may be: a statesman, a businessman, an official, or a scholar.”", callback=::callback) audio.save(filename="test-en.wav") + tts.release() println("Saved to test-en.wav") } diff --git a/sherpa-onnx/jni/keyword-spotter.cc b/sherpa-onnx/jni/keyword-spotter.cc index a88ad8b82..72b263046 100644 --- a/sherpa-onnx/jni/keyword-spotter.cc +++ b/sherpa-onnx/jni/keyword-spotter.cc @@ -1,4 +1,4 @@ -// sherpa-onnx/csrc/keyword-spotter.cc +// sherpa-onnx/jni/keyword-spotter.cc // // Copyright (c) 2024 Xiaomi Corporation diff --git a/sherpa-onnx/jni/offline-recognizer.cc b/sherpa-onnx/jni/offline-recognizer.cc index b0aa2b4cb..0103417a2 100644 --- a/sherpa-onnx/jni/offline-recognizer.cc +++ b/sherpa-onnx/jni/offline-recognizer.cc @@ -1,4 +1,4 @@ -// sherpa-onnx/csrc/offline-recognizer.h +// sherpa-onnx/jni/offline-recognizer.cc // // Copyright (c) 2024 Xiaomi Corporation diff --git a/sherpa-onnx/jni/online-recognizer.cc b/sherpa-onnx/jni/online-recognizer.cc index 07704eee9..8fa069c05 100644 --- a/sherpa-onnx/jni/online-recognizer.cc +++ b/sherpa-onnx/jni/online-recognizer.cc @@ -1,4 +1,4 @@ -// sherpa-onnx/csrc/online-recognizer.cc +// sherpa-onnx/jni/online-recognizer.cc // // Copyright (c) 2024 Xiaomi Corporation diff --git a/sherpa-onnx/jni/voice-activity-detector.cc b/sherpa-onnx/jni/voice-activity-detector.cc index 12dd10640..bfa31204b 100644 --- a/sherpa-onnx/jni/voice-activity-detector.cc +++ b/sherpa-onnx/jni/voice-activity-detector.cc @@ -1,4 +1,4 @@ -// sherpa-onnx/jni/voice-activity-detector.h" +// sherpa-onnx/csrc/voice-activity-detector.cc // // Copyright (c) 2024 Xiaomi Corporation #include "sherpa-onnx/csrc/voice-activity-detector.h" diff --git a/sherpa-onnx/kotlin-api/Speaker.kt b/sherpa-onnx/kotlin-api/Speaker.kt index 36115790d..93b1b9e4e 100644 --- a/sherpa-onnx/kotlin-api/Speaker.kt +++ b/sherpa-onnx/kotlin-api/Speaker.kt @@ -25,8 +25,10 @@ class SpeakerEmbeddingExtractor( } protected fun finalize() { - delete(ptr) - ptr = 0 + if (ptr != 0L) { + delete(ptr) + ptr = 0 + } } fun release() = finalize()