简体   繁体   中英

How to make an Alexa skill that looks up something based on input?

I'm trying to build an Alexa skill that mimics the functionality of the NPR skill. For example, assuming that the invocation name is "NPR", the dialogue would look something like this:

  • User: Alexa, open NPR
  • Alexa: 'Welcome, please tell me a ZIP code or city'
  • User: 44691
  • Alexa: In that ZIP code, there are two radio stations: radio1 and radio2 (example radio stations). Which one would you like to play?
  • User: radio1
  • (At this point, Alexa plays radio1)

So far, I have two slots {zip} and {city}. I have also made an intent named "ZiporCityIntent" that is supposed to catch the ZIP code or city that the user says. However, I am lost at this point and am not sure how to proceed. My goal is as follows:

  1. To have Alexa take in the ZIP code or city input
  2. To have Alexa look up the available radio stations at that ZIP code or city and list them to the user
  3. To play the radio station specified by the user (from the available radio stations)

I would appreciate any advice or guidance. Thank you for your time.

I'll try to answer each of your questions separately.

  1. Zip code may be hard to model as a custom slot. There isn't a built-in slot for that. You'd probably have to use the AMAZON.NUMBER slot type and create an intent with utterances that had multiple slots in them with that time. Painful to do I suspect and tough to ensure it'll be an accurate experience for your users. https://developer.amazon.com/en-US/docs/alexa/custom-skills/slot-type-reference.html#numbers-dates-times

As an alternative to asking for zip code, you could use location services to fetch the user's device's location. You will have to get permission from the user though. https://developer.amazon.com/en-US/docs/alexa/custom-skills/location-services-for-alexa-skills.html

There is a slot type, however, for cities. (See AMAZON.US_CITY https://developer.amazon.com/en-US/docs/alexa/custom-skills/slot-type-reference.html#list-types )

  1. Is there an API you can use that takes in a zip code or city and gives you back a list of radio stations (an object with name and streaming URL, I imagine)? If not, perhaps you can go the simple route of define this mapping in your code. If it's not a super large data set, I could storing this as a JSON file.

  2. Look into the AudioPlayer interface. Make sure the media format is compatible. https://developer.amazon.com/en-US/docs/alexa/custom-skills/audioplayer-interface-reference.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM