Recognizer deleteion safety + data control, remove repeating UTF8ToString() call from event system.
This commit is contained in:
26
Examples/fromFile.html
Normal file
26
Examples/fromFile.html
Normal 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>
|
||||
Reference in New Issue
Block a user