Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alexa Skill - How to get complete text of statement asked to alexa

I am creating an Alexa skill, I have coded several custom and default intents and they are working fine.

Now I want to write a fallback intent wherein I want to get the exact statement asked/sent to Alexa skill, is there a way wherein we may get the entire question string/text that has been asked to Alexa skill. I know we can get slot values and intent information, but I need the entire text statement sent to skill.

Thanks

like image 947
NKS Avatar asked May 07 '18 05:05

NKS


People also ask

How do you get Alexa to text?

What to Know. Say "Alexa, Simon says," followed by what you want it to say. It will repeat back your command. Download the Text to Voice skill in the Alexa app, go to Test to Voice in a browser, and follow the instructions to pair your Alexa device.

What is an Alexa Speechlet?

Speechlet class is the most important class in Alexa echo system. It controls all the conversation between the Alexa device and the user. It takes user input and invokes the programs which perform the actions asked by the user.


2 Answers

Well, I had faced the same issue. After trying several methods, I have got the complete text of the statement asked Alexa.

You have to make the following setup in your Alexa skill (name of intent, slot name, and slot type you can choose as per your need)

Setting up Intent

Setting up Intent

Setting up custom slot type

Setting up custom slot type

After setting up your Alexa skill you can invoke your skill, keep some response for launch request and say anything you want, you can catch the entire text as shown here.

"intent": {
            "name": "sample",
            "confirmationStatus": "NONE",
            "slots": {
                "sentence": {
                    "name": "sentence",
                    "value": "hello, how are you?",
                    "resolutions": {
                        "resolutionsPerAuthority": [
                            {
                                "authority": "xxxxxxx",
                                "status": {
                                    "code": "xxxxxxx"
                                }
                            }
                        ]
                    },
                    "confirmationStatus": "NONE",
                    "source": "USER"
                }
            }
        }

Note*: In this method you will need to handle utterances properly if there are more than one intent.

like image 65
Abhijeet Abnave Avatar answered Sep 24 '22 19:09

Abhijeet Abnave


There's no way to get the whole utterance straight from a top level intent. Right now the closest you can get is using a custom slot with type AMAZON.SearchQuery (not a custom type as suggested in another answer) but you will have to define an anchor phrase in your utterance that goes before the slot. For example, you would define an utterance like:

search {query}

where query is a slot of type AMAZON.SearchQuery.

The anchor search in the utterance is mandatory (a requirement of the SearchQuery type), so as long as the user starts the utterance by saying search, anything that follows will be captured which is pretty close to what you want to achieve.

Having said that there's actually one indirect way to approximate capturing the whole utterance the user is saying (filtered by NLU) leveraging AMAZON.SearchQuery but only as part of an ongoing dialog using Dialog Management. If you're engaging in a dialog of this kind where Alexa automatically uses defined prompts to solicit slot information you can define an utterance that is a single isolated slot of type AMAZON.SearchQuery with no anchor. Example:

Alexa: Ok, I will create a reminder for you. Please tell me the text of the reminder

User: Pick of the kids from school

Alexa: Ok. I will remind you to Pick up the kids from school

In the example above Alexa detects that the user wants to send a reminder but there's no reminder text set up so it elicits the slot. When you, as a developer, define the prompts that Alexa needs to ask you also define the possible reponses. In this case you can define a response utterance as just:

{query}

and capture the whole thing the user says in response to the prompt, like e.g. "pick up the kids from school"

like image 34
German Avatar answered Sep 24 '22 19:09

German