Skip to content

Instantly share code, notes, and snippets.

@Aymkdn
Last active November 14, 2017 15:52
Show Gist options
  • Save Aymkdn/a6a3fc55f72b017da6d987aac812c76f to your computer and use it in GitHub Desktop.
Save Aymkdn/a6a3fc55f72b017da6d987aac812c76f to your computer and use it in GitHub Desktop.
Have Google Home to speak
// npm install castv2-client google-tts-api
var Client = require('castv2-client').Client;
var client = new Client();
var DefaultMediaReceiver = require('castv2-client').DefaultMediaReceiver;
var GoogleTTS = require('google-tts-api');
var host = "192.168.0.13"; // IP Address of the Google Home
var text = "Bonjour et bienvenue"; // Text to speach
var lang = "fr-FR"; // language
GoogleTTS(text, lang, 1)
.then(function(url) {
client.connect(host, function() {
client.launch(DefaultMediaReceiver, function(err, player) {
var media = {
contentId: url,
contentType: 'audio/mp3',
streamType: 'BUFFERED'
};
player.load(media, {
autoplay: true
}, function(err, status) {
player.on('status', function(status) {
if (status.playerState == "IDLE") {
player.stop();
client.close();
}
});
});
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment