ITお絵かき修行

3歩歩いても忘れないために

アレクサにお手をしてもらいたかった

AmazonEchoPlusを買ったので。
内容自体は公式のHelloworldレベルなので内容は全く無い。出オチ。

■ソース

'use strict';
const Alexa = require('alexa-sdk');

const APP_ID = '(※環境変数か直書き)';

const HELP_MESSAGE = 'すみません、よく聞き取れませんでした。もう一度お願いします。';
const HELP_REPROMPT = '何か御用ですか?';
const STOP_MESSAGE = 'お疲れさまでした。';

const phrases = [
    'それがあなたたちのやりかたですか。',
    '夜道には気を付けてくださいね。',
    'すみません、よく聞き取れませんでした。もう一度お願いします。ははっ。',
];

const handlers = {
    'LaunchRequest': function () {
        this.emit('OteIntent');
    },
    'OteIntent': function () {
        const sources = phrases;
        const sIndex = Math.floor(Math.random() * sources.length);
        const randomFact = sources[sIndex];
        const speechOutput = randomFact;

/*        this.response.cardRenderer(SKILL_NAME, randomFact); */
        this.response.speak(speechOutput);
        this.emit(':responseReady');
    },
    'AMAZON.HelpIntent': function () {
        const speechOutput = HELP_MESSAGE;
        const reprompt = HELP_REPROMPT;

        this.response.speak(speechOutput).listen(reprompt);
        this.emit(':responseReady');
    },
    'AMAZON.CancelIntent': function () {
        this.response.speak(STOP_MESSAGE);
        this.emit(':responseReady');
    },
    'AMAZON.StopIntent': function () {
        this.response.speak(STOP_MESSAGE);
        this.emit(':responseReady');
    },
};

exports.handler = function (event, context, callback) {
    const alexa = Alexa.handler(event, context, callback);
    alexa.APP_ID = APP_ID;
    alexa.registerHandlers(handlers);
    alexa.execute();
};

■テスト結果
動作確認はコンソール上で実施できる。リクエスト内のJSONをいじってテストすることも可能。
f:id:hhhhhskw:20181008234636j:plain

■EchoPlus/アレクサ使った所感とか(1週間程度)
BlueToothスピーカーとしてはまぁまぁ。筐体が少し大きい(感覚的には900mlペットボトル)ので低音も一応出る。
→接続先デバイスの名前とかを読み上げてくれるのでセットアップ/繋ぎ変えが簡単で良かった。

・自動生成された音声が不自然な時がたまにあるので、SSMLタグでの声色調整スキルが必要だと感じた。

・アレクサに命令するには「アレクサ、〇〇を開いて××をして」のようにユーザがキーワードを覚えて組み合わせる必要があるのでちょっと億劫。
→用事次第だが、やらなくてもいいことであればあまり定着しなさそう。このあたりがVUIを意識するということ?

VUIと例外処理の設計実装、会話(セッション連携)辺りが使えるようになってからが本番だと感じた。。