AI

ラズパイで自作Amazon Echo

Amazon Echoの招待リクエストをしているのですが、なかなか招待が届かずに待ちきれなくなったので、Alexa Voice Service (AVS) Device SDK をラズパイ3で動かしてみることにしました。

ラズパイ3のOSには、2017-09-07-raspbian-stretch.imgを使いました。

Raspberry Pi Quick Start Guide

https://github.com/alexa/avs-device-sdk/wiki/Raspberry-Pi-Quick-Start-Guide

手順はこちらの公式Wikiにかなり丁寧に書かれていて、ほぼコピペで完了できるものでしたので、以下は私の作業メモ(コピペメモ)としての参考情報として共有したいと思います。

1. Install and configure dependencies for the SDK

1.1 Create the folder structure

1
cd /home/pi/ && mkdir sdk-folder && cd sdk-folder && mkdir sdk-build sdk-source third-party application-necessities && cd application-necessities && mkdir sound-files

1.2 Install dependencies

1
2
3
4
5
sudo apt-get update
sudo apt-get -y install git gcc cmake build-essential libsqlite3-dev libcurl4-openssl-dev libfaad-dev libsoup2.4-dev libgcrypt20-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-good libasound2-dev doxygen
cd /home/pi/sdk-folder/third-party && wget -c http://www.portaudio.com/archives/pa_stable_v190600_20161030.tgz && tar zxf pa_stable_v190600_20161030.tgz && cd portaudio && ./configure --without-jack && make
pip install commentjson
cd /home/pi/sdk-folder/application-necessities/sound-files/ && wget -c https://images-na.ssl-images-amazon.com/images/G/01/mobile-apps/dex/alexa/alexa-voice-service/docs/audio/states/med_system_alerts_melodic_02._TTH_.mp3 && wget -c https://images-na.ssl-images-amazon.com/images/G/01/mobile-apps/dex/alexa/alexa-voice-service/docs/audio/states/med_system_alerts_melodic_02_short._TTH_.wav && wget -c https://images-na.ssl-images-amazon.com/images/G/01/mobile-apps/dex/alexa/alexa-voice-service/docs/audio/states/med_system_alerts_melodic_01._TTH_.mp3 && wget -c https://images-na.ssl-images-amazon.com/images/G/01/mobile-apps/dex/alexa/alexa-voice-service/docs/audio/states/med_system_alerts_melodic_01_short._TTH_.wav

1.3 Clone the AVS Device SDK and the Sensory wake word engine

1
2
3
4
5
cd /home/pi/sdk-folder/sdk-source && git clone git://github.com/alexa/avs-device-sdk.git
cd /home/pi/sdk-folder/third-party && git clone git://github.com/Sensory/alexa-rpi.git
cd /home/pi/sdk-folder/third-party/alexa-rpi/bin/ && ./license.sh
:
Do you accept this license agreement? [yes or no]: yes

2. Build the SDK

1
2
cd /home/pi/sdk-folder/sdk-build && cmake /home/pi/sdk-folder/sdk-source/avs-device-sdk -DSENSORY_KEY_WORD_DETECTOR=ON -DSENSORY_KEY_WORD_DETECTOR_LIB_PATH=/home/pi/sdk-folder/third-party/alexa-rpi/lib/libsnsr.a -DSENSORY_KEY_WORD_DETECTOR_INCLUDE_DIR=/home/pi/sdk-folder/third-party/alexa-rpi/include -DGSTREAMER_MEDIA_PLAYER=ON -DPORTAUDIO=ON -DPORTAUDIO_LIB_PATH=/home/pi/sdk-folder/third-party/portaudio/lib/.libs/libportaudio.a -DPORTAUDIO_INCLUDE_DIR=/home/pi/sdk-folder/third-party/portaudio/include
make SampleApp -j2

3. Obtain credentials and set up your local auth server

3.1 Register your product with Amazon

ここでは、
https://github.com/alexa/alexa-avs-sample-app/wiki/Create-Security-Profile
の手順を実施した際の、以下の情報を使います。

  • 製品ID
  • クライアント ID
  • クライアントのシークレット

3.2 Update AlexaClientSDKConfig.json

