私的AI研究会 > VoiceKit on Pi4

Voice Kit V2 on Raspberry Pi4

Voice Kit V2 を Raspberry Pi4 で動かす

目的と準備

「Google Cloud」サイトの変更により、書籍「Raspberry Pi + AI 電子工作入門」やサイトの情報が交錯して正確な情報がつかみにくいので、「Google AIY Project」のサイトを検証してみる。
 販売されている「Voice Kit V2」は Raspberry Pi Zero 他一式のセットだがこれを利用せず、サイトのソフトウェアを使用して Raspberry Pi4 上で動作させ 2020/03 現在の手順を確立する。

 Raspberry Pi3 ではすでに各種事例がある。

ハードウェア

Google AIY Project Voice Kit V2

オフィシャルサイト
GitHab ソフトウェアリリースページ

最新のシステムイメージを取得

● GitHubのリリースページから最新のイメージファイルをダウンロード
● ダウンロードしたファイルを解凍し、Rufus(Windowsの場合)などのプログラムを使用して MicroSDカードにコピーする。

linuxのインストールメディアを作る

Raspbian の起動

● Raspberry Pi4 にMicroSD カードをいれて、モニター、マウス、キーボードを接続する。
● 日本語のページをGoogle Chrome ブラウザで表示しながら手順を確認する。
● Raspberry を起動する。

Raspbian の初期設定

● 初期設定ウイザードに従い設定を進める。
初期ユーザー(rootユーザー) としてあらかじめ「pi」が設定されている。初期設定でパスワードの入力は必要。
● 無線LANの設定をする。
● 最後のステップでソフトウェアのアップデートをする。(数分~数十分)
● 再起動して、AIYプロジェクトのロゴマークの入ったデスクトップが表示されれば最初のセットアップは完了。

詳細設定

SSH のリモートターミナル接続

VNC リモート接続

● ホストコンピュータから、VNCクライアントで接続する。 接続先のipアドレス指定に必ずポート番号を付加すること (アドレス:5901)
● 詳しくは → VNC リモート接続

音声の動作を確認する。

資格(認証)情報の取得

● Google Platform をアクセスする。
 もし、ログインしていなければログイン画面が表示されるのでGoogleアカウントでログインする。

プロジェクトを作成

● Google Console トップ画面(左)から「プロジェクトを選択」

● 「新しいプロジェクト」を選択。
● プロジェクト名(例:AIJproject)を入力。
● 「作成「」を押しプロジェクトを作成する。

プロジェクトを開く

● 左ナビゲーションの[ ホーム]リンクをクリックする。
● 画面上部の「プロジェクトの選択」をもう一度クリック、作成したプロジェクトを選択する。

Google API ライブラリに移動

● 左側のナビゲーションがまだ表示されていない場合は、ページの左上にある3行のメニューアイコンをクリックして開く。
● 「APIとサービス」の上にマウスを移動し、「ライブラリ」をクリックする。

Google Assistant API の設定

● 検索ボックスに「google assistant」と入力
● Google Assistant APIというラベルの付いたカードをクリックする。

● Google Assistant APIを有効にする

資格(認証)情報を作成

● Google Assistant APIのダッシュボードページに移動する。
●「認証情報の作成」ボタンを押す。

プロジェクトの資格情報を追加する。

●「どのAPIを使用していますか」で、「Google Assistant API」を選択。
●「どこからAPIを呼び出すのですか?」で、「その他のUI(Windows、CLIツールなど)」を選択。
●「どのデータにアクセスしますか?」で、「ユーザーデータ」を選択。
●「必要な認証情報」をクリックする。

OAuth 同意画面の設定

●「同意画面の設定」を押す。

●「外部」を選ぶ。(外部しか選べない)
●「作成」を押す。

●「アプリケーション名」を入力する。(例:AIYapp)
● ページを下にスクロールし、「保存」ボタンを押す。

