-
Notifications
You must be signed in to change notification settings - Fork 570
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JNI binding for speaker embedding extractor.
- Loading branch information
1 parent
c8ab603
commit ed89ada
Showing
8 changed files
with
321 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...rIdentification/app/src/main/java/com/k2fsa/sherpa/onnx/speaker/identification/Speaker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.k2fsa.sherpa.onnx | ||
|
||
import android.content.res.AssetManager | ||
|
||
|
||
data class SpeakerEmbeddingExtractorConfig( | ||
val model: String, | ||
var numThreads: Int = 1, | ||
var debug: Boolean = false, | ||
var provider: String = "cpu", | ||
) | ||
|
||
class SpeakerEmbeddingExtractorStream(var ptr: Long) { | ||
fun acceptWaveform(samples: FloatArray, sampleRate: Int) = acceptWaveform(ptr, samples, sampleRate) | ||
|
||
fun inputFinished() = inputFinished(ptr) | ||
|
||
protected fun finalize() { | ||
delete(ptr) | ||
ptr = 0 | ||
} | ||
|
||
private external fun myTest(ptr: Long, v: Array<FloatArray>) | ||
|
||
fun release() = finalize() | ||
private external fun acceptWaveform(ptr: Long, samples: FloatArray, sampleRate: Int) | ||
|
||
private external fun inputFinished(ptr: Long) | ||
|
||
private external fun delete(ptr: Long) | ||
companion object { | ||
init { | ||
System.loadLibrary("sherpa-onnx-jni") | ||
} | ||
} | ||
} | ||
|
||
class SpeakerEmbeddingExtractor( | ||
assetManager: AssetManager? = null, | ||
config: SpeakerEmbeddingExtractorConfig, | ||
) { | ||
private var ptr: Long | ||
|
||
init { | ||
ptr = if (assetManager != null) { | ||
new(assetManager, config) | ||
} else { | ||
newFromFile(config) | ||
} | ||
} | ||
|
||
protected fun finalize() { | ||
delete(ptr) | ||
ptr = 0 | ||
} | ||
|
||
fun release() = finalize() | ||
|
||
fun createStream(): SpeakerEmbeddingExtractorStream { | ||
val p = createStream(ptr) | ||
return SpeakerEmbeddingExtractorStream(p) | ||
} | ||
|
||
fun isReady(stream: SpeakerEmbeddingExtractorStream) = isReady(ptr, stream.ptr) | ||
fun compute(stream: SpeakerEmbeddingExtractorStream) = compute(ptr, stream.ptr) | ||
|
||
private external fun new( | ||
assetManager: AssetManager, | ||
config: SpeakerEmbeddingExtractorConfig, | ||
): Long | ||
|
||
private external fun newFromFile( | ||
config: SpeakerEmbeddingExtractorConfig, | ||
): Long | ||
|
||
private external fun delete(ptr: Long) | ||
|
||
private external fun createStream(ptr: Long): Long | ||
|
||
private external fun isReady(ptr: Long, streamPtr: Long): Boolean | ||
|
||
|
||
private external fun compute(ptr: Long, streamPtr: Long): FloatArray | ||
|
||
companion object { | ||
init { | ||
System.loadLibrary("sherpa-onnx-jni") | ||
} | ||
} | ||
} |
53 changes: 0 additions & 53 deletions
53
...p/src/main/java/com/k2fsa/sherpa/onnx/speaker/identification/SpeakerEmbeddingExtractor.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../android/SherpaOnnxSpeakerIdentification/app/src/main/java/com/k2fsa/sherpa/onnx/speaker/identification/Speaker.kt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.