Search code examples
node.jsamazon-web-servicesalexa-skills-kit

How to capture decimals with Amazon Alexa?


I am looking for a way to allow for Alexa to capture a decimal value. I am trying to speak a temperature to her (54.3). My constraint is that sometimes I want to be able to enter an integer value (54) and not have a trailing value (.0).

Any help would be appreciated.


Solution

  • I don't think Amazon provides a built-in slot for fractional or decimal numbers, but you could create one yourself to use. You can make the decimal part optional in your handling of the intent.

    So for example, create a single intent that includes slots for each part of the number. Using a single intent to do this make the decimal part optional.

    • "the temperature is {TemperatureSlot}"
    • "the temperature is {TemperatureSlot} point {PartialTempSlot}"

    Both TemperatureSlot and PartialTempSlot can be whatever slot name you like, and would be built-in number slots (AMAZON.NUMBER)

    If the user doesn't specify a decimal value, then PartialTempSlot will be missing, so you'll know that just an integer number was provided.