1
vi /home/pi/sdk-folder/sdk-build/Integration/AlexaClientSDKConfig.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
{
"authDelegate":{
// The Client Secret of the Product from developer.amazon.com
"clientSecret":"クライアントのシークレット",
// Unique device serial number. e.g. 123456
"deviceSerialNumber":"123456",
// Refresh Token populated by running AuthServer.py
"refreshToken":"{SDK_CONFIG_REFRESH_TOKEN}",
// The Client ID of the Product from developer.amazon.com
"clientId":"クライアント ID",
// Product ID from developer.amazon.com
"productId":"製品ID"
},
"alertsCapabilityAgent":{
// Path to Alerts database file. e.g. /home/ubuntu/Build/alerts.db
// Note: The directory specified must be valid.
// The database file (alerts.db) will be created by SampleApp, do not create it yourself.
// The database file should only be used for alerts (don't use it for other components of SDK)
"databaseFilePath":"/home/pi/sdk-folder/application-necessities/alerts.db",
// Path to default Alarm sound file. e.g. /home/ubuntu/alert_sounds/alarm_normal.mp3
// Note: The audio file must exist and be a valid file.
"alarmSoundFilePath":"/home/pi/sdk-folder/application-necessities/sound-files/med_system_alerts_melodic_01._TTH_.mp3",
// Path to short Alarm sound file. e.g. /home/ubuntu/alert_sounds/alarm_short.wav
// Note: The audio file must exist and be a valid file.
"alarmShortSoundFilePath":"/home/pi/sdk-folder/application-necessities/sound-files/med_system_alerts_melodic_01_short._TTH_.wav",
// Path to default timer sound file. e.g. /home/ubuntu/alert_sounds/timer_normal.mp3
// Note: The audio file must exist and be a valid file.
"timerSoundFilePath":"/home/pi/sdk-folder/application-necessities/sound-files/med_system_alerts_melodic_02._TTH_.mp3",
// Path to short timer sound file. e.g. /home/ubuntu/alert_sounds/timer_short.wav
// Note: The audio file must exist and be a valid file.
"timerShortSoundFilePath":"/home/pi/sdk-folder/application-necessities/sound-files/med_system_alerts_melodic_02_short._TTH_.wav"
},
"settings":{
// Path to Settings database file. e.g. /home/ubuntu/Build/settings.db
// Note: The directory specified must be valid.
// The database file (settings.db) will be created by SampleApp, do not create it yourself.
// The database file should only be used for settings (don't use it for other components of SDK)
"databaseFilePath":"/home/pi/sdk-folder/application-necessities/settings.db",
"defaultAVSClientSettings":{
// Default language for Alexa.
// See https://developer.amazon.com/docs/alexa-voice-service/settings.html#settingsupdated for valid values.
"locale":"en-US"
}
},
"certifiedSender":{
// Path to Certified Sender database file. e.g. /home/ubuntu/Build/certifiedsender.db
// Note: The directory specified must be valid.
// The database file (certifiedsender.db) will be created by SampleApp, do not create it yourself.
// The database file should only be used for certifiedSender (don't use it for other components of SDK)
"databaseFilePath":"/home/pi/sdk-folder/application-necessities/certifiedSender.db"
}
}
// Notes for logging
// The log levels are supported to debug when SampleApp is not working as expected.
// There are 14 levels of logging with DEBUG9 providing the highest level of logging and CRITICAL providing
// the lowest level of logging i.e. if DEBUG9 is specified while running the SampleApp, all the logs at DEBUG9 and
// below are displayed, whereas if CRITICAL is specified, only logs of CRITICAL are displayed.
// The 14 levels are:
// DEBUG9, DEBUG8, DEBUG7, DEBUG6, DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, DEBUG0, INFO, WARN, ERROR, CRTITICAL.
// To selectively see the logging for a particular module, you can specify logging level in this json file.
// Some examples are:
// To only see logs of level INFO and below for ACL and MediaPlayer modules,
// - grep for ACSDK_LOG_MODULE in source folder. Find the log module for ACL and MediaPlayer.
// - Put the following in json:
// "acl":{
// "logLevel":"INFO"
// },
// "mediaPlayer":{
// "logLevel":"INFO"
// }
// To enable DEBUG, build with cmake option -DCMAKE_BUILD_TYPE=DEBUG. By default it is built with RELEASE build.
// And run the SampleApp similar to the following command.
// e.g. TZ=UTC ./SampleApp /home/ubuntu/.../AlexaClientSDKConfig.json /home/ubuntu/KittAiModels/ DEBUG9"

