Bump emscripten version, update examples, add demo

This commit is contained in:
msqr1
2024-09-09 23:07:28 -07:00
parent fb296e8aef
commit bc3ae2e934
7 changed files with 22 additions and 22 deletions

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@@ -4,17 +4,17 @@
<script src="https://cdn.jsdelivr.net/gh/msqr1/Vosklet@1.1.5/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})
// All data is collected and transfered to the main thread so the AudioContext won't output anything. Set sinkId type to none to save power
let ctx = new AudioContext({sinkId: {type: "none"}})
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","English","vosk-model-small-en-us-0.15")
let recognizer = await module.createRecognizer(model, 16000)
let recognizer = await module.createRecognizer(model, ctx.sampleRate)
// 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
// Fetch, decode, and recognize the .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))

View File

@@ -4,24 +4,23 @@
<script src="https://cdn.jsdelivr.net/gh/msqr1/Vosklet@1.1.5/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})
// All data is collected and transfered to the main thread so the AudioContext won't output anything. Set sinkId type to none to save power
let ctx = new AudioContext({sinkId: {type: "none"}})
// Setup mic with correct sample rate
// Setup microphone
let micNode = ctx.createMediaStreamSource(await navigator.mediaDevices.getUserMedia({
video: false,
audio: {
echoCancellation: true,
noiseSuppression: true,
channelCount: 1,
sampleRate: 16000
channelCount: 1
},
}))
// Load Vosklet module, model and recognizer
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","English","vosk-model-small-en-us-0.15")
let recognizer = await module.createRecognizer(model, 16000)
let recognizer = await module.createRecognizer(model, ctx.sampleRate)
// Listen for result and partial result
recognizer.addEventListener("result", ev => console.log("Result: ", ev.detail))
@@ -33,7 +32,7 @@
// Recognize data on arrival
transferer.port.onmessage = ev => recognizer.acceptWaveform(ev.data)
// Connect to microphone
// Connect transferer to microphone
micNode.connect(transferer)
}
</script>