LoginSignup
32
37

More than 5 years have passed since last update.

Google Homeに任意の言葉を喋ってもらう方法 Golang編

Last updated at Posted at 2018-02-11

Google Homeに任意の言葉をしゃべって欲しい、そんな時ってありますよね?

現在は google-home-notifier というプログラムを使う方法が主流ですが、
この記事では、Goのパッケージを利用した方法を紹介します。

コードの取得

# Goがインストールされていない場合
# $ brew install go

$ go get -u github.com/ikasamah/homecast

サンプル実行

まずは example を起動してみます

$ go run $GOPATH/src/github.com/ikasamah/homecast/example/main.go

# GOPATHが設定されていない場合は以下
# $ go run ~/go/src/github.com/ikasamah/homecast/example/main.go

これで、ローカルネットワーク内のGoogle Homeが Hello Worldと喋ります。

次は、サンプルのHTTPサーバーを起動しましょう。

$ go run $GOPATH/src/github.com/ikasamah/homecast/example/server.go

サーバーが起動したら、ブラウザ等で次のURLにアクセスしましょう
http://localhost:8080/?text=こんにちは&lang=ja

textパラメータで指定された内容をGoogle Homeが喋ってくれます。

32
37
1

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
32
37