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 also needed some way to remotely tell Chromcast audio what phrases to say and when. I briefly considered simply using Chromecast Audio stream “as-is” and simply have the a PHP script running on my web server ‘play’ the necessary MP3’s on the server, which would then get cast to the Google Home. That would work but…. several issues. It would play EVERY sound on the PC, every new mail, every ‘ding’, every crazy web page I browsed that auto-ran video. !yuck! It also would keep a continual cast stream always open to the Google Home and that didn’t seem to be a good idea either.
Again, seemed dead-end-ish, until I figured out that Node.js supports it’s own built in web server. With a web server, I could get the Node.js code to accept JSON posts, just like I was doing with the PHP scripting, parse the JSON message, extract what phases to say and tell what was left of the Chromcast audio code to cast those phrase MP3s out to my Google home.
Easy! or at least somewhat easy. I wanted to do compound phrases like “The Door is” and “Open” or “Closed” (with visions of even being able to ‘speak’ numbers). but…. each MP3 that got cast created and then closed a cast stream. This results in a pause and a beep in-between phrases. Not cool. So I had to include code to merge compound phrases together so they could be cast as one complete MP3.
Then because Node.js is pseudo event driven (ok really return callbacks, but still…) back to back JSON posts resulted in two casts trying to overlap each other. Again not good. That took a little work to figure out how to determine when the 1st cast completed so the 2nd cast could be initiated, but finally did get that working too.
Now…. node.js and Electron (upon which Chromecast Audio Stream is built) are both a bit of a beast and I don’t have a standalone install built. What you’d have to do right now to reproduce what I’ve got is go ahead and install Chromecast Audio Stream first. Then replace the main.js and lib.js with the ones found here. Recompile and you should have CastVoice now operational.
Hopefully someone with more node.js and Electron chops than me can pick this up and make it more viable for others to use.