3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Alexa Voice ServiceをRaspberry Pi 2で動かす(未遂)

Last updated at Posted at 2015-08-17

Amazonの音声エージェント、Alexa Voice ServiceをRaspberry Pi 2で動かすための手順記録です。
※まだちゃんと動くところまでいっていないのであくまでメモです。ちゃんと動くようになったら改めて更新します。

サンプルコードのダウンロード

  • Amazon開発者アカウントを持っていない場合はここより作成
  • Amazonのページからリファレンスコード一式をダウンロード
  • 適当なディレクトリ(ここではホーム)に展開

関連ツールのインストール

Maven

$ sudo apt-get install maven

node.js

apt-getだと古いバージョンがインストールされてしまうので、node-armからインストールする。

$ wget http://node-arm.herokuapp.com/node_latest_armhf.deb
$ sudo dpkg -i node_latest_armhf.deb

サーバ用自己署名証明書の作成

RasPi上で動かすnode.jsサーバがSSL通信できるように証明書を作成する。

秘密鍵の作成

$ cd ~/AlexaVoiceServiceExamples/samples/service/ssl
$ openssl genrsa -des3 -out server.key 2048

パスフレーズを設定するように求められるので適当に入力する。

証明書の作成

$ openssl req -new -key server.key -out server.csr

証明書の情報を入力するように求められるが、"Common Name (e.g. server FQDN or YOUR name)"のところだけlocalhostと入力し、あとはブランクもしくは適当でOK。

秘密鍵からパスフレーズを削除

$ cp server.key server.key.passphrase
$ openssl rsa -in server.key.passphrase -out server.key

証明書に署名

$ openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt

-daysの引数は証明書の有効日数なので適当に。

Javaのキーストアに証明書を追加

$ keytool -import -v -trustcacerts -alias avs-companion-service -file server.crt -keystore /usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt/jre/lib/security/cacerts -keypass changeit -storepass changeit

"Trust this certificate?"と聞かれるのでyesと入力。

Amazonセキュリティプロファイルの作成

  • Alexa Developer Portalへ移動
  • "Alexa Voice Service"をクリック
  • "Register a Product Type"メニューから"Device"を選択
  • 各フィールドに以下の値を入力(適当でよい)
項目名
Device Type ID my_device
Display Name My Device
Security Profile "Create a new profile"を選択
Security Profile Name Alexa Voice Service Sample App Security Profile
Security Profile Description Alexa Voice Service Sample App Security Profile Description
  • "Web Settings"タブを選択

  • "Allowed Origins"の欄の"Add Another"をクリックし、https://localhost:3000と入力

  • "Allowed Return URLs"の欄の"Add Another"をクリックし、https://localhost:3000/authresponseと入力

  • 残りのフィールドに値を入力

項目名
Category "Other"を選択
Description Alexa Voice Service sample app test
Enable Amazon Music? "No"を選択
  • "Security Profile"の項目をクリックし、そこに表示される"Client ID"と"Client Secret"の値をメモしておく

サーバの起動

  • 関連モジュールのインストール
$ cd ~/AlexaVoiceServiceExamples/samples/service
$ npm install
  • config.jsの編集
config.js
var config = {
    clientId: 'ここにClient IDの値をペースト',
    clientSecret: 'ここにClient Secretの値をペースト',
    products: {
      "my_device": ["123456"] // デバイス固有のIDを表す適当な英数字
    },
};
  • サーバ起動
$ npm start

"Listening on port 3000"と出ればOK。

クライアントアプリの起動

$ cd ../javaclient
  • config.jsの編集
config.js
{
    "pid": "my_device",
    "serial": "123456", // サーバ側のconfig.jsで設定したデバイス固有のIDを指定
    "url":"https://localhost:3000"
}
  • pom.xmlに以下のエントリを追加
pom.xml
<dependency>
  <groupId>net.java.dev.jna</groupId>
  <artifactId>jna</artifactId>
  <version>4.1.0</version>
  <scope>compile</scope>
</dependency>
  • Mavenでビルド&実行
$ mvn install
$ mvn exec:java

成功!となるはずが...。

SIGILLで落ちる。

  • VLCのアップデート
$ sudo apt-get upgrade vlc

→エラーがSIGSEGVになったが相変わらず落ちる。

JDKのバージョンを落とすなどいろいろやってみたが状況が変わらないので、とりあえずここで断念。Amazonのフォーラムでも同じ症状の人が結構いる様子。

Thread: java client blows up JRE - please help

補足:プロキシの設定が必要な環境の場合

apt

/etc/apt.confに設定を追加。

apt.conf
Acquire::http::proxy "http://プロキシサーバー名:ポート番号/";
Acquire::https::proxy "https://プロキシサーバー名:ポート番号/";

wget

~/.bashrcに環境変数を追加。

.bashrc
export http_proxy=http://プロキシサーバー名:ポート番号
export https_proxy=http://プロキシサーバー名:ポート番号

Maven

~/.m2/以下にsettings.xmlを作成。

settings.xml
<settings>
  <proxies>
    <proxy>
      <active>true</active>
      <protocol>http</protocol>
      <host>プロキシサーバー名</host>
      <port>ポート番号</port>
    </proxy>
  </proxies>
</settings>
3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?