question

joseacevedo avatar image
joseacevedo asked

Split a long speech in Alexa Amazon in parts

I am developing a simple "skill" in Alexa where you ask her questions and the answers are "hardcode" in the code since they are fixed answers.

My question is the following: one of the Intents is activated with a phrase "Tell me the 9 rules of good behavior". The problem is that these rules are very long and the user can get bored quickly. What I want to do is that Alexa tells you the rules 1,2 and 3, and ask you, do you want to continue listening the rules?.

If you say yes, she tells you the following 3 rules, and so on.

If you say no, she goes back to the initial menu, the "Skill Invocation". It is possible to do that?. I tried to use slots, but I didn`t get what I wanted. I think is not the more logical way to use slots in this case.

Here is the code that I have for this intent:


class TheNineRulesIntentHandler(AbstractRequestHandler):
 """Handler for TheNineRulesIntent.""" 
def can_handle(self, handler_input):    
# type: (HandlerInput) -> bool    
return ask_utils.is_intent_name("TheNineRulesIntent")(handler_input) 

def handle(self, handler_input):    
# type: (HandlerInput) -> Response    
speak_output = "The Nine Rules are:\    
1. Long Text...\    
2. Long Text...\    
3. Long Text...\    
4. Long Text...\    
5. Long Text...\    
6. Long Text...\    
7. Long Text...\    
8. Long Text...\    
9. Long Text... "     
return (        
handler_input.response_builder            
.speak(speak_output)            
.ask(speak_output)            
.response    )


Thanks,


Jose

alexa skills kitalexaskillsalexa skills
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Rokas avatar image
Rokas answered

It is possible to do it to work the way you want. If I were you I would add state variable as amazon team does in this example: here. It is in JS, but I think it should be pretty similar in Python.

Now what you want to do is have several states: launched, readingRules etc.

Also I would put those rules in the array, so that when alexa reads them, you can keep a track of which rules were already read, by persisting index.

So how it would work is user would launch the skill. Your game would be in launched state. If user says 'yes' in this state, treat it as an unparsed. If user asks skill to read rules, you set state to 'readingRules' and pick first three rules from array. In 'rules' handler you save the index of last fact you have read to the session attributes and at the end of the speech, you append you question: 'do you want to hear more rules'.

Because user is in 'readingRules' state, you handle yes/no differently compared to when user was in 'launched' state. If user says 'yes' now, you give him the next three rules, starting from the last one you gave him in the previous intent. If user says no, you give him the launch copy and switch state to 'launched'.

I hope this is comprehensive enough to get you going on solving this. If any of the parts are not clear or you need more help, just let me know.

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Paiva Jr. avatar image
Paiva Jr. answered

Alexa does that natively for long texts. I think ASK might have a way to do split long answers easily — and natively.

I'd like to know that as well. I have a Q&A and one of my answers is a list (in an array) that I'd like to split it to not let anyone bored, with a confirmation whether Alexa should continue or not. BTW, I think is not a smart way I re-write all the ways to say "yes" or "no" for the confirmation question.

I'm still looking for a good solution.

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.