-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprocess_transcript_worker.js
53 lines (37 loc) · 1012 Bytes
/
process_transcript_worker.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
/**
* @file
*
* The file is a worker thread (worker).
* The worker receive a Buffer (an audio file) from the master (parent) thread
* and transcript the audio using Coqui STT functions.
*
*
*/
const { transcriptNoThread } = require('./transcript.js')
/**
* sleep for a number of milliseconds
*
* @param {Integer} ms milliseconds to sleep
* @return Promise
*/
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
async function fakeWorker(message) {
console.log('worker: parent process request:')
console.log(message)
const msecs = 2000
await sleep(msecs);
const result = 'this is a test'
return result
}
function worker(message) {
const { modelPath, scorerPath, audioBuffer } = message
const result = transcriptNoThread(modelPath, scorerPath, audioBuffer)
return result
}
// receive messages from the parent process
process.on( 'message', async (message) => {
process.send( await worker(message) )
})
// end of worker thread