● 最初の「OAuth 同意画面の設定」ページに戻る。
● 自動的に次の画面になる。

OAuth 2.0クライアントIDを作成

● クライアントIDを入力します。以前に使用したものと同じプロジェクト名の使用を推奨。
●「更新」ボタンを押す。
●「OAuthクライアントIDの作成」ボタンを押す。

認証情報ファイルをダウンロード

●「ダウンロード」ボタンを押す。
● ダウンロード開始ダイアログで「保存」ボタンを押しファイルをダウンロードする。
●「完了」ボタンを押す。

認証情報ファイルを Raspberry Pi に送る

デモフォルダに移動する。

デモフォルダを確認する。

pi@raspberrypi-aiy:~/AIY-voice-kit-python/src/examples $ ls
button_led.py  buzzer  gpiozero  leds_example.py  vision  voice
pi@raspberrypi-aiy:~/AIY-voice-kit-python/src/examples $

アシスタントデモを実行する

pi@raspberrypi-aiy:~/AIY-voice-kit-python/src/examples $ voice/assistant_grpc_demo.py
DEBUG:requests_oauthlib.oauth2_session:Generated new state XgTsap1N3etZNBuFXZoE6evP9CeJSL.
Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=1029345425416-ud313r0lt4ttrsu4ebmb00v20udao5m0.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fassistant-sdk-prototype&state=XgTsap1N3etZNBuFXZoE6evP9CeJSL&prompt=consent&access_type=offline
Enter the authorization code: ■

Google Assistant の使用許可を与える

デバイスの登録

Google Actionページ にアクセスし、デバイスを登録する。

●「New Project」を押し登録してあるプロジェクト名を入れる。

●「Language」→ Japanese 「Country」→ Japan を選択して「inprt project」を押す。

●「Device registration」を選択する。

● デモソフトの実行ですでにモデルが登録されている。
● 登録されている名前を選択する。

「traits」の設定

● Product name:Voice Kit
● Model Id :aijproject-voice-kit
● Manufacturer name :AIY Projects
● Device type :Speaker
● 右端のペンマークを押して「traits」の設定をする。

● On/Off と Start/Stop にチェックを入れる。 ●「Save」を押す。

●「traits」の項目が追加される。

デモプログラムを再実行する

・基本的に push_talk プログラムで、スイッチを押してから話しかける。
・hot-word のデモソフトではない。
・サイトには「次のステップ」の項目があるので、こちらの方を進めていく方が期待できる。

