-
Notifications
You must be signed in to change notification settings - Fork 9
/
transcodeToPCMAsyncOneBuffer.js
63 lines (49 loc) · 1.97 KB
/
transcodeToPCMAsyncOneBuffer.js
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
55
56
57
58
59
60
61
62
const vosk = require('vosk')
const { toPCM } = require('../lib/audioutils')
const { spellingEnglishCharacters } = require('../examples/spellingEnglishCharacters')
// build a 'blended' grammar just for test
const grammar = spellingEnglishCharacters.concat([
'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]'
])
const SAMPLE_RATE = 16000
async function main() {
// const modelDirectory = '../models/vosk-model-en-us-aspire-0.2'
const modelDirectory = '../models/vosk-model-small-en-us-0.15'
const sourceFile = '../audio/2830-3980-0043.wav.webm'
console.log(`model directory : ${modelDirectory}`)
console.log(`speech file name : ${sourceFile}`)
console.log(`grammar : ${grammar}`)
vosk.setLogLevel(-1)
const modelStart = new Date()
const model = new vosk.Model(modelDirectory)
const modelStop = new Date()
const recognizerStart = new Date()
const rec = new vosk.Recognizer({model: model, sampleRate: SAMPLE_RATE, grammar})
const recognizerStop = new Date()
const ffmpegStart = new Date()
const pcmBuffer = await toPCM({sourceFile})
const ffmpegStop = new Date()
const transcriptStart = new Date()
await rec.acceptWaveformAsync(pcmBuffer)
//rec.acceptWaveform(pcmBuffer)
const finalResult = rec.finalResult()
const transcriptStop = new Date()
console.log()
console.log('final transcript :')
console.log(finalResult)
console.log()
console.log('LATENCIES:')
console.log(`load model : ${modelStop - modelStart}ms`)
console.log(`recognizer : ${recognizerStop - recognizerStart}ms`)
console.log(`ffmpeg to PCM : ${ffmpegStop - ffmpegStart}ms`)
console.log(`acceptWavefromAsync : ${transcriptStop - transcriptStart}ms`)
console.log(`laten. from ffmpeg start: ${transcriptStop - ffmpegStart}ms`)
rec.free()
model.free()
}
main()