Categories
Software

Building your own Alexa skill using AWS Lambda and Python (Part 1)

While I resisted the pull of the ‘smart speaker’ for a little while, I have to admit having Amazon Music and an Echo has been one of the most enjoyable things I’ve bought for myself over the past couple of years. Maybe it’s my age, but voice activation still seems very cool to me, but I’m middle aged, quite often tired and like most adults, I have a lot of dull stuff to do in my life. ‘Aha…… Katie, why not automate away that toil……’

So yes, that’s why I thought it would be fun (and help me reawaken some tech skills) to build my own app. Of course, their is info out there already on this, but I found a lot of it stopped a bit short, or jumped right into the code writing. So here’s my write up of the first part of it which is the basic interaction between you and Alexa. After that I’ll do write ups of how to use lambda a bit more to actually have functionality.

You will need:

  • A developer account for the Alexa Skills Kit (ASK)/ Alexa Developer Console. developer.amazon.com
  • An AWS account: aws.amazon.com . You can get an account with a free tier to use AWS lambda assuming you don’t exceed 1 million requests a month. (You’ll need to provide a payment method to get the account)
  • Some basic python coding skills
  • A brilliant idea!

Alexa Developer Console

This is where you create the voice interaction model. It’s a web based IDE- nothing to download, and it has it’s own test environment. I used the following tutorial, but I found it simpler to write up my own notes.

Here’s my translation of the Alexa terms:

  1. A name for your skill ie. ” Alexa, open <insert cool name here>”- that’s the invocation name. I recommend making it simple as you may forget it….. I did, more than once.
  2. Intents could be translated as ‘functions’ of the app. With utterances being the phrases you may say, to initiate those ‘functions’.
  3. Within the utterances, you can set variables- which translates as ‘slots’. You can set the available value of the slot.
  4. Set your endpoint- ie. link it to the code in AWS Lamda

Example:

Invocation: Bin check

Intents: Check_next

Utterance: When is the next {bin_type} collection

Intent Slots: bin_type

Slot Type: waste_type with user utterances: garden waste; rubbish etc.

Once you have it all set up you’ll need to ‘build model’.

But really, that won’t do anything on it’s own. That’s where lambda comes in.

To get ready for the next bit I recommend going to the Endpoint menu to show your ‘Skill ID’ which you’ll need for later:

AWS Lambda:

For this I assume you’ve set up an AWS account and are on the Lambda service.

Firstly, You’re going to need to create a new function.

Choose a name (I went for ‘Bins’), and choose the language in which you’ll write the function. I went for Python and left the default IAM selection.

Now press ‘Create function’.

Once created you’ll see the IDE with the following at the top. This is how you link it to the ASK work you did earlier. At the following :

Click “Add trigger”. You want to choose “Alexa Skills Kit”

The following should appear and you can add the Skill ID I highlighted earlier. Click Add.

You now want to do the reverse. At the top right of the functions screen you should see the following. Copy this ready to link it back.

Right. Now back to the ASK console. Back to the Endpoints section and copy and past your function ID in. Notice you have regional options if perhaps in your Alexa skill, a reference to pants might warrant a different response if your end user is in the UK or the US………

Save the end points and …. ta da……. you’ve linked your alexa skill to a function! Sure it doesn’t do anything yet….. but hey. That’s part 2…..

Categories
Life in lockdown

Are we human, or are we dancer?

Tomorrow marks the very gradual lifting of restrictions on daily life for England (Scotland and Wales having made different choices).

On reflection, so far the lockdown hasn’t been all bad. People have made sure to look at for one another and a sense of comaradrie is present.

That said, there still have been tough times. It feels very normal and yet not normal sometimes. Seeing the number of people who have died each day makes sobering reading and I find myself switching between seeing small troubles at home and work disappear into insignifance and at other times, those same annoyances loom large as they are ever present.

Anyway, for now, I hope tomorrow marks the path forward. I took a walk this evening and listened to music. The streets were deserted. I danced, let go of my self consciousness and reminded myself that life is indeed, very precious.

Categories
Life in lockdown Science

Stargazing

I read an article yesterday that there was to be a meteor shower for the next two nights that would be visible without the need for a telescope. Given I’d got myself all worked up about an issue at work, I thought a nice reminder of how unimportant it all is would be just the thing I needed. I went out after 10pm to have a look as the sky was clear, I couldn’t see any meteors, or indeed the satellites which everyone else seems to be spotting recently but I did see what I think is Venus shining brightly in the sky. I tried to capture it, but it’s a bit blurry:

Anyway, today is a new day. I’ve downloaded an app to my phone which helps you identify which stars/constellations you’re looking at & I’ll try again tonight.

