[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

Are you a good talker now? Leave it to Google Home to tell you what's difficult to say in just 10 lines!

Hello.
I'm Mandai, in charge of Wild on the development team.

At the end of last year, I received a Google Home at a company reception, but since it was gathering dust at home, I brought it to work and let it talk all I wanted.


 

What to prepare

The only equipment I'll be using this time is Google Home (mini can also be used) and a PC.

The PC does not need to be a Raspberry PI.
If you just want it to talk, anything is fine as long as
google-home-notifier In the case of Windows, rebuilding node-gyp seems to be a problem.
this article may be helpful.

In my case, the CentOS VM was running at the time I was planning to do it, so I was able to quickly create it with the VM.

Additionally, if you have the node cron module, you can also make scheduled communications.

 

Preparation

 

Check the local IP of Google Home

For Android, you can check from the Google Home app

Display the menu from the three lines on the top left and select your device.
If you are able to connect with Google Home, select "Settings" and the IP address should be displayed at the bottom.

 

Installing node.js

You can use yum, but I prefer something newer.
This time I'm using node.js v8.9.4.

 

Installing the libraries required for communication between the PC and Google Home

When you try to install google-home-notifier with npm after preparing node, you may get something like the following.

npm install google-home-notifier > [email protected] install /home/vagrant/Documents/googlehome/node_modules/mdns > node-gyp rebuild make: Entering directory `/home/vagrant/Documents/googlehome/node_modules/mdns/build' CXX(target) Release/obj.target/dns_sd_bindings/src/dns_sd.o In file included from ../src/dns_sd.cpp:1:0: ../src/mdns.hpp:32:20: fatal error: dns_sd.h: No such file or directory #include ^ compilation terminated. make: *** [Release/obj.target/dns_sd_bindings/src/dns_sd.o] Error 1 make: Leaving directory `/home/vagrant/Documents/googlehome/node_modules/mdns/build' gyp ERR! build error gyp ERR! stack Error: `make` failed with exit code: 2 gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258: 23) gyp ERR! stack at emitTwo (events.js:126:13) gyp ERR! stack at ChildProcess.emit (events.js:214:7) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process .js:198:12) gyp ERR! System Linux 3.10.0-693.17.1.el7.x86_64 gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules /node-gyp/bin/node-gyp.js" "rebuild" gyp ERR! cwd /home/vagrant/Documents/googlehome/node_modules/mdns gyp ERR! node -v v8.9.4 gyp ERR! node-gyp -v v3 .6.2 gyp ERR! not ok npm WARN [email protected] No description npm WARN [email protected] No repository field. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [email protected] install: `node-gyp rebuild` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] install script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /home/vagrant/.npm/_logs/2018-03-17T06_56_20_006Z-debug.log

 

The error is that the header file dns_sd.h to include does not exist, but if you run the command below, the header file will also be installed.

sudo yum install avahi-compat-libdns_sd-devel

 

Errors may occur when installing using npm related to node-gyp, but since node-gyp is simply node.js, it is a tool that automates the compilation of sources written in C++ as in this case, so it is usually necessary to build. The problem is a lack of required files.

nvm , it might be easier to clean up afterwards!

 

Install the required modules with npm

All you have to do is install the necessary modules from npm.

The minimum requirement is google-home-notifier, without which you cannot link with Google Home.
If you install node-cron as an option, it will chat periodically, which is perfect for lively.

# Build a working environment mkdir path/to/project cd path/to/project npm init # Install google-home-notifier npm install google-home-notifier # Install module for periodic execution (cron) npm install cron

 

easy sauce

The code prepared here is very simple, so I will expose it first.

// sample1.js const googlehome = require('google-home-notifier'); const googlehome_name = 'Your Google Home Name'; // Google Home name (any name) const googlehome_ip = 'xxx.xxx.xxx.xxx '; // IP address of Google Home const language = 'ja'; // Language you want Google Home to speak (English in US) const message = 'Let's chat'; // Content you want Google Home to speak googlehome.device (googlehome_name, language); googlehome.ip(googlehome_ip); googlehome.notify(message, (res) => { console.log(res); });

 

Save the above source as sample1.js.
Execute the following command.

node sample.js

 

There is almost no need for explanation, but there are three places to change, so please enter them according to your environment.

  • googlehome_name
  • googlehome_ip
  • language

Please be careful around the 8th and 9th line.
It seems that a lot of people are addicted to it, and originally it seems that you can resolve the name (DNS lookup) using the name given to Google Home with just the 8th line, but it often doesn't work, so you can do a DNS lookup with the name given to Google Home on the 9th line. Specified.

If you are specifying an IP address, line 8 is unnecessary, but it seems that the language setting can only be done from the device() method, so I purposely wrote both.

 

Develop it so that it can be executed regularly

Since the google-home-notifier module is very well made, I didn't have much to do with it, so I decided to develop it a little more and say something periodically, preferably with cron, so I did something like that. I'll take a look.
I would like to implement it using the npm module cron instead of using Linux cron.

// sample2.js const googlehome = require('google-home-notifier'); const CronJob = require('cron').CronJob; const messages = require('./messages'); // Execution interval and content to talk about const googlehome_name = 'Your Google Home Name'; // Google Home name (anything is fine) const googlehome_ip = 'xxx.xxx.xxx.xxx'; // Google Home IP address const language = 'ja '; // Language you want Google Home to speak (English in US) googlehome.device(googlehome_name, language); googlehome.ip(googlehome_ip); messages.forEach((m) => { new CronJob({ cronTime: m .schedule, onTick: () => { googlehome.notify(m.message, (res) => { console.log(res); }); }, start : true, timeZone: 'Asia/Tokyo', }) ; });

 

Below is a definition file containing the sentences to be spoken and the schedule.

// messages.js module.exports = [ // The writing style is almost the same as Linux cron { schedule: '0 0 10,13,16,19,22 * * *', message: 'Hogehoge' }, / / Note the concept of seconds at the beginning { schedule: '0 0 22 * ​​* *', message: 'test' }, // Write with numbers, asterisks, commas, hyphens, and slashes { schedule: '0 */5 9-18 1,2,3 * *', message: 'I will speak every 5 minutes from 9:00 to 18:00 in January, February, and March' }, ];

 

If you make messages.js fatter, it will talk about various things and you will be able to enjoy it for a while.

 

summary

I had a lot of fun just having a device that I could talk to.
Above all, the level of abstraction of google-home-notifier is so great that you can say that you don't need to do anything on your part, but it's amazing that you can just give the string you want to speak as an argument. I think it could become more common.
I thought that if all this was included in the Google Home package, it would probably sell better, but would it be too much?

 
That's it.

If you found this article helpful , please give it a like!
0
Loading...
0 votes, average: 0.00 / 10
1,714
X facebook Hatena Bookmark pocket
[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

The person who wrote this article

About the author

Yoichi Bandai

My main job is developing web APIs for social games, but I'm also fortunate to be able to do a lot of other work, including marketing.
Furthermore, my portrait rights in Beyond are treated as CC0 by him.