LoginSignup
3
3

More than 3 years have passed since last update.

Raspberry Pi3 で Google Home に喋らせる

Posted at

Raspberry Pi と Google-home-notifier を使うと Google Home に
メッセージをプッシュすることができる

OSのインストール

:strawberry: Raspbian をインストールする。
2019/10 時点で最新の Buster を使うとうまく構築できないので
一つ前のバージョン Stretch からダウンロード:inbox_tray: を使う。
イメージを MicroSDカード:floppy_disk: に書き込んで、無線LAN設定ぐらいまで終わらせておく。

$ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
VERSION_CODENAME=stretch
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
$ cat /etc/debian_version 
9.11

お約束の最新化と node、npm インストール

インストールしたらバージョンチェックもしておく。

$ sudo apt update & apt upgrade
$ sudo apt install -y nodejs npm
$ sudo npm cache clean
$ sudo npm install npm n -g
$ sudo n lts
$ node --version
v10.16.3
$ npm --version
6.9.0

次のパッケージもインストールしておく

$ sudo apt-get install git-core libnss-mdns libavahi-compat-libdnssd-dev

README.md 参照

Google Home Notifier インストール

$ mkdir ghn
$ cd ghn
$ npm install google-home-notifier

インストール後の作業

google-tts-apiのバージョンアップ
package.json の google-tts-api を 0.0.4 に設定

node_modules/google-home-notifier/package.json
   "bundleDependencies": false,
   "dependencies": {
     "body-parser": "^1.15.2",
     "castv2-client": "^1.1.2",
     "express": "^4.14.0",
-    "google-tts-api": "https://github.com/darrencruse/google-tts/tarball/british-voice",
+    "google-tts-api": "0.0.4",
     "mdns": "^2.3.3",
     "ngrok": "^2.2.4"
   },

修正したpackage.jsonで更新

$ cd node_modules/google-home-notifier/
$ npm update google-tts-api

browser.js の修正

node_modules/mdns/lib/browser.js
 Browser.defaultResolverSequence = [
-  rst.DNSServiceResolve(), 'DNSServiceGetAddrInfo' in dns_sd ? rst.DNSServiceGetAddrInfo() : rst.getaddrinfo()
+  rst.DNSServiceResolve(), 'DNSServiceGetAddrInfo' in dns_sd ? rst.DNSServiceGetAddrInfo() : rst.getaddrinfo({families:[4]})
 , rst.makeAddressesUnique()
 ];

rst.getaddrinfo に引数 {families:[4]} を追加する。

main.js
const googlehome = require('google-home-notifier')
const language = 'ja';

const msg = process.argv[2]

googlehome.device('Google-Home', language);
googlehome.notify(msg, function(res) {
  console.log(res);
});
node main.js メッセージを送信しました

応用例)
IFTTTと連携させると、家のそばに来たらメッセージを喋らせるなどを行うことができる。
WebAPIを作ってメッセージを投げられるようにすれば、外部から発話させることができる。

今後の課題)
音楽を流しているとき、メッセージをプッシュすると音楽が止まってしまう。

参照:https://github.com/noelportugal/google-home-notifier

3
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3