-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreatettsfiles.js
More file actions
57 lines (53 loc) · 1.26 KB
/
createttsfiles.js
File metadata and controls
57 lines (53 loc) · 1.26 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const googleTTS = require('google-tts-api');
const fs = require('fs');
const http = require('http');
async function download(url, dest) {
url = url.replace('https','http');
let file = fs.createWriteStream(dest);
let request = http.get(url, (response) => {
response.pipe(file);
file.on('finish', () => {
file.close();
return dest;
});
}).on('error', (err) => { // Handle errors
fs.unlink(dest);
return "";
});
};
function createTTSfile(text, filename) {
googleTTS(text, 'en', 1) // speed normal = 1 (default), slow = 0.24
.then(function (url) {
download(url, './tts/' + filename + '.mp3');
console.log(url);
})
.catch(function (err) {
console.error(err.stack);
});
}
function createTTSfiles(arr) {
for(let obj of arr)
createTTSfile(obj.text, obj.filename);
}
createTTSfiles([
{
text: 'Hello World',
filename: 'test'
},
{
text: 'Turning lights on',
filename: 'lightson'
},
{
text: 'Turning lights off',
filename: 'lightsoff'
},
{
text: 'Toggling lights',
filename: 'lights'
},
{
text: 'Changing temperature',
filename: 'thermostat'
}
]);