From a9ba42d24c63d7a73d3b6c6c7652f3838456be6c Mon Sep 17 00:00:00 2001 From: r0r-5chach Date: Sat, 19 Oct 2024 19:50:30 +0100 Subject: [PATCH] Speech to text --- src/main/kotlin/STT.kt | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/main/kotlin/STT.kt diff --git a/src/main/kotlin/STT.kt b/src/main/kotlin/STT.kt new file mode 100644 index 0000000..3421cb3 --- /dev/null +++ b/src/main/kotlin/STT.kt @@ -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 +} \ No newline at end of file