Return to Tricks with Google Home

Make Google Home Speak

After I got my Google Home cooperating with my Particle garage door opener, I thought there was still something meeting….  Feedback!

The very first thing you want to do after doing the “Ok Google, open the garage door” trick is to ask “OK Google, is the garage door open?”  Turns out that’s really difficult.  The IFTTT interface allows you to intercept “OK Google” commands, but the only feedback is hard-coded.  So one “OK Google” command = one pre-programmed verbal response.  No way to actually tell Google Home to pick from a list of statements based on a response and no way to send a “notification” message to Google Home.

It looked like it was a dead-end.

The I ran across Chromcast-audio-stream.  it’s an interesting little app that lets you stream the audio on your PC out to a chromcast device, which of course Google Home, is a chromecast device as well.  Now… Chromecast audio stream is a Node.js application and I’m barely literate in java.  It’s also a bit complicated in it’s functionality as it has a pseudo sound card driver that intercepts the .wav audio stream coming from the PC, converts that to an MP3 stream and finally casts it out to the selected chromcast define.

Whew…. but casting an MP3 seemed like kind of the direction I needed to go.  It’s pretty straight forward to convert text to MP3s (SoundOfText is what I used)  Once I had MP3 ‘phrases’ I hoped it would be a simple matter to get Chromcast audio stream to cast those MP3 phrases to Google Home.

I did then use Chromcast-audio-stream for awhile to get Google to speak.  I’ve got a modified version on GitHub over here, but…. it’s clunky and hard to maintain.  The Electron implementation it’s based on might actually be the way to go for a production product, but it’s difficult deal with in a DIY space where you need to constantly tweak and rebuild.  But it worked, so I used it for awhile.

Then, I ran across Google-Home-Notifier, based on Node.js.  Much simpler code than the Chromcast-audio-stream implementation.  I still needed to modify it a bit to fit my DIY needs so my own GitHub fork is here. The main thing I modified was building an example that ran a small web server to accept JSON requests and to host MP3 audio phrase files.  The audio phrase idea is a carry over from my Chromcast audio stream implement and is not strictly necessary because Google-Home-Notifier also supports on the fly Text to Speech conversion.  But I figured eventually with fixed phrases I might want to skip the contact TTS and still use MP3’s so I kept the functionality.  In the JSON functionality I added being able to specify Text, and MP3 and the Device to cast to.  That was really all just in the example ‘client’.

I did also modify the back-end a bit.  The problem with the whole idea of using CASTing to make Google Home speak, is that it stops any current CAST.  For my Google-Home-Notifier implementation I wanted to serialize the ‘Notify’ requests so that at least they would not step on each other.  Implementing that queuing in the front-end example client, required modifying the back-end because the original back-end returned when the CAST was launched, not when the CAST finished.   Switching to calling back on CAST finish was a bit of a trick since there is no event I could find for that.  Simply had to monitor the status of the CAST to watch it going from IDLE to BUFFERING to PLAYING an then back to IDLE to know when a CAST was done.

Using my forked Google-Home-Notifier is easy, install Node.js and then run the example.js to start the process.  Look what port it’s running on (it’ll say when it launches) and use an HTML POST to send a JSON string like this

{“SpeakTXT”:”Hello”,”Device”:”The name you gave your google home device”}

A quick and dirty way to do that is with Android Tasker and a HTTP Post Action.  Set the Server:Port to what example.js displayed, set the path to / and then set the Data/File to your JSON string.  Don’t forget to also set the Content Type to application/json as well.  The run the task.  You should see the information show up in the example.js console and then hear your Google Home speak