30 lines
1.3 KiB
HTML
30 lines
1.3 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<script src="https://cdn.jsdelivr.net/gh/msqr1/Vosklet@1.1.0/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> |