pi@raspberrypi-aiy:~ $ cd AIY-projects-python
pi@raspberrypi-aiy:~/AIY-projects-python $ ls
CHANGES.md  CONTRIBUTING.md  HACKING.md  LICENSE  MANIFEST.in  Makefile  README.md  checkpoints  docs  schematics  scripts  setup.py  src  stdeb.cfg
pi@raspberrypi-aiy:~/AIY-projects-python $ src/examples/voice/assistant_grpc_demo.py
DEBUG:google.auth.transport.requests:Making request: POST https://oauth2.googleapis.com/token
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): oauth2.googleapis.com:443
DEBUG:urllib3.connectionpool:https://oauth2.googleapis.com:443 "POST /token HTTP/1.1" 200 None
INFO:aiy.assistant.grpc:device_model_id: aijproject-voice-kit
INFO:aiy.assistant.grpc:device_id: aijproject-voice-kit-dfab0b2a-9abc-4b3c-be51-e9cd1e423f48
DEBUG:google.auth.transport.requests:Making request: POST https://oauth2.googleapis.com/token
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): oauth2.googleapis.com:443
DEBUG:urllib3.connectionpool:https://oauth2.googleapis.com:443 "POST /token HTTP/1.1" 200 None
INFO:aiy.assistant.grpc:Connecting to embeddedassistant.googleapis.com
INFO:root:Press button to start conversation...
INFO:root:Conversation started!
INFO:aiy.assistant.grpc:Recording started.
INFO:aiy.assistant.grpc:You said: "今日".
INFO:aiy.assistant.grpc:You said: "今日の".
INFO:aiy.assistant.grpc:You said: "今日のて".
INFO:aiy.assistant.grpc:You said: "今日の天".
INFO:aiy.assistant.grpc:You said: "今日の天気".
INFO:aiy.assistant.grpc:You said: "今日の天気は".
INFO:aiy.assistant.grpc:You said: "今日の天気は".
INFO:aiy.assistant.grpc:You said: "今日の天気は".
INFO:aiy.assistant.grpc:End of audio request detected.
INFO:aiy.assistant.grpc:You said: "今日の天気は".
INFO:aiy.assistant.grpc:Assistant said: "足元に注意してお出かけください
今日の八尾は、予想最高気温12度、最低気温7度で、断続的に雨が降るでしょう。 現在気温8度、雨です。
---
(weather.com でもっと見る)"
INFO:aiy.assistant.grpc:Not expecting follow-on query from user.
INFO:aiy.assistant.grpc:Recording stopped.
INFO:aiy.assistant.grpc:Playing started.
INFO:aiy.assistant.grpc:Playing stopped.
INFO:root:Press button to start conversation...
INFO:root:Conversation started!
INFO:aiy.assistant.grpc:Recording started.
INFO:aiy.assistant.grpc:You said: "今".
INFO:aiy.assistant.grpc:You said: "今の".
INFO:aiy.assistant.grpc:You said: "今何".
INFO:aiy.assistant.grpc:You said: "今何時".
INFO:aiy.assistant.grpc:End of audio request detected.
INFO:aiy.assistant.grpc:You said: "今何時".
INFO:aiy.assistant.grpc:You said: "今何時".
INFO:aiy.assistant.grpc:Assistant said: "時刻は、9:23です。"
INFO:aiy.assistant.grpc:Not expecting follow-on query from user.
INFO:aiy.assistant.grpc:Playing started.
INFO:aiy.assistant.grpc:Recording stopped.
INFO:aiy.assistant.grpc:Playing stopped.
INFO:root:Press button to start conversation...
INFO:root:Conversation started!
INFO:aiy.assistant.grpc:Recording started.
INFO:aiy.assistant.grpc:You said: "さや".
INFO:aiy.assistant.grpc:You said: "佐用".
INFO:aiy.assistant.grpc:You said: "さような".
INFO:aiy.assistant.grpc:You said: "さようなら".
INFO:aiy.assistant.grpc:End of audio request detected.
INFO:aiy.assistant.grpc:You said: "さようなら".
INFO:aiy.assistant.grpc:Recording stopped.
INFO:aiy.assistant.grpc:Assistant said: "はい、ありがとうございました??"
INFO:aiy.assistant.grpc:Not expecting follow-on query from user.
INFO:aiy.assistant.grpc:Playing started.
INFO:aiy.assistant.grpc:Playing stopped.
INFO:root:Press button to start conversation...
^CTraceback (most recent call last):
  File "src/examples/voice/assistant_grpc_demo.py", line 57, in <module>
    main()
  File "src/examples/voice/assistant_grpc_demo.py", line 52, in main
    board.button.wait_for_press()
  File "/home/pi/AIY-projects-python/src/aiy/board.py", line 164, in wait_for_press
    return event.wait(timeout)
  File "/usr/lib/python3.7/threading.py", line 552, in wait
    signaled = self._cond.wait(timeout)
  File "/usr/lib/python3.7/threading.py", line 296, in wait
    waiter.acquire()
KeyboardInterrupt
pi@raspberrypi-aiy:~/AIY-projects-python $
 

参考資料

「AIYプロジェクト」オフィシャルドキュメント

Voise Kit を Raspberry Pi 上で動かす

カスタマイズ関連


Last-modified: 2020-04-06 (月) 09:02:19