Recognizer deleteion safety + data control, remove repeating UTF8ToString() call from event system.

This commit is contained in:
msqr1
2024-09-02 23:02:06 -07:00
parent 070fc73126
commit b0f8464eeb
15 changed files with 136 additions and 102 deletions

26
Examples/fromFile.html Normal file
View File

@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/gh/msqr1/Vosklet@1.1.4/Examples/Vosklet.min.js" async defer></script>
<script>
async function start() {
// Make sure sample rate matches that in the training data
let ctx = new AudioContext({sampleRate : 16000})
let module = await loadVosklet()
let model = await module.createModel("https://ccoreilly.github.io/vosk-browser/models/vosk-model-small-en-us-0.15.tar.gz","model","ID")
let recognizer = await module.createRecognizer(model, 16000)
// Listen for result and partial result
recognizer.addEventListener("result", ev => console.log("Result: ", ev.detail))
recognizer.addEventListener("partialResult", ev => console.log("Partial result: ", ev.detail))
// Fetch, decode, and recognize .wav
let wav = await fetch("https://cdn.jsdelivr.net/gh/msqr1/Vosklet/examples/example.wav")
let audioBuf = await ctx.decodeAudioData(await wav.arrayBuffer())
recognizer.acceptWaveform(audioBuf.getChannelData(0))
}
</script>
</head>
<!-- Start and create audio context only as a result of user's action -->
<button onclick="start()">Start</button>
</html>