mirror of
https://github.com/ggerganov/whisper.cpp.git
synced 2025-04-18 16:28:33 +02:00
Merge 5c76377b09
into f92bd59951
This commit is contained in:
commit
aaab74ea08
@ -143,7 +143,7 @@ class MainScreenViewModel(private val application: Application) : ViewModel() {
|
|||||||
printMessage("${data.size / (16000 / 1000)} ms\n")
|
printMessage("${data.size / (16000 / 1000)} ms\n")
|
||||||
printMessage("Transcribing data...\n")
|
printMessage("Transcribing data...\n")
|
||||||
val start = System.currentTimeMillis()
|
val start = System.currentTimeMillis()
|
||||||
val text = whisperContext?.transcribeData(data)
|
val text = whisperContext?.transcribeData(data, tokenTimestamps = false, splitOnWord = false, maxLen = 1)
|
||||||
val elapsed = System.currentTimeMillis() - start
|
val elapsed = System.currentTimeMillis() - start
|
||||||
printMessage("Done ($elapsed ms): \n$text\n")
|
printMessage("Done ($elapsed ms): \n$text\n")
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@ -222,4 +222,4 @@ private suspend fun Context.copyData(
|
|||||||
}
|
}
|
||||||
Log.v(LOG_TAG, "Copied $assetPath to $destination")
|
Log.v(LOG_TAG, "Copied $assetPath to $destination")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,11 @@ class WhisperContext private constructor(private var ptr: Long) {
|
|||||||
Executors.newSingleThreadExecutor().asCoroutineDispatcher()
|
Executors.newSingleThreadExecutor().asCoroutineDispatcher()
|
||||||
)
|
)
|
||||||
|
|
||||||
suspend fun transcribeData(data: FloatArray, printTimestamp: Boolean = true): String = withContext(scope.coroutineContext) {
|
suspend fun transcribeData(data: FloatArray, printTimestamp: Boolean = true, tokenTimestamps: Boolean = false, splitOnWord: Boolean = false, maxLen: Int): String = withContext(scope.coroutineContext) {
|
||||||
require(ptr != 0L)
|
require(ptr != 0L)
|
||||||
val numThreads = WhisperCpuConfig.preferredThreadCount
|
val numThreads = WhisperCpuConfig.preferredThreadCount
|
||||||
Log.d(LOG_TAG, "Selecting $numThreads threads")
|
Log.d(LOG_TAG, "Selecting $numThreads threads")
|
||||||
WhisperLib.fullTranscribe(ptr, numThreads, data)
|
WhisperLib.fullTranscribe(ptr, numThreads, data, tokenTimestamps, splitOnWord, maxLen)
|
||||||
val textCount = WhisperLib.getTextSegmentCount(ptr)
|
val textCount = WhisperLib.getTextSegmentCount(ptr)
|
||||||
return@withContext buildString {
|
return@withContext buildString {
|
||||||
for (i in 0 until textCount) {
|
for (i in 0 until textCount) {
|
||||||
@ -134,7 +134,7 @@ private class WhisperLib {
|
|||||||
external fun initContextFromAsset(assetManager: AssetManager, assetPath: String): Long
|
external fun initContextFromAsset(assetManager: AssetManager, assetPath: String): Long
|
||||||
external fun initContext(modelPath: String): Long
|
external fun initContext(modelPath: String): Long
|
||||||
external fun freeContext(contextPtr: Long)
|
external fun freeContext(contextPtr: Long)
|
||||||
external fun fullTranscribe(contextPtr: Long, numThreads: Int, audioData: FloatArray)
|
external fun fullTranscribe(contextPtr: Long, numThreads: Int, audioData: FloatArray, tokenTimestamps: Boolean, splitOnWord: Boolean, maxLen: Int)
|
||||||
external fun getTextSegmentCount(contextPtr: Long): Int
|
external fun getTextSegmentCount(contextPtr: Long): Int
|
||||||
external fun getTextSegment(contextPtr: Long, index: Int): String
|
external fun getTextSegment(contextPtr: Long, index: Int): String
|
||||||
external fun getTextSegmentT0(contextPtr: Long, index: Int): Long
|
external fun getTextSegmentT0(contextPtr: Long, index: Int): Long
|
||||||
@ -177,4 +177,4 @@ private fun cpuInfo(): String? {
|
|||||||
Log.w(LOG_TAG, "Couldn't read /proc/cpuinfo", e)
|
Log.w(LOG_TAG, "Couldn't read /proc/cpuinfo", e)
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ Java_com_whispercpp_whisper_WhisperLib_00024Companion_freeContext(
|
|||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_com_whispercpp_whisper_WhisperLib_00024Companion_fullTranscribe(
|
Java_com_whispercpp_whisper_WhisperLib_00024Companion_fullTranscribe(
|
||||||
JNIEnv *env, jobject thiz, jlong context_ptr, jint num_threads, jfloatArray audio_data) {
|
JNIEnv *env, jobject thiz, jlong context_ptr, jint num_threads, jfloatArray audio_data, jboolean token_timestamps, jboolean split_on_word, jint max_len) {
|
||||||
UNUSED(thiz);
|
UNUSED(thiz);
|
||||||
struct whisper_context *context = (struct whisper_context *) context_ptr;
|
struct whisper_context *context = (struct whisper_context *) context_ptr;
|
||||||
jfloat *audio_data_arr = (*env)->GetFloatArrayElements(env, audio_data, NULL);
|
jfloat *audio_data_arr = (*env)->GetFloatArrayElements(env, audio_data, NULL);
|
||||||
@ -181,6 +181,9 @@ Java_com_whispercpp_whisper_WhisperLib_00024Companion_fullTranscribe(
|
|||||||
params.offset_ms = 0;
|
params.offset_ms = 0;
|
||||||
params.no_context = true;
|
params.no_context = true;
|
||||||
params.single_segment = false;
|
params.single_segment = false;
|
||||||
|
params.token_timestamps = token_timestamps;
|
||||||
|
params.split_on_word = split_on_word;
|
||||||
|
params.max_len = max_len;
|
||||||
|
|
||||||
whisper_reset_timings(context);
|
whisper_reset_timings(context);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user