-
Notifications
You must be signed in to change notification settings - Fork 1
/
tts.js
61 lines (46 loc) · 1.7 KB
/
tts.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
58
59
60
61
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const events = require('events');
class Tts extends events.EventEmitter {
constructor(data) {
super();
}
init(options) {
let qs = require('querystring');
let params = {};
//required
params['text'] = options['text'];
params['key'] = options['key'];
//optional
params['speaker'] = (options['speaker']) ? options['speaker'] : 'jane';
params['format'] = (options['format']) ? options['format'] : 'mp3';
params['quality'] = (options['quality']) ? options['quality'] : 'hi';
params['platform'] = (options['platform']) ? options['platform'] : 'web';
params['application'] = (options['application']) ? options['application'] : 'translate';
params['lang'] = (options['lang']) ? options['lang'] : 'ru_RU';
console.log('Text To Speech settings', params);
return qs.stringify(params);
};
request(url, filePath, callback) {
let request = require('request');
let fs = require('fs');
let yandex_tts_url = 'https://speech.kloud.one/tts?';
let fullUrl = yandex_tts_url + url;
function download(callback) {
let file = fs.createWriteStream(filePath);
file.on('finish', function () {
file.close(callback);
});
request(fullUrl)
.on('error', err => {
console.log('Error', err);
if (err) {
callback(err);
}
}).
pipe(file);
}
download(callback);
};
}
module.exports = Tts;