LoginSignup
4
13

More than 5 years have passed since last update.

お手軽!!5分でGoogle Homeに任意の文章を喋らせる

Last updated at Posted at 2018-05-13

やっていること

  • Google Homeからアクセス可能なURLにMP3音声ファイルを作成する。
  • python3のライブラリpychormecastを使用し、Google HomeにMP3の再生指示を出す。
  • Google Homeで再生される。

必要な物

  • Google Home
  • PC
    • python3
    • pip

準備

ネットワーク接続

PCとGoogle Homeを同一ネットワークに接続する

pychromecastのインストール

$ pip install pychromecast

MP3音声ファイルの作成

最短での実現を目指すためSound of Textを利用

  1. Textに喋らせたい文章を入力
  2. Voiceで言語を指定
  3. Submitを押す
  4. Downloadのリンク先URLをコピーする ※PCにはダウンロードしない

実行

以下通り実行するとGoogle Homeが喋ります。
xxxは実際の値ではありません。

$ python
>>> import pychromecast
>>> chromecasts = pychromecast.get_chromecasts()
>>> chromecasts
[Chromecast('192.168.10.8', port=8009, device=DeviceStatus(friendly_name='リビング', model_name='Google Home Mini', manufacturer='Google Inc.', uuid=UUID('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'), cast_type='cast'))]
>>> google_home = chromecasts[0]
>>> mc = google_home.media_controller
>>> mc.play_media('https://soundoftext.nyc3.digitaloceanspaces.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.mp3','audio/mp3')

最後に

最短でGoogle Homeを喋らせることを目標としましたが、
任意の文章を動的に生成するならPythonを使って、Google Homeに喋らせてみる
のような方法でやる必要がありそうです。

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