LoginSignup
4
1

More than 5 years have passed since last update.

Alexaが240秒再生可能になったので約4分間告白され続けるスキルを創った

Last updated at Posted at 2018-12-06

ごきげんよう

この記事は
「するめごはんのVUI・スマートスピーカー Advent Calendar 2018」
の7日目の記事です。

Alexaのオーディオファイルの再生時間が90秒から240秒に延びた

この記事を書いている今日、つまり12月6日の
Alexa Dev Summit TokyoのAlexaスキルのクイズでオーディオ再生が4分まで対応できるようになった旨が出題されました。

■Alexa Dev Summit TokyoのAlexaスキル
https://www.amazon.co.jp/Amazon-Alexa-Dev-Summit-Tokyo/dp/B07KGH1VJ1/

また、smartioさんのツイートでも同様の報告がありました。

早速、約240秒告白されてみる

とのことなので、早速240秒、つまり4分間何かしらを流そうかと思い、考えた結果、やはり?もってる音声ファイルとしてAlexaスキル ヒロインの告白のうちの告白セリフを連結して3分58秒にしました。

71g60WqgQ8L._AC_US218_.png

実機テスト通りましたので録画・公開してみました。
なお、何も考えないで動くことのみを目的としたため、結城琴葉ちゃんの表示が遅れたりしています。

ソースコード

たいして何もしてないので、今まで通りです。

とりあえず、LaunchRequestだけ作成して、実機で動くかのみ確かめました。


'use strict';

const Alexa = require('ask-sdk');


//20種類の告白セリフを結合したファイル
const kotoha_20 = '<audio src=\"https://s3-XXXXXXXXXXXXXXXXXX.mp3\" />';


//画像
const DisplayImg1 = {
      title: '結城琴葉',
      url: 'https://s3-ap-XXXXXXXXXXXXXXXXXXXXX.png'
    };

const DisplayImg2 = {
      title: '結城琴葉',
      url: 'https://s3-ap-XXXXXXXXXXXXXXXXXXXXX.png'
};

const LaunchRequestHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
  },
  async handle(handlerInput) {

    // Template 6
    if (supportsDisplay(handlerInput)){
      const myImage1 = new Alexa.ImageHelper()
        .addImageInstance(DisplayImg1.url)
        .getImage();

      const myImage2 = new Alexa.ImageHelper()
        .addImageInstance(DisplayImg2.url)
        .getImage();

      const primaryText = new Alexa.RichTextContentHelper()
        .withPrimaryText('')
        .getTextContent();

        handlerInput.responseBuilder.addRenderTemplateDirective({
        type: 'BodyTemplate6',
        token: 'string',
        backButton: 'HIDDEN',
        backgroundImage: myImage2,
        image: myImage1,
        title: "",
        textContent: primaryText
      });
    }

    ///////////////////////////////////////////
    var hoge = 'さぁ、付き合いますか!?';
    ///////////////////////////////////////////


    let speechText =  '<break time="0.7s"/>' + kotoha_20;

    return handlerInput.responseBuilder
      .speak('<speak>' + kotoha_20 + '</speak>')
      .reprompt('<speak>' + kotoha_20 + '</speak>')
      .withShouldEndSession(false) //本来きちんと対応する
      .getResponse();
  }
};


// returns true if the skill is running on a device with a display (show|spot)
function supportsDisplay(handlerInput) {
  var hasDisplay =
    handlerInput.requestEnvelope.context &&
    handlerInput.requestEnvelope.context.System &&
    handlerInput.requestEnvelope.context.System.device &&
    handlerInput.requestEnvelope.context.System.device.supportedInterfaces &&
    handlerInput.requestEnvelope.context.System.device.supportedInterfaces.Display;

  console.log("Supported Interfaces are" + JSON.stringify(handlerInput.requestEnvelope.context.System.device.supportedInterfaces));
  return hasDisplay;
}


// LaunchRequestHnadlerより後に書く必要あり
exports.handler = Alexa.SkillBuilders.standard()
  .addRequestHandlers(LaunchRequestHandler)
  .lambda();


これによりどうなるか

僕個人ですと、もっとキャラクターの表現がしやすくなりますし、ポッドキャストに近いこともできることになります。

90秒は結構厳しかったので、今回の対応はうれしい限りです。

が、4分間告白され続け、終わった後8秒間返答しないと repromptで再度4分間告白される動きを上記のコードだとしてしまいます。

いずれにしろ、この長くなったからといって、やみくもに長いのはユーザーからすると鬱陶しいので、それこそVUIデザインの話になるかと思います。
スキルの特性によって適宜利用していきましょう。

以上

4
1
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
4
1