Speech to text

This commit is contained in:
Joshua Perry 2024-10-19 19:50:30 +01:00
parent 4836e4c4c0
commit a9ba42d24c
1 changed files with 39 additions and 0 deletions

39
src/main/kotlin/STT.kt Normal file
View File

@ -0,0 +1,39 @@
import org.vosk.Model
import org.vosk.Recognizer
import java.nio.file.Paths
/**
* TODO: Documentation
*/
class STT {
/**
*
*/
private val model = Model(getModelPath())
/**
*
*/
private val recognizer = Recognizer(model, 16000.0f)
/**
*
*/
fun parseBuffer(buffer: ByteArray, audioBytes: Int): String? {
return if (recognizer.acceptWaveForm(buffer, audioBytes)) {
recognizer.result
} else {
recognizer.partialResult
}
}
fun closeModel() {
recognizer.close()
}
/**
*
*/
private fun getModelPath(): String {
return Paths.get(
javaClass.getResource("STT-model")!!.toURI()
).toFile().absolutePath
}
//TODO: Install model into dir from resource link
}