forked from lexoyo/marcel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeaker.js
More file actions
36 lines (32 loc) · 1.02 KB
/
speaker.js
File metadata and controls
36 lines (32 loc) · 1.02 KB
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
var streamArray = require("stream-array");
var makeProp = require("make-prop-stream");
var speechStream = require("speech-stream");
// var forceSpeed = 130;
// var randomvoice = require("randomvoice")();
// randomvoice.speed = forceSpeed || randomvoice.speed;
const Speaker = function(config) {
this.config = config;
this.voice = config.voice;
};
exports.Speaker = Speaker;
Speaker.prototype = {
say: function(phrase, cbk) {
console.log('speaker says:', phrase);
var Speaker = require('speaker');
var wav = require('wav');
var reader = new wav.Reader();
// the "format" event gets emitted at the end of the WAVE header
reader.on('format', function (format) {
// the WAVE header is stripped from the output of the reader
reader.pipe(new Speaker(format));
});
reader.on('end', function () {
if(cbk) cbk();
});
// console.log('random voice options: ', randomvoice);
streamArray([phrase])
.pipe(makeProp("message"))
.pipe(speechStream(this.voice))
.pipe(reader)
}
}