mirror of
https://github.com/ggml-org/whisper.cpp.git
synced 2026-10-04 13:31:18 +02:00
whisper.android : add support for loading directly from asset in C (#415)
This commit is contained in:
+1
-2
@@ -73,8 +73,7 @@ class MainScreenViewModel(private val application: Application) : ViewModel() {
|
||||
printMessage("Loading model...\n")
|
||||
val models = application.assets.list("models/")
|
||||
if (models != null) {
|
||||
val inputstream = application.assets.open("models/" + models[0])
|
||||
whisperContext = WhisperContext.createContextFromInputStream(inputstream)
|
||||
whisperContext = WhisperContext.createContextFromAsset(application.assets, "models/" + models[0])
|
||||
printMessage("Loaded model ${models[0]}.\n")
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.whispercppdemo.whisper
|
||||
|
||||
import android.content.res.AssetManager
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import kotlinx.coroutines.*
|
||||
@@ -56,6 +57,15 @@ class WhisperContext private constructor(private var ptr: Long) {
|
||||
}
|
||||
return WhisperContext(ptr)
|
||||
}
|
||||
|
||||
fun createContextFromAsset(assetManager: AssetManager, assetPath: String): WhisperContext {
|
||||
val ptr = WhisperLib.initContextFromAsset(assetManager, assetPath)
|
||||
|
||||
if (ptr == 0L) {
|
||||
throw java.lang.RuntimeException("Couldn't create context from asset $assetPath")
|
||||
}
|
||||
return WhisperContext(ptr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,6 +97,7 @@ private class WhisperLib {
|
||||
|
||||
// JNI methods
|
||||
external fun initContextFromInputStream(inputStream: InputStream): Long
|
||||
external fun initContextFromAsset(assetManager: AssetManager, assetPath: String): Long
|
||||
external fun initContext(modelPath: String): Long
|
||||
external fun freeContext(contextPtr: Long)
|
||||
external fun fullTranscribe(contextPtr: Long, audioData: FloatArray)
|
||||
|
||||
Reference in New Issue
Block a user