-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (34 loc) · 1.26 KB
/
index.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
try {
require('./env.js');
} catch(e){
if (!process.env.REV_TOKEN) console.log('error: you need process.env.REV_TOKEN defined in the env.js file, or in the call to this node script.')
}
const fs = require('fs');
// Creates a client
const RevRecognize = require('./revRecognize');
const stream = new RevRecognize({
url: `wss://api.rev.ai/speechtotext/v1alpha/stream?access_token=${process.env.REV_TOKEN}&content_type=audio/x-raw;layout=interleaved;rate=44100;format=S16LE;channels=1`,
headers: ''
});
stream.on('error', err => {
console.log({ msg: 'error from rev stream', err });
}).on('results', results => {
console.log('Transcription: ', results);
}).on('data', data => {
console.log('got final tx data object');
console.log({keys: Object.keys(data), });
})
const filename = './discovery-1min.wav'
// Stream an audio file from disk to the Speech API, e.g. "./resources/audio.raw"
fs.createReadStream(filename).pipe(stream);
const secs = 85;
console.log(`ending stream in ${secs} sec`);
setTimeout(() => {
console.log('end rec stream!')
stream.emit('end');
stream.stop();
console.log('waiting 5 more secs for stream to print final message');
setTimeout(() => {
console.log('end scrript')
}, 5000);
}, secs*1000);