just because sometime i'm kind... (my favorite sentence!)
Try this:
const gTTS = require('gtts');
var player = require('play-sound')(
opts = {
player: "mpg123" // use only `mpg123` for playing sounds
}
);
var gtts = new gTTS('text to speak', 'es-es');
// main file player
function playing (file) {
player.play(file, (err) => {
if (err) throw new Error(err)
});
}
gtts.save('/tmp/hello.wav', (err, result) => {
if(err) { throw new Error(err) }
console.log('Success! start playing result.');
// right ! sound file is created let's play it !
playing("/tmp/hello.wav");
});
Notes:
- You need to install
mpg123app withsudo apt-get install mpg123 - I replace your
playlibrary byplay-soundfor better compatibility
Don’t forget to install this librarynpm install play-sound - You can see manual of
play-soundlibrary there