forked from solyarisoftware/voskJs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrammar.js
More file actions
54 lines (41 loc) · 1.57 KB
/
Copy pathgrammar.js
File metadata and controls
54 lines (41 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const { logLevel, loadModel, transcript, freeModel } = require('../voskjs')
/**
* @see https://alphacephei.com/vosk/adaptation
*/
async function main() {
// Note that big models with static graphs do not support this modification,
// you need a model with dynamic graph.
//const modelDirectory = '../models/vosk-model-en-us-aspire-0.2'
const modelDirectory = '../models/vosk-model-small-en-us-0.15'
const audioFile = '../audio/2830-3980-0043.wav' // -> experience proves this
//const audioFile = '../audio/4507-16021-0012.wav' // -> why should one hold on the way
//const audioFile = '../audio/8455-210777-0068.wav' // -> your power is sufficient i said
const grammar = [
'experience proves this',
'why should one hold on the way',
'your power is sufficient i said',
'oh one two three four five six seven eight nine zero',
//'Giorgio Robino'
'[unk]'
]
console.log(`model directory : ${modelDirectory}`)
console.log(`speech file name : ${audioFile}`)
console.log(`grammar : ${grammar}`)
// set the vosk log level to silence
logLevel(-1)
// load in memory a Vosk directory model
const { model, latency } = await loadModel(modelDirectory)
console.log(`load model latency : ${latency}ms`)
// speech recognition of an audio file
try {
const { result, latency } = await transcript(audioFile, model, {grammar})
console.log( result )
console.log(`transcript latency : ${latency}ms`)
}
catch (error) {
console.error(error)
}
// free the Vosk runtime model
freeModel(model)
}
main()