-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (33 loc) · 948 Bytes
/
index.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
'use strict';
/**
* Module dependencies.
*/
var googleTTS = require('google-tts-api');
var player = require('play-sound')({});
var wget = require('wget-improved');
/**
* Accepts a string as parameter, converts it into an mp3 and plays the sound
* @param {string} string
* @return {string}
*/
function basicTtsPlayer(string) {
googleTTS(string, 'en', 1).then(function (url) {
const options = { };
let download = wget.download(url, '/tmp/basic-tts-player.mp3', options);
download.on('error', function(err) {
console.log(err);
});
download.on('end', function(output) {
player.play('/tmp/basic-tts-player.mp3', function(err){
if (err) throw err
return {
url: url
};
});
});
})
.catch(function (err) {
console.error(err.stack);
});
};
module.exports = basicTtsPlayer;