我对 Alexa Skills Kit 非常陌生。我一直在尝试在https://www.pythonanywhere.com的网络托管服务器上制作简单的音乐播放器技能。当我尝试提出请求时
“SKILL_ENDPOINT_ERROR”
在设备日志中捕获,并具有以下描述:
“技能执行返回了 requestId amzn1.echo-api.request.e08ec414-0a30-4e95-87bb-28f315c8d4eb 的异常”。
这是我的技能请求处理程序代码:
from ask_sdk_core.skill_builder import SkillBuilder
from ask_sdk_core.utils import is_intent_name, is_request_type
from flask import Flask
from flask_ask_sdk.skill_adapter import SkillAdapter
from ask_sdk_model.ui import SimpleCard
app = Flask(__name__)
sb = SkillBuilder()
#VARIABLES
Current_song = ""
silent_mode = False
"""/////////////////////////
// Request Handlers //
////////////////////////"""
#Launch request
@sb.request_handler(can_handle_func=is_request_type("LaunchRequest"))
def launch_request_handler(handler_input):
speech_text = "What do you wish to play?"
return handler_input.response_builder.speak(speech_text).set_card(
SimpleCard("Hello World", speech_text)).set_should_end_session(
False).response
#Session Ended Request
@sb.request_handler(can_handle_func=is_request_type("SessionEndedRequest"))
def session_ended_request_handler(handler_input):
return handler_input.response_builder.response
"""/////////////////////////
// ASK Intent Handlers //
////////////////////////"""
#Help Intent
@sb.request_handler(can_handle_func=is_intent_name("AMAZON.HelpIntent"))
def help_intent_handler(handler_input):
speech_text = "You can ask me to play something on your server!"
return handler_input.response_builder.speak(speech_text).ask(
speech_text).set_card(SimpleCard(
"Wha can I do", speech_text)).response
#Stop Skill intent
@sb.request_handler(
can_handle_func=lambda handler_input:
is_intent_name("AMAZON.CancelIntent")(handler_input) or
is_intent_name("AMAZON.StopIntent")(handler_input))
def cancel_and_stop_intent_handler(handler_input):
speech_text = "Goodbye!"
return handler_input.response_builder.speak(speech_text).set_card(
SimpleCard("Hello World", speech_text)).response
#FallBack Intent
@sb.request_handler(can_handle_func=is_intent_name("AMAZON.FallbackIntent"))
def fallback_handler(handler_input):
speech = (
"I can't help you with that. "
"You can ask me to play music!")
reprompt = "You can ask me to play music!"
handler_input.response_builder.speak(speech).ask(reprompt)
return handler_input.response_builder.response
"""/////////////////////////
// Bot Intent Handlers //
////////////////////////"""
#Play Intent
@sb.request_handler(can_handle_func=is_intent_name("PlayIntent"))
def Play_intent_handler(handler_input):
song_value = handler_input.request_envelope.request.intent.slots["music"].value
if song_value:
speak_output = "Now playing {} on our server.".format(song_value)
Current_song = song_value
else:
speak_output = "I dont know what you want to play."
if silent_mode == False:
handler_input.response_builder.speak(speak_output).ask(speak_output).set_card(SimpleCard("Playing {}...".format(song_value), speak_output))
return handler_input.response_builder.response
#Pause Intent
@sb.request_handler(can_handle_func=is_intent_name("PauseIntent"))
def Pause_intent_handler(handler_input):
speak_output = "Paused."
if silent_mode == False:
handler_input.response_builder.speak(speak_output).set_card(SimpleCard("Pause", speak_output))
return handler_input.response_builder.response
#Loop Intent
@sb.request_handler(can_handle_func=is_intent_name("LoopIntent"))
def Loop_intent_handler(handler_input):
speak_output = "Song loop enabled."
if silent_mode == False:
handler_input.response_builder.speak(speak_output).set_card(SimpleCard("Loop", speak_output))
return handler_input.response_builder.response
#Restart Intent
@sb.request_handler(can_handle_func=is_intent_name("RestartIntent"))
def Restart_intent_handler(handler_input):
speak_output = "Restarting current song"
if silent_mode == False:
handler_input.response_builder.speak(speak_output).set_card(SimpleCard("Restart", speak_output))
return handler_input.response_builder.response
#Resume Intent
@sb.request_handler(can_handle_func=is_intent_name("ResumeIntent"))
def Resume_intent_handler(handler_input):
speak_output = "Resumed."
if silent_mode == False:
handler_input.response_builder.speak(speak_output).set_card(SimpleCard("Resume", speak_output))
return handler_input.response_builder.response
#Now Playing Intent
@sb.request_handler(can_handle_func=is_intent_name("NowPlayingIntent"))
def Now_Playing_intent_handler(handler_input):
if Current_song:
speak_output = "Now playing {}.".format(Current_song)
else:
speak_output = "There is nothing playing at the moment"
if silent_mode == False:
handler_input.response_builder.speak(speak_output).set_card(SimpleCard("Now Playing", speak_output))
return handler_input.response_builder.response
#Print Intent
@sb.request_handler(can_handle_func=is_intent_name("PrintIntent"))
def Print_intent_handler(handler_input):
speak_output = "Printed."
if silent_mode == False:
handler_input.response_builder.speak(speak_output).set_card(SimpleCard("Print", speak_output))
return handler_input.response_builder.response
#Remove Number Intent
@sb.request_handler(can_handle_func=is_intent_name("RemoveNumIntent"))
def Remove_Num_intent_handler(handler_input):
num_value = handler_input.request_envelope.request.intent.slots["MusicNum"].value
if num_value:
speak_output = "Removed song number {} from queue".format(num_value)
else:
speak_output = "There is no song in number {}".format(num_value)
if silent_mode == False:
handler_input.response_builder.speak(speak_output).ask(speak_output).set_card(SimpleCard("Remove", speak_output))
return handler_input.response_builder.response
#Remove Position Intent
@sb.request_handler(can_handle_func=is_intent_name("RemovePosIntent"))
def Remove_Pos_intent_handler(handler_input):
pos_value = handler_input.request_envelope.request.intent.slots["MusicPos"].value
if pos_value:
speak_output = "Removed {} song from queue.".format(pos_value)
else:
speak_output = "There is no {} song in queue.".format(pos_value)
if silent_mode == False:
handler_input.response_builder.speak(speak_output).ask(speak_output).set_card(SimpleCard("Remove", speak_output))
return handler_input.response_builder.response
#Remove All Intent
@sb.request_handler(can_handle_func=is_intent_name("RemoveALLIntent"))
def Remove_All_intent_handler(handler_input):
speak_output = "All songs removed from queue"
if silent_mode == False:
handler_input.response_builder.speak(speak_output).set_card(SimpleCard("Remove", speak_output))
return handler_input.response_builder.response
#Back Intent
@sb.request_handler(can_handle_func=is_intent_name("BackIntent"))
def Back_intent_handler(handler_input):
speak_output = "Went back a song in queue."
if silent_mode == False:
handler_input.response_builder.speak(speak_output).set_card(SimpleCard("Back", speak_output))
return handler_input.response_builder.response
#Skip Intent
@sb.request_handler(can_handle_func=is_intent_name("SkiptIntent"))
def Skip_intent_handler(handler_input):
speak_output = "Skipped."
if silent_mode == False:
handler_input.response_builder.speak(speak_output).set_card(SimpleCard("Skip", speak_output))
return handler_input.response_builder.response
#Shuffle Intent
@sb.request_handler(can_handle_func=is_intent_name("ShuffleIntent"))
def Shuffle_intent_handler(handler_input):
speak_output = "Shuffled queue."
if silent_mode == False:
handler_input.response_builder.speak(speak_output).set_card(SimpleCard("Shuffle", speak_output))
return handler_input.response_builder.response
#Skip to number Intent
@sb.request_handler(can_handle_func=is_intent_name("SkipToNumIntent"))
def Skip_To_Num_intent_handler(handler_input):
num_value = handler_input.request_envelope.request.intent.slots["MusicNum"].value
if num_value:
speak_output = "Skiped to song number {}.".format(num_value)
else:
speak_output = "There is no {} song in queue.".format(num_value)
if silent_mode == False:
handler_input.response_builder.speak(speak_output).ask(speak_output).set_card(SimpleCard("Skip To", speak_output))
return handler_input.response_builder.response
#Skip to position Intent
@sb.request_handler(can_handle_func=is_intent_name("SkipToPosIntent"))
def Skip_To_Pos_intent_handler(handler_input):
pos_value = handler_input.request_envelope.request.intent.slots["MusicPos"].value
if pos_value:
speak_output = "Skiped to {} song in queue.".format(pos_value)
else:
speak_output = "There is no {} song in queue.".format(pos_value)
if silent_mode == False:
handler_input.response_builder.speak(speak_output).ask(speak_output).set_card(SimpleCard("Skip To", speak_output))
return handler_input.response_builder.response
#Loop queue Intent
@sb.request_handler(can_handle_func=is_intent_name("LoopQueueIntent"))
def Loop_Queue_intent_handler(handler_input):
speak_output = "Looped queue."
if silent_mode == False:
handler_input.response_builder.speak(speak_output).set_card(SimpleCard("Loop Queue", speak_output))
return handler_input.response_builder.response
#Silent Mode Intent
@sb.request_handler(can_handle_func=is_intent_name("SilentModeIntent"))
def Silent_Mode_intent_handler(handler_input):
silent_mode = True
return handler_input.response_builder.response
#Disconnect Intent
@sb.request_handler(can_handle_func=is_intent_name("DisconnectIntent"))
def Disconnect_intent_handler(handler_input):
speak_output = "Disconnected."
if silent_mode == False:
handler_input.response_builder.speak(speak_output).set_card(SimpleCard("Disconnect", speak_output))
return handler_input.response_builder.response
sa = SkillAdapter(skill=sb.create(), skill_id="amzn1.ask.skill.e5e95d9a-6047-41aa-96f1-879b88421432", app=app)
"""/////////////////////////
// Exception Handlers //
////////////////////////"""
#Exception Handler
@sb.exception_handler(can_handle_func=lambda i, e: True)
def all_exception_handler(handler_input, exception):
speech = "Sorry, there was some problem. Please try again!!"
handler_input.response_builder.speak(speech).ask(speech)
return handler_input.response_builder.response
@app.route("/")
def invoke_skill():
return sa.dispatch_request()
我首先假设问题是我没有异常处理程序,但是自从我实现了一个异常处理程序后,结果没有任何变化。
有没有人解决了这个问题或知道我的代码缺少什么?