LoginSignup
1
4

More than 5 years have passed since last update.

Raspberry Pi から GoogleHome を喋らせる & 音声ファイル再生(google-home-notifier)

Last updated at Posted at 2018-02-03

Raspberry Pi から GoogleHome を喋らせる & 音声ファイル再生(google-home-notifier)

google-home-notifier を利用して、Raspberry Pi から指定の文字列や音声ファイルをGoogleHomeで再生します。
google-home-notifier

準備

必要なパッケージをインストールします。
Node.jsは導入されているので省略します。

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

google-home-notifier の入手

google-home-notifierをgit から clone します。

$ git clone https://github.com/noelportugal/google-home-notifier

google-home-notifier のインストール

google-home-notifier をインストールします。

$ cd google-home-notifier
$ npm install

喋らせる

インストールディレクトリ内の「example.js」を参考に 以下のスクリプトを作成し、Google Home を喋らせます。
「ip」に GoogleHome のIPアドレスを入力します。
「googlehome.notify」の引数に喋らせたい文言を設定します。

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

var deviceName = 'GoogleHome';
var ip = '<GoogleHomeのIPアドレス>';

googlehome.ip(ip, language);
googlehome.device(deviceName, language); 

googlehome.notify('こんにちわ。私はGoogleHomeです。', function(notifyRes) {
      console.log(notifyRes);
});
$ node notify.js

仕組み

Google Text To Speech で文字列を音声化して、GoogleHomeで再生しているようです。

Google Text To Speech

Google翻訳で確認できます。文字列を入力してスピーカーのアイコンを押すと音声出力されます。
https://translate.google.com/

「こんにちわ。私はGoogleHomeです。」と入力して、出力されている音声は以下でした。
MP3でした。
https://translate.google.com/translate_tts?ie=UTF-8&q=%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%82%8F%E3%80%82%E7%A7%81%E3%81%AFGoogleHome%E3%81%A7%E3%81%99%E3%80%82&tl=ja&total=1&idx=0&textlen=21&tk=972902.571097&client=t&prev=input

音声ファイルの再生

音声ファイルを再生しているということで、ネットワーク上のMP3ファイルを指定して再生することも可能です。

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

var deviceName = 'GoogleHome';
var ip = '<GoogleHomeのIPアドレス>';

googlehome.ip(ip, language);
googlehome.device(deviceName, language); 

googlehome.play('http://<MP3ファイルのURL>', function(notifyRes) {
  console.log(notifyRes);
});
$ node play.js

ところで

「example.js」を実行すると以下のように表示されます。

$ node example.js

~(略)~
Endpoints:
    http://<GoogleHomeのローカルIPアドレス>:8091/google-home-notifier
    https://xxxxxx.ngrok.io/google-home-notifier
GET example:
curl -X GET https://xxxxxx.ngrok.io/google-home-notifier?text=Hello+Google+Home
POST example:
curl -X POST -d "text=Hello Google Home" https://xxxxxx.ngrok.io/google-home-notifier

ngrok を利用して間接的にGoogleHomeがインターネットに公開されているようです。
GoogleHomeを喋らせるだけであれば、グローバルにGoogleHomeを公開する必要はありません。

1
4
0

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
1
4