3.3 Obtain a refresh token

1
cd /home/pi/sdk-folder/sdk-build && python AuthServer/AuthServer.py

http://localhost:3000/
でログインするとAlexaClientSDKConfig.jsonrefreshTokenが更新されました。

3.4 Test the microphone

ここは実行せずに、その代わりとしてラズパイのデスクトップメニューの
Preferences > Audio Device Settings
からオーディオ設定をしました。

4. Run the sample app

1
cd /home/pi/sdk-folder/sdk-build/SampleApp/src && TZ=UTC ./SampleApp /home/pi/sdk-folder/sdk-build/Integration/AlexaClientSDKConfig.json /home/pi/sdk-folder/third-party/alexa-rpi/models

を実行すると

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# # # ##### ##### ###### # #
# # # # # # # # # # # #
# # # # # # # # # #
# # # # ##### ##### # # ###
####### # # # # # # # #
# # # # # # # # # # # #
# # # ##### ##### ###### # #
##### #
# # ## # # ##### # ###### # # ##### #####
# # # ## ## # # # # # # # # # #
##### # # # ## # # # # ##### # # # # # #
# ###### # # ##### # # ####### ##### #####
# # # # # # # # # # # # #
##### # # # # # ###### ###### # # # #
+----------------------------------------------------------------------------+
| Options: |
| Wake word: |
| Simply say Alexa and begin your query. |
| Tap to talk: |
| Press 't' and Enter followed by your query (no need for the 'Alexa').|
| Hold to talk: |
| Press 'h' followed by Enter to simulate holding a button. |
| Then say your query (no need for the 'Alexa'). |
| Press 'h' followed by Enter to simulate releasing a button. |
| Stop an interaction: |
| Press 's' and Enter to stop an ongoing interaction. |
| Privacy mode (microphone off): |
| Press 'm' and Enter to turn on and off the microphone. |
| Playback Controls: |
| Press '1' for a 'PLAY' button press. |
| Press '2' for a 'PAUSE' button press. |
| Press '3' for a 'NEXT' button press. |
| Press '4' for a 'PREVIOUS' button press. |
| Settings: |
| Press 'c' followed by Enter at any time to see the settings screen. |
| Speaker Control: |
| Press 'p' followed by Enter at any time to adjust speaker settings. |
| Info: |
| Press 'i' followed by Enter at any time to see the help screen. |
| Quit: |
| Press 'q' followed by Enter at any time to quit the application. |
+----------------------------------------------------------------------------+

このような表示が出てきました。

Language Optionsをみると以下の3つの言語にしか対応していないようです。

1
2
3
4
5
6
7
+----------------------------------------------------------------------------+
| Language Options: |
| |
| Press '1' followed by Enter to change the language to US English. |
| Press '2' followed by Enter to change the language to UK English. |
| Press '3' followed by Enter to change the language to German. |
+----------------------------------------------------------------------------+

日本語対応が待ち遠しいところですが、とりあえずつたない英語で、

”アレクサ!ハロー”

と言ってみると

”Hi!”

と返ってきました。

その時端末画面には

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
############################
# Listening... #
############################
###########################
# Thinking... #
###########################
########################################
# Alexa is currently idle! #
########################################
###########################
# Speaking... #
###########################
########################################
# Alexa is currently idle! #
########################################

このような感じの表示がされるので、動作していることがログとしても確認できました。

おそらくビルド時にオプションを設定するとここのログを増やすことができるのではないかと推測しています。

続いて

”グッドモーニング”

と言ってみると、この日の情報として、マイケル・ジャクソンのスリラーの情報を教えてくれました。

ひとまずは簡単に試すことができましたので、本物のAmazon Echoを手に入れるまでの間はこちらで我慢したいと思います。