Raspberry piでAmazon Echo(AVS)を動かしてみる未遂

前段

思うところあってRaspberry piを買ってみた。 IMG_20161222_204815.jpg 買って早速OSを入れて、Airplay受信したり、Radiko録音したりやっていたが、一番やってみたかったAmazonEcho(AVS)を試してみたので記録に残す。 ただし題名にもある通り、2016.12.27現在、やりたかったことはできていない。

そもそもAVSとはなんであろう。英語ではあるが公式ページに書かれている。

Alexa Voice Service
Alexa Voice Service...

そもそもはAmazonEchoという米英独で発売されている製品の中で動ているソフトウェアだ。 その、AVSをAmazonがライブラリとして他ハードでも動くように用意してくれている。

alexa/alexa-avs-sample-app: This project demonstrates how to access and test the Alexa Voice Service using a Java client (running on a Raspberry Pi), and a Node.js server.
alexa/alexa-avs-sample-app: This project demonstrates how to access and test the Alexa Voice Service using a Java client (running on a Raspberry Pi), and a Node.js server....

インストール方法は英語ではあるがithubに丁寧に書かれており、Linuxを扱える人であれば問題なくインストールできると思う。 上にも書いた通り、うまくいってないのでそのあたりを中心に書き残しておく。

Raspberry Pi · alexa/alexa-avs-sample-app Wiki
Type ctrl-X and then Y, and then press Enter to save the changes to the file. ...

Amazon Developer アカウントの登録

https://developer.amazon.com/login.html

証明書の取得

Project, ClientID, ClientSecretの取得

AVSをraspberry piにgit clone

$ cd ~/Desktop
$ git clone https://github.com/alexa/alexa-avs-sample-app.git

インストール

$ cd ~/Desktop/alexa-avs-sample-app
$ vim automated_install.sh

304 #--------------------------------------------------------------------------------------------                                                              
305 # Checking if script has been updated by the user with ProductID, ClientID, and ClientSecret                                                               
306 #--------------------------------------------------------------------------------------------                                                              
307                                                                                                                                                            
308 if [ "$ ProductID" = "YOUR_PRODUCT_ID_HERE" ]; then                                                                                                         
309   ProductID="mypialexa"                                                                                                                                    
310 fi                                                                                                                                                         
311 if [ "$ ClientID" = "YOUR_CLIENT_ID_HERE" ]; then                                                                                                           
312   ClientID="amzn1.application-xxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"                                                                                 
313 fi                                                                                                                                                         
314 if [ "$ ClientSecret" = "YOUR_CLIENT_SECRET_HERE" ]; then                                                                                                   
315   ClientSecret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"                                                                          316 fi          


$ ./automated_install.sh
※基本的にはプロンプトに対しては「y」で良い。

VNCのインストール)

GUIが必要なため、モニタをRaspberry pi に接続していない場合はVNCをインストールしておく。

(ここからGUI)

Webサービス開始

$ cd ~/Desktop/alexa-avs-sample-app/samples
$ cd companionService && npm start

1.PNG

別のターミナルを起動して

$ cd ~/Desktop/alexa-avs-sample-app/samples
$ cd javaclient && mvn exec:exec

2.PNG

Login Register/Autehnitication youre Device で YESを押下するとブラウザが立ち上がるのでproceed to localhost(unsafe)を押下する。 3.PNG

Amazon.comサイトへリダイレクトされるのでログインして認証し、OKを押下するとAlexa Voice Serv..にTokenが自動的に入力される。 4.PNG

(ここからはAlexaという声で反応させたい場合)

Alexa

別のターミナルを起動して

$ cd ~/Desktop/alexa-avs-sample-app/samples
$ cd wakeWordAgent/src && ./wakeWordAgent -e sensory

  ここで僕の環境で問題が発生!