UPDATE: Still couldn’t see the meteor shower but the app (Star Tracker) did at least show me where the Lyrid constellation was so I could be confident of looking in the right place. Rose and I had some fun using the app to try and find the names of the stars we could see.

Categories
Software

Garden Furniture Restoration: Part 1

Started restoring the outdoor table and chairs today. OK, so strictly speaking, I started to treat the wood last weekend, but I had to admit to myself more serious prep was required.

So roll on this weekend… And armed with an electric sander, the job begins in earnest. I’ve not used an electric sander before. It made my hands feel a bit strange after using it for a while. Here’s the table so far:

I managed to do half a chair as well before needing to give my hands a break. Quite pleased with result so far. Plenty more to do as I don’t feel I can make shortcuts now. All the old stain will have to be removed. Part 2 tomorrow if the weather holds.

Categories
Software

If it ain’t broke…

The sun has been shining in the UK! I know, I’m surprised too. Anyway, because of that, I’ve missed my glasses with transition lenses which have been out of action since the right arm broke.

I set out to see it I could replace the arms with spares from an old pair, but having been mostly a contact lens wearer for the past decade, I didn’t have much to use. The best contender looked like my current day to day pair. So I set about a little test run.

Using a really old pair of glasses to see, I set about removing the right arm of my current pair. It came off easy enough, but the hinge was different so it was a non starter. I go to put it back together, and I can’t get the screw back in. OK…. Tweezers…. Nope. Nothing was working. Now I have 2 pairs of non functioning glasses. Great.

Annoyed with myself, I leave it be and decide to try again to glue the broken arm of the 1st pair back together. Are you managing to keep track so far?

I spend a good bit of time on the super glue and manage to get the broken arm to hold together and I then reassemble the glasses. It works, but I have my doubts it will take much stress before it breaks.

Back to the pair I wear all the time. Well, I try and try. Nothing. But I won’t be beaten. I get a safety pin and use the pin to align the holes between the frame and the arm, take out the pin. Place the screw lightly in the hole and use some pincers to push it in slightly. Bingo! It pops into the hole. I screw it tightly and then pinch it home when it seems it won’t go any further. Success!

So yes, if it ain’t broke… Don’t try and fix it. I spent a good part of the day on it. You’ve done well to read all of that. Now for a photo…..

Categories
Life in lockdown

Morning run

I got up at 6am for a morning run having fallen asleep in my running gear the evening before. (Rest assured that I did wake up, change and go to bed). To my surprise, the restrictions have encouraged many other people out on to the street for an early morning run.

I did my normal hill route, but then extended my trip to the local shop to get some bread. The increased number of people out and about meant a lot of running on the road to keep at a safe distance – and there is still traffic!

Getting the bread was a task and a half. In a small shop, staying 2m apart from people is not easy. At one point I got trapped in the corner as both exits were blocked by people looking at items or queuing. It was like a human form of the game ‘Rush Hour’.

I had to lean to place the bread on the counter as lines clearly marked how close I could get. Money had to be placed on the counter–no handing it to the cashier. Not being terribly tall meant I ended up sort of throwing it. The cashier (also not tall) ended up sort of throwing my change back at me. I pondered that this was a bit ridiculous, but decided not to say anything as people are just trying to be safe.

On the way home I noticed the gate to the woods is permanently tied open. I assume so lots of people don’t touch it. I took a photo (above). It made me realise how crazy things are.

Miles run: Not enough. Too much starting and stopping.

New tracks added to running playlist: Highway Star, Deep Purple

Categories
Life in lockdown

Little things

Yesterday, I felt a little down as I’m sure a lot of people do just now.

This morning, I received a postcard from a friend just to say ‘Hello’. It was unexpected and has brightened my day.

I have put it in a frame. Next time things feel a bit gloomy, I hope that it will remind me how lucky I am to have lovely people in my life.

Categories
Life in lockdown

The view from across the pond

Today was the first day of the UK living under strict limits of when we can leave our homes. It feels very unreal and cast a long shadow over what was a day of bright sunshine and blue skies.

It is hard to know how to approach the situation and I find myself darting between not thinking about it and clinging on tightly to what little bit of routine I can find. I have, however, pledged to make the most of our allowance to leave our homes once per day for exercise. So I am trying to look positively at an opportunity to up the mileage that I run every week.

Main road into Christchurch at 10pm

As expected, it was earily quiet, although some signs of life as people walked dogs. We all gave each other space as I passed.

Tonight’s run: 4 miles.

New song added to running playlist: Pompeii, Bastille.