質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Alexa

Alexa(アレクサ)は、米アマゾンが開発したクラウドベースのAIアシスタント。Amazon EchoやEcho dotに搭載され、話かけると音楽を再生したり、天気予報やスケジュールなど様々な情報を提供します。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

1回答

1515閲覧

Alexaを使ったお弁当の注文

ka2

総合スコア16

Alexa

Alexa(アレクサ)は、米アマゾンが開発したクラウドベースのAIアシスタント。Amazon EchoやEcho dotに搭載され、話かけると音楽を再生したり、天気予報やスケジュールなど様々な情報を提供します。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

1クリップ

投稿2019/01/21 01:15

編集2022/01/12 10:55

Alexaを使った実店舗の注文システムを作りたいと考えています。
お弁当屋さんに来たお客さんがAlexaに注文を話し、それを厨房に伝えるシステムです

イメージとしては以下のようになります。

客  「注文」//Alexaのインテントトリガー
Alexa「注文をどうぞ」//レスポンス
客  「○○を一つ○○の大盛りを2つ・・・」//関数(注文内容を厨房のタブレットにslackを使って表示
「~以上で」//注文を終わらせる文言
Alexa「注文は(注文内容繰り返し)でよろしかったでしょうか」
客  「はい」
Alexa「出来上がりまで少々お待ちください」//終了

Alexaに話したことをslackに表示させることはできたのですが、大盛りや弁当の個数、注文を終わらせるまでループ処理をさせる、といったところでつまずいております。なにかヒントをいただければ幸いです。

python

1#coding : utf-8 2""" 3This sample demonstrates a simple skill built with the Amazon Alexa Skills Kit. 4The Intent Schema, Custom Slots, and Sample Utterances for this skill, as well 5as testing instructions are located at http://amzn.to/1LzFrj6 6 7For additional samples, visit the Alexa Skills Kit Getting Started guide at 8http://amzn.to/1LGWsLG 9""" 10 11from __future__ import print_function 12import urllib.parse 13import urllib.request 14 15 16# --------------- Helpers that build all of the responses ---------------------- 17 18def build_speechlet_response(title, output, reprompt_text, should_end_session): 19 return { 20 'outputSpeech': { 21 'type': 'PlainText', 22 'text': output 23 }, 24 'card': { 25 'type': 'Simple', 26 'title': "SessionSpeechlet - " + title, 27 'content': "SessionSpeechlet - " + output 28 }, 29 'reprompt': { 30 'outputSpeech': { 31 'type': 'PlainText', 32 'text': reprompt_text 33 } 34 }, 35 'shouldEndSession': should_end_session 36 } 37 38 39def build_response(session_attributes, speechlet_response): 40 return { 41 'version': '1.0', 42 'sessionAttributes': session_attributes, 43 'response': speechlet_response 44 } 45 46 47# --------------- Functions that control the skill's behavior ------------------ 48 49def get_welcome_response(): 50 """ If we wanted to initialize the session to have some attributes we could 51 add those here 52 """ 53 54 session_attributes = {} 55 card_title = "Welcome" 56 speech_output = "注文をどうぞ" 57 reprompt_text = "もう一度おねがいします" 58 should_end_session = False 59 return build_response(session_attributes, build_speechlet_response( 60 card_title, speech_output, reprompt_text, should_end_session)) 61 62 63def handle_session_end_request(): 64 card_title = "Session Ended" 65 speech_output = "Thank you for trying the Alexa Skills Kit sample. " \ 66 "Have a nice day! " 67 # Setting this to true ends the session and exits the skill. 68 should_end_session = True 69 return build_response({}, build_speechlet_response( 70 card_title, speech_output, None, should_end_session)) 71 72 73def take_memo(intent, session): 74 try: 75 memo = intent["slots"]["contents"].get("value") 76 url = ''//ここにwebhookを使って作成したURLを入れる 77 params = urllib.parse.urlencode({"payload": {"text":":memo:"+memo}}).encode("utf-8") 78 f = urllib.request.urlopen(url, params) 79 speech_output = "注文を受け付けました" 80 except: 81 speech_output = "失敗しました" 82 83 session_attributes = {} 84 reprompt_text = None 85 should_end_session = True 86 return build_response(session_attributes, build_speechlet_response( 87 intent['name'], speech_output, reprompt_text, should_end_session)) 88 89 90# --------------- Events ------------------ 91 92def on_session_started(session_started_request, session): 93 """ Called when the session starts """ 94 95 print("on_session_started requestId=" + session_started_request['requestId'] 96 + ", sessionId=" + session['sessionId']) 97 98 99def on_launch(launch_request, session): 100 """ Called when the user launches the skill without specifying what they 101 want 102 """ 103 104 print("on_launch requestId=" + launch_request['requestId'] + 105 ", sessionId=" + session['sessionId']) 106 # Dispatch to your skill's launch 107 return get_welcome_response() 108 109 110def on_intent(intent_request, session): 111 """ Called when the user specifies an intent for this skill """ 112 113 print("on_intent requestId=" + intent_request['requestId'] + 114 ", sessionId=" + session['sessionId']) 115 116 intent = intent_request['intent'] 117 intent_name = intent_request['intent']['name'] 118 119 # Dispatch to your skill's intent handlers 120 if intent_name == "Memointent": 121 return take_memo(intent, session) 122 elif intent_name == "AMAZON.HelpIntent": 123 return get_welcome_response() 124 elif intent_name == "AMAZON.CancelIntent" or intent_name == "AMAZON.StopIntent": 125 return handle_session_end_request() 126 else: 127 raise ValueError("Invalid intent") 128 129 130def on_session_ended(session_ended_request, session): 131 """ Called when the user ends the session. 132 133 Is not called when the skill returns should_end_session=true 134 """ 135 print("on_session_ended requestId=" + session_ended_request['requestId'] + 136 ", sessionId=" + session['sessionId']) 137 # add cleanup logic here 138 139 140# --------------- Main handler ------------------ 141 142def lambda_handler(event, context): 143 """ Route the incoming request based on type (LaunchRequest, IntentRequest, 144 etc.) The JSON body of the request is provided in the event parameter. 145 """ 146 print("event.session.application.applicationId=" + 147 event['session']['application']['applicationId']) 148 149 """ 150 Uncomment this if statement and populate with your skill's application ID to 151 prevent someone else from configuring a skill that sends requests to this 152 function. 153 """ 154 # if (event['session']['application']['applicationId'] != 155 # "amzn1.echo-sdk-ams.app.[unique-value-here]"): 156 # raise ValueError("Invalid Application ID") 157 158 if event['session']['new']: 159 on_session_started({'requestId': event['request']['requestId']}, 160 event['session']) 161 162 if event['request']['type'] == "LaunchRequest": 163 return on_launch(event['request'], event['session']) 164 elif event['request']['type'] == "IntentRequest": 165 return on_intent(event['request'], event['session']) 166 elif event['request']['type'] == "SessionEndedRequest": 167 return on_session_ended(event['request'], event['session'])

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

y_waiwai

2019/01/21 01:18

> Alexaに話したことをslackに表示させること のところのコードを提示しましょう
ka2

2019/01/21 01:20

スミマセン!忘れてしまっていました!
guest

回答1

0

こんにちは。

対話を続けるためにはセッションとステート(状態)の管理が必要ですね。
下が参考になります。

Alexaスキル開発トレーニングシリーズ 第3回 音声ユーザーインターフェースの設計 : Alexa Blogs

投稿2019/01/23 01:28

firedfly

総合スコア1131

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問