#author("2020-03-15T23:34:51+00:00","default:mizutu","mizutu")
[[私的AI研究会]] > Google API

* Google Cloud Platform の利用 [#ue475a74]
#ref(画像一覧/20200210_000002_001s.jpg,right,around,25%,20200210_000002_001s.jpg)
#contents

** 登録と設定 [#qb28dd80]
> &color(red){2019/06「Google Assistant Library」の破棄に伴い既存の情報はその公開時期を確認する必要が必須となった。};~
以下、書籍「Raspberry Pi + AI 電子工作入門」の手順を参考に 2020/03 現在の実行手順を検証した。~
※&color(green){(ページ数)}; は「Raspberry Pi + AI 電子工作入門」の該当ページを示す。

*** 事前準備として Googleアカウント(Gmailアカウント)を用意 [#pb7fd4df]
- [[https://accounts.google.com/signup>+https://accounts.google.com/signup]] で Googleアカウントの新規作成画面を表示し、アカウントを作成する。~

> (姓)いづつ (名)まさひろ~
(ユーザー名) idzutsumasahiro@gmail.com~
(パスワード) *********~
(電話番号) XXX-XXXX-XXXX~
(メールアドレス) XXXXXXXXX@XXXXX~
(生年月日) XXXX/XX/XX~
(性別) 男性~

*** 「Google Cloud Platform」登録と設定 [#l3c58349]





&color(red){ ※ 以下の登録と設定手順は 2020/03/05 現在再現不能である。};
新しい手順は [[Google Cloud2]] を参照のこと。
*** 「Cloud Platform」サインアップ [#r9ffe59e]
- [[https://console.cloud.google.com>+https://console.cloud.google.com/]] でクラウド・プラットフォーム・コンソールにアクセスしてGmailアカウントでログインする。~
個人的な利用の「自分用」を選び、新規プロジェクトを作成する。
-- プロジェクト名:RaspberryAi
-- プロジェクトID: raspberryai-mizutu

*** 「Google Assistant API」の有効化 [#a23d3668]
- 「Cloud Platform」上の検索窓から Assistant API を表示し、APIを有効化する。

** Assistant SDK クラウド設定 [#o912688c]
*** 「Action on Google」プロジェクトの作成 [#dac12688]
#ref(画像一覧/20200210_000001_001s.jpg,right,around,25%,20200210_000001_001s.jpg)
#ref(画像一覧/20200210_000000_001s.jpg,right,around,25%,20200210_000000_001s.jpg)
- [[https://console.actions.google.com/>+https://console.actions.google.com/]] にアクセスして新規プロジェクトを作成する。
-- ProjectName: RaspberryAi
-- language: Japanese
-- country:  Japan
#clear

*** 「Google API」認証情報の設定 [#u3fb481a]
- [[https://console.developers.google.com/apis/credentials/consent>+https://console.developers.google.com/apis/credentials/consent]] にアクセスし、「アプリを編集」を押し左カラム「OAuth 同意画面」を選択。
-- アプリケーション名:RasAiApp
-- その他の項目はデフォールトで作成する。

*** アクティビティの設定 [#scb00313]
- [[https://myaccount.google.com/activitycontrols>+https://myaccount.google.com/activitycontrols]] にアクセスし、「ウェブアプリのアクティビティ」「デバイス情報」「音声アクティビティ」をONにする。

*** モデルの登録 [#d688e7f8]
- [[https://console.actions.google.com/>+https://console.actions.google.com/]] にアクセスしてデバイスを登録する。
-- Action Console からプロジェクトを選択し、Develop タブの左カラムDevice registration を選び「REGISTER MODEL」からデバイス登録する。
-- Product name: RasAiPrd
-- Manufacture name: RasAiMnf
-- Device Type: Speaker (選択)
-- Model Id: raspberryai-rasaiprd (自動生成されるIDを使う)
--「REGISTER MODEL」を押す。

*** Traitsの設定 [#k37e74dd]
- 前項の操作によって証明書ダウンロードのページが表示される。~
&Color(red){Windowsの場合(Edge/IE)ダウンロードボタンを押してもダウンロードできない(2020/02/19現在)ので次に進む。};
- All traits を選んでSAVE する。
- デバイスの登録が終わるとデバイス一覧に表示される。この画面から証明書の再取得ができる。~
&Color(red){VNCビューアなどからRaspberry Pi 上のWEBブラウザを呼び出し先の画面の再取得で証明書をダウンロードすることができる。(取得場所: ~/Downloads)};

** Assistant SDK (Python) インストール [#i17c14bf]
*** Raspberry Pi での導入準備 [#e8763cdf]
-「Python3」と開発環境仮想化できる「venv」をインストール
 pi@raspberrypi:~ $ sudo apt install python3-dev python3-venv
 パッケージリストを読み込んでいます... 完了
 依存関係ツリーを作成しています                
 状態情報を読み取っています... 完了
 python3-dev はすでに最新バージョン (3.7.3-1) です。
 python3-dev は手動でインストールしたと設定されました。
 python3-venv はすでに最新バージョン (3.7.3-1) です。
 python3-venv は手動でインストールしたと設定されました。
 アップグレード: 0 個、新規インストール: 0 個、削除: 0 個、保留: 0 個。

- 仮想環境を作成
 pi@raspberrypi:~ $ python3 -m venv env

- 仮想環境のパッケージをアップデート
 pi@raspberrypi:~ $ env/bin/python -m pip install --upgrade pip setuptools wheel
 Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
 Collecting pip
   Downloading https://files.pythonhosted.org/packages/54/0c/d01aa759fdc501a58f431eb594a17495f15b88da142ce14b5845662c13f3/pip-20.0.2-py2.py3-none-any.whl (1.4MB)
     100% |████████████████████████████████| 1.4MB 273kB/s 
 Collecting setuptools
   Downloading https://files.pythonhosted.org/packages/3d/72/1c1498c1e908e0562b1e1cd30012580baa7d33b5b0ffdbeb5fde2462cc71/setuptools-45.2.0-py3-none-any.whl (584kB)
     100% |████████████████████████████████| 593kB 618kB/s 
 Collecting wheel
   Downloading https://files.pythonhosted.org/packages/8c/23/848298cccf8e40f5bbb59009b32848a4c38f4e7f3364297ab3c3e2e2cd14/wheel-0.34.2-py2.py3-none-any.whl
 Installing collected packages: pip, setuptools, wheel
   Found existing installation: pip 18.1
     Uninstalling pip-18.1:
       Successfully uninstalled pip-18.1
   Found existing installation: setuptools 40.8.0
     Uninstalling setuptools-40.8.0:
       Successfully uninstalled setuptools-40.8.0
 Successfully installed pip-20.0.2 setuptools-45.2.0 wheel-0.34.2

- 保存ライブラリのインストール
 pi@raspberrypi:~ $ sudo apt install portaudio19-dev libffi-dev libssl-dev libmpg123-dev
 パッケージリストを読み込んでいます... 完了
 依存関係ツリーを作成しています                
 状態情報を読み取っています... 完了
 libssl-dev はすでに最新バージョン (1.1.1d-0+deb10u2+rpt1) です。
 libssl-dev は手動でインストールしたと設定されました。
 以下の追加パッケージがインストールされます:
   libasound2-dev libjack-jackd2-dev libout123-0 libportaudiocpp0
 提案パッケージ:
   libasound2-doc portaudio19-doc
 以下のパッケージが新たにインストールされます:
   libasound2-dev libffi-dev libjack-jackd2-dev libmpg123-dev libout123-0 libportaudiocpp0 portaudio19-dev
 アップグレード: 0 個、新規インストール: 7 個、削除: 0 個、保留: 0 個。
 602 kB のアーカイブを取得する必要があります。
 この操作後に追加で 1,924 kB のディスク容量が消費されます。
 続行しますか? [Y/n] y
 取得:1 http://archive.raspberrypi.org/debian buster/main armhf libasound2-dev armhf 1.1.8-1+rpt1 [145 kB]
 取得:2 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian buster/main armhf libffi-dev armhf 3.2.1-9 [159 kB]
 取得:3 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian buster/main armhf libjack-jackd2-dev armhf 1.9.12~dfsg-2 [92.9 kB]          
 取得:4 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian buster/main armhf libout123-0 armhf 1.25.10-2 [35.5 kB]
 取得:5 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian buster/main armhf libmpg123-dev armhf 1.25.10-2 [54.9 kB]
 取得:6 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian buster/main armhf libportaudiocpp0 armhf 19.6.0-1 [16.8 kB]
 取得:7 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian buster/main armhf portaudio19-dev armhf 19.6.0-1 [98.6 kB]
 602 kB を 4秒 で取得しました (149 kB/s)   
 以前に未選択のパッケージ libasound2-dev:armhf を選択しています。
 (データベースを読み込んでいます ... 現在 156865 個のファイルとディレクトリがインストールされています。)
 .../0-libasound2-dev_1.1.8-1+rpt1_armhf.deb を展開する準備をしています ...
 libasound2-dev:armhf (1.1.8-1+rpt1) を展開しています...
 以前に未選択のパッケージ libffi-dev:armhf を選択しています。
 .../1-libffi-dev_3.2.1-9_armhf.deb を展開する準備をしています ...
 libffi-dev:armhf (3.2.1-9) を展開しています...
 以前に未選択のパッケージ libjack-jackd2-dev:armhf を選択しています。
 .../2-libjack-jackd2-dev_1.9.12~dfsg-2_armhf.deb を展開する準備をしています ...
 libjack-jackd2-dev:armhf (1.9.12~dfsg-2) を展開しています...
 以前に未選択のパッケージ libout123-0:armhf を選択しています。
 .../3-libout123-0_1.25.10-2_armhf.deb を展開する準備をしています ...
 libout123-0:armhf (1.25.10-2) を展開しています...
 以前に未選択のパッケージ libmpg123-dev:armhf を選択しています。
 .../4-libmpg123-dev_1.25.10-2_armhf.deb を展開する準備をしています ...
 libmpg123-dev:armhf (1.25.10-2) を展開しています...
 以前に未選択のパッケージ libportaudiocpp0:armhf を選択しています。
 .../5-libportaudiocpp0_19.6.0-1_armhf.deb を展開する準備をしています ...
 libportaudiocpp0:armhf (19.6.0-1) を展開しています...
 以前に未選択のパッケージ portaudio19-dev:armhf を選択しています。
 .../6-portaudio19-dev_19.6.0-1_armhf.deb を展開する準備をしています ...
 portaudio19-dev:armhf (19.6.0-1) を展開しています...
 libjack-jackd2-dev:armhf (1.9.12~dfsg-2) を設定しています ...
 libffi-dev:armhf (3.2.1-9) を設定しています ...
 libout123-0:armhf (1.25.10-2) を設定しています ...
 libportaudiocpp0:armhf (19.6.0-1) を設定しています ...
 libasound2-dev:armhf (1.1.8-1+rpt1) を設定しています ...
 libmpg123-dev:armhf (1.25.10-2) を設定しています ...
 portaudio19-dev:armhf (19.6.0-1) を設定しています ...
 libc-bin (2.28-10+rpi1) のトリガを処理しています ...
 man-db (2.8.5-2) のトリガを処理しています ...
 install-info (6.5.0.dfsg.1-4+b1) のトリガを処理しています ...

- 仮想環境を有効化(アクティベイト)
 pi@raspberrypi:~ $ source ~/env/bin/activate
 (env) pi@raspberrypi:~ $
&color(green){以降、(env) $ のコマンドプロンプトの場合は仮想環境下にある。};

*** 仮想環境のコントロール [#d8cb3161]
- Activate (有効化)
 pi@raspberrypi:~ $ source ~/env/bin/activate

- python のバージョン確認
 (env) pi@raspberrypi:~ $ python -V
 Python 3.7.3

- Deactivate (無効化)
 (env) pi@raspberrypi:~ $ deactivate

- 終了(無効化)確認
 pi@raspberrypi:~ $ python -V
 Python 2.7.16

- 参考サイト: [[venv: Python 仮想環境管理>+https://qiita.com/fiftystorm36/items/b2fd47cf32c7694adc2e]]

*** Assistant SDK (Pyton) インストール [#ze97ef60]
- Assistant Library のインストール (env)
 (env) pi@raspberrypi:~ $ python -m pip install --upgrade google-assistant-library==1.0.1
 Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
 Collecting google-assistant-library==1.0.1
   Downloading google_assistant_library-1.0.1-py2.py3-none-linux_armv7l.whl (5.6 MB)
      |████████████████████████████████| 5.6 MB 9.5 kB/s 
 Collecting argparse<2,>=1.4.0
   Downloading argparse-1.4.0-py2.py3-none-any.whl (23 kB)
 Collecting google-auth<2,>=1.0.1
   Downloading google_auth-1.11.0-py2.py3-none-any.whl (76 kB)
      |████████████████████████████████| 76 kB 1.5 MB/s 
 Collecting requests<3,>=2.14.2
   Downloading requests-2.22.0-py2.py3-none-any.whl (57 kB)
      |████████████████████████████████| 57 kB 1.6 MB/s 
 Collecting pathlib2<3,>=2.3.0
   Downloading pathlib2-2.3.5-py2.py3-none-any.whl (18 kB)
 Collecting enum34<2,>=1.1.6
   Downloading enum34-1.1.6-py3-none-any.whl (12 kB)
 Collecting six>=1.9.0
   Downloading six-1.14.0-py2.py3-none-any.whl (10 kB)
 Collecting cachetools<5.0,>=2.0.0
   Downloading cachetools-4.0.0-py3-none-any.whl (10 kB)
 Collecting pyasn1-modules>=0.2.1
   Downloading pyasn1_modules-0.2.8-py2.py3-none-any.whl (155 kB)
      |████████████████████████████████| 155 kB 639 kB/s 
 Requirement already satisfied, skipping upgrade: setuptools>=40.3.0 in ./env/lib/python3.7/site-packages (from google-auth<2,>=1.0.1->google-assistant-library==1.0.1) (45.2.0)
 Collecting rsa<4.1,>=3.1.4
   Downloading rsa-4.0-py2.py3-none-any.whl (38 kB)
 Collecting chardet<3.1.0,>=3.0.2
   Downloading chardet-3.0.4-py2.py3-none-any.whl (133 kB)
      |████████████████████████████████| 133 kB 2.5 MB/s 
 Collecting idna<2.9,>=2.5
   Downloading idna-2.8-py2.py3-none-any.whl (58 kB)
      |████████████████████████████████| 58 kB 1.7 MB/s 
 Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1
   Downloading urllib3-1.25.8-py2.py3-none-any.whl (125 kB)
      |████████████████████████████████| 125 kB 3.1 MB/s 
 Collecting certifi>=2017.4.17
   Downloading certifi-2019.11.28-py2.py3-none-any.whl (156 kB)
      |████████████████████████████████| 156 kB 3.1 MB/s 
 Collecting pyasn1<0.5.0,>=0.4.6
   Downloading pyasn1-0.4.8-py2.py3-none-any.whl (77 kB)
      |████████████████████████████████| 77 kB 1.7 MB/s 
 Installing collected packages: argparse, six, cachetools, pyasn1, pyasn1-modules, rsa, google-auth, chardet, idna, urllib3, certifi, requests, pathlib2, enum34, google-assistant-library
 Successfully installed argparse-1.4.0 cachetools-4.0.0 certifi-2019.11.28 chardet-3.0.4 enum34-1.1.6 google-assistant-library-1.0.1 google-auth-1.11.0 idna-2.8 pathlib2-2.3.5 pyasn1-0.4.8 pyasn1-modules-0.2.8 requests-2.22.0 rsa-4.0 six-1.14.0 urllib3-1.25.8
 (env) pi@raspberrypi:~ $ 

- assistant SDK インストール &color(green){(時間がかかる)};
 (env) pi@raspberrypi:~ $ python -m pip install --upgrade google-assistant-sdk[samples]==0.5.1
 Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
 Collecting google-assistant-sdk[samples]==0.5.1
   Downloading google_assistant_sdk-0.5.1-py2.py3-none-any.whl (33 kB)
 Collecting google-auth-oauthlib[tool]>=0.1.0
   Downloading google_auth_oauthlib-0.4.1-py2.py3-none-any.whl (18 kB)
 Collecting sounddevice<0.4,>=0.3.7; extra == "samples"
   Downloading sounddevice-0.3.14-py2.py3-none-any.whl (30 kB)
 Requirement already satisfied, skipping upgrade: urllib3[secure]<2,>=1.21; extra == "samples" in ./env/lib/python3.7/site-packages (from google-assistant-sdk[samples]==0.5.1) (1.25.8)
 Collecting click<7,>=6.7; extra == "samples"
   Downloading click-6.7-py2.py3-none-any.whl (71 kB)
      |████████████████████████████████| 71 kB 214 kB/s 
 Collecting tenacity<5,>=4.1.0; extra == "samples"
   Downloading tenacity-4.12.0-py2.py3-none-any.whl (25 kB)
 Collecting google-assistant-grpc==0.2.1; extra == "samples"
   Downloading google_assistant_grpc-0.2.1-py2.py3-none-any.whl (21 kB)
 Collecting futures<4,>=3.1.1; extra == "samples"
   Downloading futures-3.1.1-py3-none-any.whl (2.8 kB)
 Requirement already satisfied, skipping upgrade: pathlib2<3,>=2.3.0; extra == "samples" in ./env/lib/python3.7/site-packages (from google-assistant-sdk[samples]==0.5.1) (2.3.5)
 Requirement already satisfied, skipping upgrade: google-auth in ./env/lib/python3.7/site-packages (from google-auth-oauthlib[tool]>=0.1.0->google-assistant-sdk[samples]==0.5.1) (1.11.0)
 Collecting requests-oauthlib>=0.7.0
   Downloading requests_oauthlib-1.3.0-py2.py3-none-any.whl (23 kB)
 WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))': /simple/cffi/
 Collecting CFFI>=1.0
   Downloading cffi-1.14.0.tar.gz (463 kB)
      |████████████████████████████████| 463 kB 2.7 MB/s 
 Requirement already satisfied, skipping upgrade: certifi; extra == "secure" in ./env/lib/python3.7/site-packages (from urllib3[secure]<2,>=1.21; extra == "samples"->google-assistant-sdk[samples]==0.5.1) (2019.11.28)
 Requirement already satisfied, skipping upgrade: idna>=2.0.0; extra == "secure" in ./env/lib/python3.7/site-packages (from urllib3[secure]<2,>=1.21; extra == "samples"->google-assistant-sdk[samples]==0.5.1) (2.8)
 Collecting cryptography>=1.3.4; extra == "secure"
   Downloading https://www.piwheels.org/simple/cryptography/cryptography-2.8-cp37-cp37m-linux_armv7l.whl (852 kB)
      |████████████████████████████████| 852 kB 139 kB/s 
 Collecting pyOpenSSL>=0.14; extra == "secure"
   Downloading pyOpenSSL-19.1.0-py2.py3-none-any.whl (53 kB)
      |████████████████████████████████| 53 kB 38 kB/s 
 Requirement already satisfied, skipping upgrade: six>=1.9.0 in ./env/lib/python3.7/site-packages (from tenacity<5,>=4.1.0; extra == "samples"->google-assistant-sdk[samples]==0.5.1) (1.14.0)
 Collecting googleapis-common-protos>=1.5.2
   Downloading https://www.piwheels.org/simple/googleapis-common-protos/googleapis_common_protos-1.51.0-py3-none-any.whl (74 kB)
      |████████████████████████████████| 74 kB 54 kB/s 
 Collecting grpcio>=1.3.5
   Downloading grpcio-1.27.1.tar.gz (16.9 MB)
      |████████████████████████████████| 16.9 MB 28 kB/s 
 Requirement already satisfied, skipping upgrade: cachetools<5.0,>=2.0.0 in ./env/lib/python3.7/site-packages (from google-auth->google-auth-oauthlib[tool]>=0.1.0->google-assistant-sdk[samples]==0.5.1) (4.0.0)
 Requirement already satisfied, skipping upgrade: setuptools>=40.3.0 in ./env/lib/python3.7/site-packages (from google-auth->google-auth-oauthlib[tool]>=0.1.0->google-assistant-sdk[samples]==0.5.1) (45.2.0)
 Requirement already satisfied, skipping upgrade: rsa<4.1,>=3.1.4 in ./env/lib/python3.7/site-packages (from google-auth->google-auth-oauthlib[tool]>=0.1.0->google-assistant-sdk[samples]==0.5.1) (4.0)
 Requirement already satisfied, skipping upgrade: pyasn1-modules>=0.2.1 in ./env/lib/python3.7/site-packages (from google-auth->google-auth-oauthlib[tool]>=0.1.0->google-assistant-sdk[samples]==0.5.1) (0.2.8)
 Requirement already satisfied, skipping upgrade: requests>=2.0.0 in ./env/lib/python3.7/site-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib[tool]>=0.1.0->google-assistant-sdk[samples]==0.5.1) (2.22.0)
 Collecting oauthlib>=3.0.0
   Downloading oauthlib-3.1.0-py2.py3-none-any.whl (147 kB)
      |████████████████████████████████| 147 kB 2.9 MB/s 
 Collecting pycparser
   Downloading https://www.piwheels.org/simple/pycparser/pycparser-2.19-py2.py3-none-any.whl (111 kB)
      |████████████████████████████████| 111 kB 136 kB/s 
 Collecting protobuf>=3.6.0
   Downloading protobuf-3.11.3-py2.py3-none-any.whl (434 kB)
      |████████████████████████████████| 434 kB 2.9 MB/s 
 Requirement already satisfied, skipping upgrade: pyasn1>=0.1.3 in ./env/lib/python3.7/site-packages (from rsa<4.1,>=3.1.4->google-auth->google-auth-oauthlib[tool]>=0.1.0->google-assistant-sdk[samples]==0.5.1) (0.4.8)
 Requirement already satisfied, skipping upgrade: chardet<3.1.0,>=3.0.2 in ./env/lib/python3.7/site-packages (from requests>=2.0.0->requests-oauthlib>=0.7.0->google-auth-oauthlib[tool]>=0.1.0->google-assistant-sdk[samples]==0.5.1) (3.0.4)
 Building wheels for collected packages: CFFI, grpcio
   Building wheel for CFFI (setup.py) ... done
   Created wheel for CFFI: filename=cffi-1.14.0-cp37-cp37m-linux_armv7l.whl size=344199 sha256=065c9116c377d349abb73c3dab4c81e96f1f4b609feea59b0ed8e5ed7a507996
   Stored in directory: /home/pi/.cache/pip/wheels/c4/91/4f/81fe591804590e3cd010d6c54f251607dc4c61fc5eb5840a51
   Building wheel for grpcio (setup.py) ... done
   Created wheel for grpcio: filename=grpcio-1.27.1-cp37-cp37m-linux_armv7l.whl size=19730888 sha256=e82f92e8a83f098324388108730a9b139ed4e17df1ebda496b41b44af68c0a6f
   Stored in directory: /home/pi/.cache/pip/wheels/17/b1/29/54f293e4b9aa742164ebc8ba54fef15efefcca306bf6335860
 Successfully built CFFI grpcio
 Installing collected packages: oauthlib, requests-oauthlib, click, google-auth-oauthlib, pycparser, CFFI, sounddevice, tenacity, protobuf, googleapis-common-protos, grpcio, google-assistant-grpc, futures, google-assistant-sdk, cryptography, pyOpenSSL
 Successfully installed CFFI-1.14.0 click-6.7 cryptography-2.8 futures-3.1.1 google-assistant-grpc-0.2.1 google-assistant-sdk-0.5.1 google-auth-oauthlib-0.4.1 googleapis-common-protos-1.51.0 grpcio-1.27.1 oauthlib-3.1.0 protobuf-3.11.3 pyOpenSSL-19.1.0 pycparser-2.19 requests-oauthlib-1.3.0 sounddevice-0.3.14 tenacity-4.12.0
 (env) pi@raspberrypi:~ $

- google 認証ツールのインストール
 (env) pi@raspberrypi:~ $ python -m pip install --upgrade google-auth-oauthlib[tool]
 Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
 Requirement already up-to-date: google-auth-oauthlib[tool] in ./env/lib/python3.7/site-packages (0.4.1)
 Requirement already satisfied, skipping upgrade: google-auth in ./env/lib/python3.7/site-packages (from google-auth-oauthlib[tool]) (1.11.0)
 Requirement already satisfied, skipping upgrade: requests-oauthlib>=0.7.0 in ./env/lib/python3.7/site-packages (from google-auth-oauthlib[tool]) (1.3.0)
 Requirement already satisfied, skipping upgrade: click; extra == "tool" in ./env/lib/python3.7/site-packages (from google-auth-oauthlib[tool]) (6.7)
 Requirement already satisfied, skipping upgrade: rsa<4.1,>=3.1.4 in ./env/lib/python3.7/site-packages (from google-auth->google-auth-oauthlib[tool]) (4.0)
 Requirement already satisfied, skipping upgrade: setuptools>=40.3.0 in ./env/lib/python3.7/site-packages (from google-auth->google-auth-oauthlib[tool]) (45.2.0)
 Requirement already satisfied, skipping upgrade: cachetools<5.0,>=2.0.0 in ./env/lib/python3.7/site-packages (from google-auth->google-auth-oauthlib[tool]) (4.0.0)
 Requirement already satisfied, skipping upgrade: six>=1.9.0 in ./env/lib/python3.7/site-packages (from google-auth->google-auth-oauthlib[tool]) (1.14.0)
 Requirement already satisfied, skipping upgrade: pyasn1-modules>=0.2.1 in ./env/lib/python3.7/site-packages (from google-auth->google-auth-oauthlib[tool]) (0.2.8)
 Requirement already satisfied, skipping upgrade: oauthlib>=3.0.0 in ./env/lib/python3.7/site-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib[tool]) (3.1.0)
 Requirement already satisfied, skipping upgrade: requests>=2.0.0 in ./env/lib/python3.7/site-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib[tool]) (2.22.0)
 Requirement already satisfied, skipping upgrade: pyasn1>=0.1.3 in ./env/lib/python3.7/site-packages (from rsa<4.1,>=3.1.4->google-auth->google-auth-oauthlib[tool]) (0.4.8)
 Requirement already satisfied, skipping upgrade: certifi>=2017.4.17 in ./env/lib/python3.7/site-packages (from requests>=2.0.0->requests-oauthlib>=0.7.0->google-auth-oauthlib[tool]) (2019.11.28)
 Requirement already satisfied, skipping upgrade: idna<2.9,>=2.5 in ./env/lib/python3.7/site-packages (from requests>=2.0.0->requests-oauthlib>=0.7.0->google-auth-oauthlib[tool]) (2.8)
 Requirement already satisfied, skipping upgrade: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in ./env/lib/python3.7/site-packages (from requests>=2.0.0->requests-oauthlib>=0.7.0->google-auth-oauthlib[tool]) (1.25.8)
 Requirement already satisfied, skipping upgrade: chardet<3.1.0,>=3.0.2 in ./env/lib/python3.7/site-packages (from requests>=2.0.0->requests-oauthlib>=0.7.0->google-auth-oauthlib[tool]) (3.0.4)

*** 認証情報の登録 [#d9439590]
- 認証ツール google-oauthlib-tool コマンドを実行。&color(red){事前にgoogle cloud サイトから認証ファイル(JSONファイル)をダウンロードしておく。};
 (env) pi@raspberrypi:~ $ google-oauthlib-tool --scope https://www.googleapis.com/auth/assistant-sdk-prototype --scope https://www.googleapis.com/auth/gcm --save --headless --client-secrets client_secret_[XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX].apps.googleusercontent.com.json
 Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=1063710001909-4c3g9b9900le8dke9agqdq7i7p3c02vf.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fassistant-sdk-prototype+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgcm&state=slpK7tPNVrk7YXVk8SJJ8fxuyAAhEx&prompt=consent&access_type=offline
 Enter the authorization code: 
※「XXXXX」は実際のファイル名を入れる。

- 一旦WEBブラウザ上で上記の最後部分 https:// 以下をアクセスし、ログインしたアカウントで Googleアシスタントの使用を許可する。
- 表示された認証コードをコピーし、前記のコマンド操作の続きで「Enter the authorization code:」の後に張り付ける。
 Enter the authorization code: [XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX]
 credentials saved: /home/pi/.config/google-oauthlib-tool/credentials.json
 (env) pi@raspberrypi:~ $ 
- 以上で認証登録完了。

- 作成した環境にインストールされているパッケージの確認
 (env) pi@raspberrypi:~ $ pip freeze
 cachetools==4.0.0
 certifi==2019.11.28
 cffi==1.14.0
 chardet==3.0.4
 click==6.7
 cryptography==2.8
 enum34==1.1.6
 futures==3.1.1
 google-assistant-grpc==0.2.1
 google-assistant-library==1.0.1
 google-assistant-sdk==0.5.1
 google-auth==1.11.0
 google-auth-oauthlib==0.4.1
 googleapis-common-protos==1.51.0
 grpcio==1.27.1
 idna==2.8
 oauthlib==3.1.0
 pathlib2==2.3.5
 pkg-resources==0.0.0
 protobuf==3.11.3
 pyasn1==0.4.8
 pyasn1-modules==0.2.8
 pycparser==2.19
 pyOpenSSL==19.1.0
 requests==2.22.0
 requests-oauthlib==1.3.0
 rsa==4.0
 six==1.14.0
 sounddevice==0.3.14
 tenacity==4.12.0
 urllib3==1.25.8

** HotWord機能の実行 [#y6d0c0d3]
*** Google Assistant のデモ機能の実行 [#q82720d2]
- Pyson3 仮想環境をアクティベイトする。
 pi@raspberrypi:~ $ source ~/env/bin/activate
 (env) pi@raspberrypi:~ $
-「google-assistant-demo」コマンドを実行
 (env) pi@raspberrypi-mas:~ $ google-assistant-demo --project-id raspberryai-mizutu --device-model-id raspberryai-mizutu-rasaiprd-XXXXXX
 Segmentation fault
&color(red){セグメントエラーで前に進めず!!};~
以下、試行錯誤のコマンド入力結果。%%(2020/02/14 未解決)%%
 (env) pi@raspberrypi:~ $ google-assistant-demo -h
 usage: google-assistant-demo [-h] [--device-model-id DEVICE_MODEL_ID]
                              [--project-id PROJECT_ID] [--nickname NICKNAME]
                              [--device-config DEVICE_CONFIG_FILE]
                              [--credentials OAUTH2_CREDENTIALS_FILE]
                              [--query QUERY] [-v]
 
 optional arguments:
   -h, --help            show this help message and exit
   --device-model-id DEVICE_MODEL_ID, --device_model_id DEVICE_MODEL_ID
                         the device model ID registered with Google
   --project-id PROJECT_ID, --project_id PROJECT_ID
                         the project ID used to register this device
   --nickname NICKNAME   the nickname used to register this device
   --device-config DEVICE_CONFIG_FILE
                         path to store and read device configuration
   --credentials OAUTH2_CREDENTIALS_FILE
                         path to store and read OAuth2 credentials
   --query QUERY         query to send as soon as the Assistant starts
   -v, --version         show program's version number and exit
 (env) pi@raspberrypi:~ $ google-assistant-demo --project-id raspberryai-mizutu > --device-model-id raspberryai-mizutu-rasaiprd-XXXXXX
 usage: google-assistant-demo [-h] [--device-model-id DEVICE_MODEL_ID]
                              [--project-id PROJECT_ID] [--nickname NICKNAME]
                              [--device-config DEVICE_CONFIG_FILE]
                              [--credentials OAUTH2_CREDENTIALS_FILE]
                              [--query QUERY] [-v]
 google-assistant-demo: error: unrecognized arguments: raspberryai-mizutu-rasaiprd-bxeos5
 (env) pi@raspberrypi:~ $ google-assistant-demo --project-id raspberryai-mizutu --device-model-id raspberryai-mizutu-rasaiprd-XXXXXX
 Segmentation fault
 (env) pi@raspberrypi:~ $ google-assistant-demo -v
 google-assistant-demo 1.0.1 core: 136467
 (env) pi@raspberrypi:~ $ googlesamples-assistant-hotword --project-id raspberryai-mizutu --device-model-id raspberryai-mizutu-rasaiprd-XXXXXX
 Segmentation fault
 (env) pi@raspberrypi:~ $ google-assistant-demo --project-id raspberryai-mizutu --device-model-id raspberryai-mizutu-rasaiprd-XXXXXX
 Segmentation fault
 (env) pi@raspberrypi-mas:~ $ 

>&color(red){※ 2020/02/15 記};~
- 上記で使用するコマンドは、「Googl Assistant Service」の一部である「Google Assistant Library」を使用しているらしい。~
- 「Google Assistant Library」は2019/06 で破棄されたと記述あり。今後の動作保証は望めないようだ。サイトには各種混乱状況の記述あり。
- オフィシャルサイトでは「Googl Assistant Service」を利用しろということなので、オフィシャルサイトのドキュメントから再度確認することにする。~

>''以後のステップは → [[Assistant SDK]] ページへ。''

*** セグメントエラー考察 [#xc956867]
> 「google-assistant-demo」のセグメントエラーを引き続き調査。
-[[Assistant Library の廃止>Assistant Demo]]
#br