$ cd wakeWordAgent/src && ./wakeWordAgent -e sensory
INFO:main: Starting Wake Word Agent
INFO:WakeWordAgent: State set to IDLE(2)
INFO:Initializing Sensory library | library name: TrulyHandsfree | library version: 5.0.0-avs.1 | model file: ../ext/resources/spot-alexa-rpi.snsr
WARNING:Library expires on: License expires on 27 Mar 2017 00:00:00 GMT
wakeWordAgent: pcm.c:694: snd_pcm_close: Assertion `pcm' failed.
Aborted

5.PNG

困ったよー。 ググりまくった結果、githubのコミュニティで良い情報を得た。

Sensory Wake Word engine · Issue #284 · alexa/alexa-avs-sample-app
Sensory Wake Word engine · Issue #284 · alexa/alexa-avs-sample-app...

ndphu commented on 12 Oct I got the same problem. There is a file under wakeWordAgent/sensory/alexa-rpi/config called asound.conf. I replaced my ~/.asoundrc by this file and it can fix the problem. (make sure you have >a backup for your current ~/.asoundrc)

どうやらwakeWordAgent/sensory/alexa-rpi/configを見ろと言う事だ。

$ cat asound.conf
pcm.!default
{
  type asym
  playback.pcm {
    type hw
    card 1
    device 0
  }
  capture.pcm {
    type plug
    slave {
      pcm {
        type hw
        card 0
        device 0
      }
    }
  }
}

ぼくの環境をチェックしてみる。

$ cat /proc/asound/modules
 0 snd_usb_audio
 1 snd_bcm2835

$ arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: Device [USB PnP Audio Device], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 1: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 1: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

どうやら問題なさそうだ。 今度は~配下の .asoundrcを確認してみる。

$ cat .asoundrc
pcm.!default {
  type asym
   playback.pcm {
     type plug
     slave.pcm "hw:0,0"
   }
   capture.pcm {
     type plug
     slave.pcm "hw:1,0"
   }
}

pcm.!default {
        type hw
        card 1
}

ctl.!default {
        type hw
        card 1
}

うん?なんかおかしい。おかしいぞ!と言う事で変更してみた。

$ vi .asoundrc
$ cat .asoundrc
pcm.!default {
  type asym
   playback.pcm {
     type plug
     slave.pcm "hw:1,0"
   }
   capture.pcm {
     type plug
     slave.pcm "hw:0,0"
   }
}

再実行

$ ./wakeWordAgent -e sensory
INFO:main: Starting Wake Word Agent
INFO:WakeWordAgent: State set to IDLE(2)
INFO:Initializing Sensory library | library name: TrulyHandsfree | library version: 5.0.0-avs.1 | model file: ../ext/resources/spot-alexa-rpi.snsr
WARNING:Library expires on: License expires on 27 Mar 2017 00:00:00 GMT
INFO:SensoryWakeWordEngine: mainLoop thread started
INFO:WakeWordIPCSocket::mainLoop thread started
INFO:WakeWordIPCSocket: init socket on port:5123
INFO:WakeWordAgent: thread started
INFO:===> Connected to AVS client <===

キターーーーー!

別のターミナルを起動して

$ cd ~/Desktop/alexa-avs-sample-app/samples
$ cd wakeWordAgent/src && ./wakeWordAgent -e kitt_ai
INFO:main: Starting Wake Word Agent
INFO:WakeWordAgent: State set to IDLE(2)
ERROR:Failed to open PortAudio stream.Device unavailable
ERROR:KittAiSnowboyWakeWordEngine: Initialization error:Failed to open PortAudio stream.
ERROR:WakeWordAgent: exception in constructor: Failed to open PortAudio stream.
ERROR:main: Exception happened: Failed to open PortAudio stream.

6.PNG

こなーいorz 一応このあたりは見てみた。

wake word engine problem · Issue #277 · alexa/alexa-avs-sample-app
wake word engine problem · Issue #277 · alexa/alexa-avs-sample-app...

ググっても有力な情報が得られず、途方に暮れているところでQiitaを書いてみた。。