Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ class WhisperEngine {
isCancelled.set(false)
val language = normalizeLanguageTag(config?.languageTag)
val numThreads = if (config != null && config.cpuThreads > 0) {
config.cpuThreads
// not more threads than cores
config.cpuThreads.coerceAtMost(maxOf(1, Runtime.getRuntime().availableProcessors()))
} else {
minOf(4, maxOf(1, Runtime.getRuntime().availableProcessors()))
}
Expand Down Expand Up @@ -147,7 +148,9 @@ class WhisperEngine {
.asShortBuffer()
.get(shortBuffer, 0, bytesRead / 2)

for (i in 0 until bytesRead / 2) {
// bounded, so an endless stream can't use up the memory
val room = MAX_BUFFERED_SAMPLES - utteranceBuffer.size
for (i in 0 until minOf(bytesRead / 2, room)) {
utteranceBuffer.add(shortBuffer[i])
}
}
Expand Down Expand Up @@ -316,5 +319,10 @@ class WhisperEngine {
private const val SAMPLE_RATE = 16000
private const val FRAME_SIZE_BYTES = 960 // 30ms @ 16kHz 16-bit mono
private const val SILENCE_RMS = 0.001f // Sensitive peak threshold to reliably detect short words
/**
* 10 minutes of audio, the keyboard's longest fixed setting; more is not buffered. The buffer holds boxed
* samples (about 20 bytes each), so this is already about 200 MB
*/
private const val MAX_BUFFERED_SAMPLES = SAMPLE_RATE * 60 * 10
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ModelManager(
}

fun isModelReady(engineType: String): Boolean {
if (!isKnownEngine(engineType)) return false
val targetFile = File(modelsDir, engineType)
if (!targetFile.exists()) return false

Expand Down