Getting Alexa To Pronounce Ordinals

Today, I’m working on a project that requires Alexa to say things like “first,” “second,” or “twenty-first.”  I’ve gone through a few iterations of creating these ordinal strings.

First: Brute Force Attempt

I started the easy way: I created a hard-coded switch statement for the values from 1 – 10, and used a helper function to feed me the appropriate return value as a string..  Not the most elegant, but it got the job done.

Second: Slightly More Elegant and Scaleable

As my application grew, I realized that I would now need the values from 1 – 50 available in my application.  I added to my switch statement…until I got to 15.  At that point, I realized I needed a new solution that could scale to any number I passed in.  So I started writing some logic to append “st” to numbers that ended in 1, “nd” to numbers that ended in 2, “rd” to numbers that ended in 3, and “th” to pretty much everything else.  I had to write some exception cases for 11, 12, and 13.

It was at this point that I made an amazing discovery.

Third: Alexa is already too smart for me.

While playing with my second solution, I used the Voice Simulator that is available when you are building an Alexa skill.  I wanted to see if Alexa would pronounce the words the same if I just appended the suffixes like “th” or “nd” to the actual number value, rather than trying to convert the whole thing to a word.

This is where the discovery was made.

I tried getting her to say “4th,” and she pronounced it as I expected: “fourth.”

On a whim, I added “th” to the number 2, which would normally be incorrect.  She pronounced it “second.”  I had the same experience with “1th,” which she still got correct as “first.”

If you append “th” to the end of any number, Alexa will pronounce the appropriate ordinal.

My mind was slightly blown today.  Thanks, Alexa.

Holy Cow Garageio!

I’ve decided to start a series of posts about the ever-growing list of smart home devices I’ve decided to bring into my home.  These won’t be on a regular schedule, but as I continue to add functionality to my house, I’ll do my best to provide my opinions and experience with those products.

Today, I want to talk about Garageio.

garageio

You can probably guess from the name, but Garageio is a device that you connect to your garage doors to open/close them, as well as monitor their state.  In addition, you can connect Garageio to Alexa, and make all of that functionality happen with your voice.

Yes, there are certainly cheaper options.  Yes, you could probably build one yourself.  But to get all of this functionality in a package that works reliably, had IFTTT integrations, a great mobile experience, AND works with Alexa?  That’s a tougher deal to beat.

In fact, I tried.  I bought a WeMo Maker device ($70) and hooked that up to my garage door.  It worked, but it didn’t manage state.  So I added a webcam to my garage so that I could see whether the door was open.  It also only allowed me to send an “event” to my door, which meant that it would close if it was open, and open if it was closed.  Not a great experience.

Installation

Installation was surprisingly easy.  The entire contents of the box boiled down to five parts. (I have the two-door model, but the different models really just determine how many wires you get.  It appears it’s always the same box.)

  • The Garageio Black Box
  • Wire for connecting box to garage door opener #1.
  • Wire for connecting box to garage door opener #2.
  • Sensor for garage door #1.
  • Sensor for garage door #2.

Basically, you connect all four wires to the box, connect the box to your wifi, and you’re off and running.  Incredibly easy.

garageioproductphotos-6

Using the Garageio App

For most smart home devices, the app that drives everything is a make-or-break experience.  Thankfully, the Garageio team knocked this one out of the park.  I have a horizontal scrolling list of my doors, and swiping up on a door opens it, swiping down closes it.

20161107_151428000_ios

I also get notifications if a door stays open for 15 minutes.  This is a nice feature, but as a parent of two active kids, the door is constantly open in the afternoons after school.  My daughter gets home at 3pm, and so nearly every day at 3:15pm, I get a notification that the door is still open.  You only get one notification, however, so it’s not annoying.

You can see from my screenshot that there’s also the ability to “Share Doors.”  This allows me to grant temporary (or permanent) access to my garage door to others.

20161107_152049000_ios

IFTTT Integration

As expected, they also did an excellent job with their IFTTT integrations, so that all of the functionality I want can be triggered by all of the other services I use.  For example, I can set a geofence on my phone, so that if I enter a specific area, my garage door automatically opens.

I can also set specific times for it, so that at 10:30pm, it automatically shuts both of my doors so that I don’t leave them open all night.

If you’ve used IFTTT, you know this is only scratching the surface of what is possible, but there’s only so many creative ways to open and close a door.  So far, I’ve been delighted, however.

Alexa Integration

“Alexa, ask Garageio to close Bike Door.”

It works exactly as you would expect.

Garageio was an early entrant in to the world of Alexa, which is awesome.   I think that they will eventually hook it up to the new smart home skill API, which helps in simplifying how I communicate with it, but even now, it’s perfect. It recognizes the names I gave my doors, and works every time.  I’m really happy to have this device in my house, and I would highly recommend it for yours.

You can pick one up on Amazon for about $200.

Making An Alexa Raspberry Pi

Last week, I ordered all of the bits and pieces I needed to get a Raspberry Pi configured to become an Alexa device.  It was incredibly easy, the tutorial was very straightforward, and I ended up with something that can do this:

What You Need

If you want to try this, here’s what you’ll need (links and prices from Amazon):

Optionally, you might want to protect your Raspberry Pi if you plan to take it anywhere.  They make a very nice, inexpensive case for it:

Finally, there are a few things you’ll need to get it running, but these are things I assume you probably have.  If you don’t, I’ve recommended some with the links.

  • USB keyboard & mouse (Logitech MK270 Wireless USB keyboard and mouse – $19.95)

    keyboard
    I like this one because it’s small, compact, and easy to travel with.  Most travel keyboards are garbage, so I tend to lean towards smaller, full-function keyboards instead.  (My primary keyboard is a Das Keyboard, much bigger and clickier.)

  • HDMI monitor (there are way too many options here, any monitor will do. I’m hunting for a tiny one I can travel with.  Like 5″ or smaller.  But in a secure case, since it will likely see the bottom of my backpack occasionally.)
  • Micro-USB Charging Cable (you literally have 100 of these in a drawer. Any of them.)
  • 3.5mm audio cable
  • Literally ANY speaker that can take a 3.5mm audio cable as input (I used the Nokia MD-12 for mine, but you can certainly find cheaper speakers if you need one.)

    nokiamd12

The How-To

I would normally give you a run-down of the steps I took, and the issues I faced, but there simply isn’t much point in that.  I followed the provided tutorial on GitHub, and it was one of the smoothest experiences I’ve ever had setting something like this up.

https://github.com/alexa/alexa-avs-sample-app/wiki/Raspberry-Pi

My Takeaways

I’m working on a few things to enhance the experience, but here’s my takeaways:

  1. If you ONLY want an Alexa device, this is probably not the project for you.  The Echo Dot is $49.99, and doesn’t require any setup to work.  This project, at a minimum cost, is about $53.15.  That being said, having an Alexa device that can also run some other services is really compelling.  Adding a touchscreen to it would allow you to see the “cards” that Alexa skills produce at http://alexa.amazon.com, for example.
  2. Each time you power up the Raspberry Pi, you have to manually start all of the services again.  I’m hoping that with some creative effort, this might not always be true, but there’s some authentication that happens that requires your monitor, mouse, and keyboard every time you power it up.  (This is why I’m looking for travel keyboards and monitors.)
  3. This was one of my first experiences in the Raspberry Pi ecosystem, and I’m very excited by what I found.  There are tons of accessories to enhance and protect your device, and I’m looking forward to seeing where I can take this project forward.