Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Storylineではじめる モック駆動Alexa Skill開発 / alexa-story...

Storylineではじめる モック駆動Alexa Skill開発 / alexa-storyline

Hidetaka Okamoto

May 29, 2018
Tweet

More Decks by Hidetaka Okamoto

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ • Digitalcube Co. Ltd. • WordCamp Kyoto 2017࣮ߦҕ һ௕

    • AWS Samurai 2017 H i d e t a k a O k a m o t o
  2. Alexa SkillͰ࡞Δ΋ͷ͸̎ͭ A u d i o C a p

    t u re A u d i o P l a y b a c k C a l l w e b A P I Ta l k s o m t h i n g R e s p o n c e S p e e c h t o Te x t Te x t t o S p e e c h A l e x a S k i l l s K i t - > Ի ੠ Λ Ͳ ͏ ม ׵ ͢ Δ ͔ AW S L a m b d a - > Ͳ ͏ σ ʔ λ Λ ॲ ཧ ͢ Δ ͔
  3. ʮԻ੠ΛͲ͏ม׵͢Δ͔ʯ͕࠷༏ઌ A u d i o C a p t

    u re A u d i o P l a y b a c k C a l l w e b A P I Ta l k s o m t h i n g R e s p o n c e S p e e c h t o Te x t Te x t t o S p e e c h A l e x a S k i l l s K i t - > Ի ੠ Λ Ͳ ͏ ม ׵ ͢ Δ ͔ ʮ Կ ͕ ͘Δ ͔ ʯ ͕ Θ ͔ Β ͳ ͍ ͱ ࣮ ૷ ʹ ೖ Ε ͳ ͍
  4. ͳͥStorylineΛ࢖͏΂͖͔ʁ • ର࿩Ϟσϧ͕μϝͳΒͦ΋ͦ΋࢖ΘΕͳ͍ • ࣮ࡍͷར༻γʔϯͰςετͯ͠ௐ੔͢΂͖ • ͦ΋ͦ΋ͦͷγʔϯͰԻ੠ΞϓϦ͸ඞཁ͔ʁ • ΋ࣗ͠෼͕ਓʹ͓ئ͍͢ΔͳΒͲ͏͍͏͔ʁ •

    ேٸ͍Ͱ͍Δ࣌ʹͦͷฦࣄ͸ΠϥΠϥ͠ͳ͍ʁ • ུশ΍ํݴΛΧόʔͰ͖͍ͯΔʁ • νΣοΫϦετͷʮϢʔβʔ͕εΩϧΛར༻͢Δͱ͜Ζ Λ؍࡯͠·͔ͨ͠ʁʯΛૉૣ࢝͘ΊΕΔ
  5. alexa-sdk / Lambda͸΋͏ཁΒͳ͍ͷʁ • ͦΜͳ͜ͱ͸ͳ͍ɻ • GUIͰܧଓతʹอक͍ͨ͠։ൃνʔϜ͕͍Ε͹ผ͔΋ • Storyline΍BlueprintͰɺର࿩ϞσϧΛ࡞Δ •

    ର࿩ϞσϧͱγφϦΦ͕͋Ε͹ɺςετέʔε͕࡞ΕΔ • JSONಡΊΕ͹ςετίʔυ΋͔͚Δ • ϞοΫ͔Β࡞Δͱɺޮ཰తʹ࣮૷ʹೖΔ͜ͱ͕Ͱ͖Δ
  6. Alexa Skills Kitʹ͸CLIπʔϧ͕͋Δ $ npm i -g ask-cli $ ask

    -h Usage: ask [options] [command] Command Line Interface for Alexa Skill Management API
  7. Storyline͕σϓϩΠͨ͠σʔλΛΤΫεϙʔτ # ͻͳܗ࡞੒ $ ask new -n SKILL_NAME && cd

    SKILL_NAME # εΩϧ৘ใ $ ask api get-skill -s {SKILL_ID} > ./skill.json # ର࿩Ϟσϧ $ ask api get-model -s {SKILL_ID} \ —stage development -l ja-JP > ./models/ja-JP.json
  8. ࡞ͬͨϞοΫΛLambda / API։ൃʹ׆͔͢ • StorylineͰ࡞ͬͨϞοΫΛσϓϩΠ͢Δ • Alexa։ൃίϯιʔϧͰςετ͢Δ • දࣔ͞Εͨinput /

    outputΛه࿥͢Δ • ։ൃνʔϜʹinput / outputΛࢀߟʹ࣮૷ͯ͠΋Β͏ • in / outΛςετίʔυԽͰ͖Ε͹ΑΓ҆ఆͨ͠։ൃʹ
  9. Dialog.DelegateσΟϨΫςΟϒΛ࢖ͬͯॲཧ // ͜͜ͷintentRequestม਺͸ɺεΩϧʹૹ৴͞ΕΔIntentRequestΦϒδΣΫτͰ͢ɻ if (intentRequest.dialogState === "STARTED"){ // ೖྗࡁΈεϩοτ: σϑΥϧτ஋ͷ͋Δεϩοτ஋Λ࢖༻ͯ͠

    // ΠϯςϯτΦϒδΣΫτΛߋ৽͠·͢ɻ࣍ʹupdatedIntentϓϩύςΟͷ͜ͷߋ৽͞ΕͨΠϯ ςϯτͰ // Dialog.DelegateΛฦ͠·͢ɻ } else if (intentRequest.dialogState != "COMPLETED"){ // updatedIntentϓϩύςΟΛ࣋ͨͳ͍Dialog.Delegate σΟϨΫςΟϒΛฦ͠·͢ɻ } else { // μΠΞϩά͸׬ྃ͠ɺ͢΂ͯͷඞཁͳεϩοτ͕ೖྗ͞Ε·ͨ͠ɻ // ௨ৗͷΠϯςϯτϋϯυϥʔΛݺͼग़͍ͯͩ͘͠͞ɻ handlePlanMyTripIntent(intent, session, callback); }
  10. ޮՌԻΛ؆୯ʹೖखɾར༻Ͱ͖ΔΑ͏ʹͳΔ <speak> This is Alexa's regular speech, followed by the

    sound effect "bear groan roar (1)". <audio src='https://s3.amazonaws.com/ask- soundlibrary/animals/ amzn_sfx_bear_groan_roar_01.mp3'/> </speak>
  11. ޮՌԻͷछྨ΋๛෋ • Ambience • Animal • Battle • Cartoon •

    Foley • Home • Human • Impact • Magic • Musical • Nature • Office • SciFi • Transportation
  12. ϥϯμϜͳฦ౴Λฦ࣮͢૷αϯϓϧ const { randomResponse } = require('ask-utils') const errorMessages =

    [ '͢Έ·ͤΜɺΑ͘ฉ͖औΕ·ͤΜͰͨ͠ɻ΋͏Ұ౓͓ئ͍͠·͢ɻ', '͢Έ·ͤΜɺΑ͘ฉ͖औΕ·ͤΜͰͨ͠ɻ', '্खʹฉ͖औΕͳͯ͘͢Έ·ͤΜɻ΋͏Ұ౓ݴͬͯ΋Β͑·͔͢ʁ', '͝ΊΜͳ͍͞ɻ΋͏Ұ౓ݴͬͯ΋Β͑Δͱॿ͔Γ·͢ɻ' ] const message = randomResponse.getRandomMessage(errorMessages) return handlerInput.responseBuilder .speak(message) .reprompt(message) .getResponse()
  13. ϥϯμϜͳฦ౴Λฦ࣮͢૷αϯϓϧ const { randomResponse } = require('ask-utils') const errorMessages =

    [ '͢Έ·ͤΜɺΑ͘ฉ͖औΕ·ͤΜͰͨ͠ɻ΋͏Ұ౓͓ئ͍͠·͢ɻ', '͢Έ·ͤΜɺΑ͘ฉ͖औΕ·ͤΜͰͨ͠ɻ', '্खʹฉ͖औΕͳͯ͘͢Έ·ͤΜɻ΋͏Ұ౓ݴͬͯ΋Β͑·͔͢ʁ', '͝ΊΜͳ͍͞ɻ΋͏Ұ౓ݴͬͯ΋Β͑Δͱॿ͔Γ·͢ɻ' ] const message = randomResponse.getRandomMessage(errorMessages) return handlerInput.responseBuilder .speak(message) .reprompt(message) .getResponse()