-
Notifications
You must be signed in to change notification settings - Fork 14
/
stream.js
56 lines (45 loc) · 1.08 KB
/
stream.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
/**
* @module audio-speaker
*
* Wraps node-speaker to ensure format.
*
*/
'use strict';
var inherits = require('inherits');
var Through = require('audio-through');
var NodeSpeaker;
try {
NodeSpeaker = require('speaker');
} catch (e) {
console.warn('`speaker` package was not found. Using `audio-sink` instead.');
NodeSpeaker = require('audio-sink');
}
/**
* Speaker is just a format wrapper for node-speaker,
* as node-speaker doesn’t support any input format in some platforms, like windows.
* So we need to force the most safe format.
*
* @constructor
*/
function AudioSpeaker (opts) {
if (!(this instanceof AudioSpeaker)) {
return new AudioSpeaker(opts);
}
Through.call(this, opts);
//create node-speaker with default options - the most cross-platform case
this.speaker = new NodeSpeaker({
channels: this.channels
});
this.pipe(this.speaker);
}
inherits(AudioSpeaker, Through);
/**
* Predefined format for node-speaker
*/
Object.assign(AudioSpeaker.prototype, {
float: false,
interleaved: true,
bitDepth: 16,
signed: true
});
module.exports = AudioSpeaker;