Speech to text
This commit is contained in:
parent
4836e4c4c0
commit
a9ba42d24c
|
|
@ -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
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue