-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprocess_transcript.js
66 lines (51 loc) · 1.54 KB
/
process_transcript.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
63
64
65
/**
* @file
*
* The parent (master) thread spawn a worker thread (worker)
* with asyncronous function runThread(), waiting for a response back.
*
* The master pass to the worker thread a Buffer (an audio file) to be transcriped.
*
*
*/
const fs = require('fs')
const { setTimer, getTimer } = require('../lib/chronos')
const { runProcess } = require('../lib/workerProcess')
/**
* transcript a Buffer, using a specified Model and Scorer
*
* @function
* @public
* @async
*
* @param {String} modelPath
* @param {String} scorerPath
* @param {Buffer} audioBuffer
* @return {String} transcript result
*
*/
async function transcriptProcess(modelPath, scorerPath, audioBuffer) {
const workerFile = './process_transcript_worker.js'
const workerData = { modelPath, scorerPath, audioBuffer }
// transcript is done in a worker thread
return runProcess( workerFile, workerData )
}
/**
* unit test
*/
async function master() {
const modelPath = '../models/coqui-stt-0.9.3-models.pbmm'
const scorerPath = '../models/coqui-stt-0.9.3-models.scorer'
const sourceFile = '../audio/2830-3980-0043.wav'
//
// load an audio file into a Buffer
//
// https://nodejs.org/api/fs.html#fs_file_system_flags
const audioBuffer = fs.readFileSync(sourceFile, { flag: 'rs+' } )
const runThreadTime = setTimer()
const result = await transcriptProcess(modelPath, scorerPath, audioBuffer)
console.log(`transcript: ${result} (${getTimer(runThreadTime)}ms)`)
}
if (require.main === module)
master()
module.exports = { transcriptProcess }