Enforce one nameing convention
This commit is contained in:
1
Examples/README.md
Normal file
1
Examples/README.md
Normal file
@@ -0,0 +1 @@
|
||||
**Note: Examples in this folder uses its own *Vosklet.js* because I can't set the Response headers for my model for browsers to decompress correctly. Instead, I used DecompressionStream to decompress manually, so this *Vosklet.js* only works for the examples. In production, please use the top-level Vosklet.js instead.**
|
||||
22
Examples/Vosklet.js
Normal file
22
Examples/Vosklet.js
Normal file
File diff suppressed because one or more lines are too long
BIN
Examples/example.wav
Normal file
BIN
Examples/example.wav
Normal file
Binary file not shown.
48
Examples/fromMic.html
Normal file
48
Examples/fromMic.html
Normal file
@@ -0,0 +1,48 @@
|
||||
<!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})
|
||||
|
||||
// Setup mic with correct sample rate
|
||||
let micNode = ctx.createMediaStreamSource(await navigator.mediaDevices.getUserMedia({
|
||||
video: false,
|
||||
audio: {
|
||||
echoCancellation: true,
|
||||
noiseSuppression: true,
|
||||
channelCount: 1,
|
||||
sampleRate: 16000
|
||||
},
|
||||
}))
|
||||
|
||||
// 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","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)
|
||||
})
|
||||
|
||||
// Create a transferer node to get audio data on the main thread
|
||||
let transferer = await module.createTransferer(ctx, 128 * 150)
|
||||
|
||||
// Recognize data on arrival
|
||||
transferer.port.onmessage = ev => {
|
||||
recognizer.acceptWaveform(ev.data)
|
||||
}
|
||||
// Connect to microphone
|
||||
micNode.connect(transferer)
|
||||
}
|
||||
</script>
|
||||
<!-- Start and create audio context only as a result of user's action -->
|
||||
<button onclick="start()">Start</button>
|
||||
</head>
|
||||
</html>
|
||||
30
Examples/fromWav.html
Normal file
30
Examples/fromWav.html
Normal file
@@ -0,0 +1,30 @@
|
||||
<!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>
|
||||
Reference in New Issue
Block a user