-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample.js
57 lines (45 loc) · 1.11 KB
/
example.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
import NodeMic from './dist/index.js';
import fs from 'fs';
const mic = new NodeMic({
rate: 16000,
channels: 1,
debug: true,
threshold: 6
});
const micInputStream = mic.getAudioStream();
const outputFileStream = fs.createWriteStream('output.raw');
micInputStream.pipe(outputFileStream);
micInputStream.on('data', (data) => {
//console.log('Recieved Input Stream: ' + data.length);
});
micInputStream.on('error', (err) => {
console.log(`Error in Input Stream: ${err.message}`);
});
micInputStream.on('started', () => {
console.log('Starting');
setTimeout(() => {
mic.pause();
}, 5000);
});
micInputStream.on('stopped', () => {
console.log('Stopped');
});
micInputStream.on('paused', () => {
console.log('Paused');
setTimeout(() => {
mic.resume();
}, 5000);
});
micInputStream.on('unpaused', () => {
console.log('Unpaused');
setTimeout(() => {
mic.stop();
}, 5000);
});
micInputStream.on('silence', () => {
console.log('Silence');
});
micInputStream.on('exit', (code) => {
console.log(`Exited with code: ${code}`);
});
mic.start();