スマートスピーカーが流行っています。Google HomeやAmazon Echo、AppleのHomePodなどを購入し、自宅やオフィスに置いている方も多いかと思います。そうしたスマートスピーカーはカスタマイズしてこそ価値が出ます。とは言えテキスト認識処理を行って、クラウドサービスを呼び出したりするのは大変です。 そこで使ってみたいのがhomecastです。LAN内であれば、Google Homeに認識の言葉を喋らせることができます。

homecastの使い方

例えばこんなコードを書きます。言語を指定すればちゃんと日本語も流ちょうに喋ってくれます。

package main

import (
	"context"
	"fmt"

	"github.com/ikasamah/homecast"
)

func main() {
	ctx := context.Background()
	devices := homecast.LookupAndConnect(ctx)

	for _, device := range devices {
		fmt.Printf("Device: [%s:%d]%s", device.AddrV4, device.Port, device.Name)

		if err := device.Speak(ctx, "こんにちは世界", "ja"); err != nil {
			fmt.Printf("Failed to speak: %v", err)
		}
	}
}

後は実行するだけです。自動的にGoogle Homeを見つけて、喋らせてくれます。

$ go run main.go
2018/02/19 09:03:42.710124 [ERR] mdns: Failed to bind to udp6 port: listen udp6 [ff02::fb]:5353: setsockopt: can't assign requested address
2018/02/19 09:03:42.873457 [INFO] ServiceEntry detected: [192.168.0.XX:8009]Google-Home-c5c801a79c4fdb387e69d58ed0d70f01._googlecast._tcp.local.
2018/02/19 09:03:42.906080 [INFO] ServiceEntry detected: [192.168.0.99:8009]Google-Home-95adced04d38805ecfb019b7d71030ce._googlecast._tcp.local.
2018/02/19 09:03:43.714772 [INFO] mdns: Closing client {0xc420096020 0xc420096028 0xc420096030 <nil> true 0xc420078240 {1 0}}
Device: [192.168.0.XX:8009]Google-Home-c5c801a79c4fdb387e69d58ed0d70f01._googlecast._tcp.local.2018/02/19 09:03:43.714921 [ERR] mdns: Failed to read packet: read udp6 [::]:55550: use of closed network connection
2018/02/19 09:03:43.714959 [ERR] mdns: Failed to read packet: read udp4 0.0.0.0:55549: use of closed network connection
2018/02/19 09:03:43.715015 [ERR] mdns: Failed to read packet: read udp4 0.0.0.0:5353: use of closed network connection
2018/02/19 09:03:44.643390 [INFO] Load media: content_id=https://translate.google.com/translate_tts?client=tw-ob&ie=UTF-8&q=%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF%E4%B8%96%E7%95%8C&tl=ja
Device: [192.168.0.99:8009]Google-Home-95adced04d38805ecfb019b7d71030ce._googlecast._tcp.local.2018/02/19 09:03:46.421228 [INFO] Load media: content_id=https://translate.google.com/translate_tts?client=tw-ob&ie=UTF-8&q=%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF%E4%B8%96%E7%95%8C&tl=ja

LAN内に限定はされますが、思いの外簡単に喋らせられるので面白いです。社内であれば最後の話す部分だけを利用して、データを読ませたりイベントの通知を行うこともできるでしょう。色々な使い道が考えられそうなソフトウェアです。

homecastはGo製のオープンソース・ソフトウェア(MIT License)です。

ikasamah/homecast: Text-to-Speech on your Google Home