Build your own voice-powered weather assistant with Snips and a Raspberry Pi 3 in just one hour

The first brick of your fully private alternative to Amazon’s Echo!

You’ve probably heard about voice assistants like Amazon Echo and Google Home. Maybe, you’ve also been curious about the idea of controlling your home via voice. Yet, your home is also your most intimate space, and you have been thinking twice before installing an always-listening, cloud-connected device streaming your data to some distant server… Fear no more, we have something for you! 😜

At Snips, we are challenging the idea that adding Artificial Intelligence to our everyday life means giving up Privacy. This belief is why we recently launched the Snips Voice Platform, a 100% on-device alternative to Amazon Alexa, allowing anyone to easily add powerful voice assistants to connected devices without compromising their Privacy.

In this post, I am going to walk you through 3 simple steps to set up your own Private by Design alternative to Amazon’s Echo.

Within an hour, you should have a functional voice assistant in front of you, responding to weather queries. As easy as 1, 2, 3…

  1. Build your own assistant.
  2. Set up Snips on your Raspberry Pi 3.
  3. Handle weather requests.

Requirements

What you’ll need: a Raspberry PI3, a mic, and a speaker.
  1. If you’re not equipped with a Raspberry Pi 3 yet, you should probably consider the starter kit (49.99$ on Amazon.com).
  2. In case you don’t have a mic at home, here’s a decent one to get started (16.99$ on Amazon.com). You may consider getting a mic array instead if you want your assistant to hear you from afar.
  3. Any USB or 3.5mm jack speaker would do.

If you have this material ready, let’s move forward!

Step 1. Build your own assistant

Objective: in this first step, we are going to build a component that is able to extract an explicit intent, data and location from a weather query expressed in natural language.

Go to www.console.snips.ai, and sign up.

You are now on Snips’ console. Here, you’ll be able to teach your assistant to understand any command you’d like it to handle. For now, we’re interested in queries related to weather. Let’s create an assistant, by clicking on the top-left menu, and name it WeatherAssistant.

Create a new assistant

For the other parameters of the assistant, we can keep the default values: we’re targeting a Raspberry Pi 3, in English, using Snips’ Automatic Speech Recognition (ASR) solution that will run on your device.

You can now click back onSave and Continue. You will then be taken to the Bundle store. Bundles are groups of intents meant to cover a given use case.

Let’s add the Weather bundle published by Snips to my cart, and let’s install it to my assistant (bottom-right button):

Add and install the Weather bundle published by Snips in the Bundle Store

You can now see the bundles installed in your assistant, and the intent contained in each bundle:

You can see that the following 4 intents are now supported by your assistant:

  • searchWeatherForecast: for general weather-related questions
  • searchWeatherForecastCondition: for questions specific to weather conditions
  • searchWeatherForecastTemperature: for questions specific to the temperature.
  • searchWeatherForecastItem: for questions regarding the need to wear a given accessory (a scarf, raincoat, sunglasses, etc)

To finish this step, simply train your model:

Now, test it in the right-hand console for validation.

🎯 Validate step 1:

Type “How’s the weather tomorrow in Paris?” in the right-hand console. The intent searchWeatherForecast should be detected, associated with the corresponding time, and location. Here you go!

Step 2. Set up Snips on your Raspberry Pi 3

Objective: get Snips up and running on your Raspberry Pi 3. We want it to react when you call it, “Hey Snips”, and we want it to understand when you ask it out loud for the weather!

The first thing you’ll need to do is install Raspbian StretchLite on your SD card. See here for instructions.

Then, you need to further configure your Raspberry Pi 3 to access internet, in order to install the Snips Platform, and to query weather forecasts. The last thing will be to configure sound, so your Raspberry Pi can listen and respond to you.

Let’s take it step after step. 😉

Connecting your Raspberry Pi 3 to internet

If your Raspberry Pi 3 is plugged by Ethernet, then there is nothing left to do. If you’re aiming to use Wifi, then insert the SD card in your computer and add the following file wpa_supplicant.conf at the root of the boot volume of the SD card (do not forget to update the ssid and psk keys):

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="Your wifi network name"
psk="Your wifi network password"
}

Enable ssh

To enable ssh on your Raspberry Pi 3, also add an empty file ssh at the root of the boot volume on your SD card. Insert the SD card into the Raspberry Pi. It will boot in about 20 seconds. If you run into issues, check this doc.

You can now access your Raspberry Pi 3 from your computer using:

$ ssh pi@raspberrypi.local

Note that if you have several Raspberry Pi’s on the same network, we recommend you to change their hostname or connect to them using their IP.

Install Snips

Connect to your Raspberry Pi 3, as indicated above. Once on it, simply run the following commands:

(pi) $ sudo apt-get update
(pi) $ sudo apt-get install -y dirmngr
(pi) $ sudo bash -c 'echo "deb https://raspbian.snips.ai/$(lsb_release -cs) stable main" > /etc/apt/sources.list.d/snips.list'
(pi) $ sudo apt-key adv --keyserver pgp.mit.edu --recv-keys D4F50CDCA10A2849
(pi) $ sudo apt-get update
(pi) $ sudo apt-get install -y snips-platform-voice
(pi) $ sudo apt-get install -y snips-watch

These command will install Snips and its dependencies, as well as a few handy utils.

Setup sound input and output

From your Raspberry Pi 3, run the following command:

(pi) $ aplay -l

That should trigger the following type of response:

**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
Subdevices: 8/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
Subdevices: 1/1
Subdevice #0: subdevice #0

From the output of this command, we learn that the audio output is linked to card 0, and device 0 (the bits in bold). This will be noted hw:0,0. Indices may very well be different in your setup, which is why we are going through these steps.

Similarly, to know the card and device index of the audio input:

(pi) $ arecord -l

Which triggers:

**** List of CAPTURE Hardware Devices ****
card 1: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0

The audio input is linked to card 1, and device 0 (in bold, again). This will be noted hw:1,0.

With this information, we can update the /etc/asound.conf file accordingly:

(pi) $ nano /etc/asound.conf
pcm.!default {
type asym
playback.pcm {
type plug
slave.pcm "hw:0,0"
}
capture.pcm {
type plug
slave.pcm "hw:1,0"
}
}

Install your assistant

Now, the last step before validating that Snips is up and running is to install the assistant you’ve prepared in Step 1. From your computer, unzip and copy the assistant folder that you downloaded from the web console:

$ scp -r <PATH_TO_ASSISTANT_FOLDER> pi@raspberrypi.local:/home/pi/assistant

Then, from your Raspberry pi 3:

(pi) $ sudo mv /home/pi/assistant /usr/share/snips/assistant
(pi) $
sudo systemctl restart snips*

🎯 Validate step 2:

We’re now ready to validate that Snips is up and running on your Raspberry Pi 3. From your Raspberry Pi 3, run

(pi) $ snips-watch -v

This will show you concisely what’s going on. Once everything is done loading, wake up the assistant saying “Hey Snips”. This should trigger a reaction. It is called a hotword, it simply communicates to your assistant that you are going to ask it something.

You can now say “How’s the weather tomorrow in Paris?”. You should see from the logs that the SearchWeatherForecast intent has been triggered.

Let me take a second to insist on the fact that everything that just happened, happened on your device: the hotword detection, the voice recognition, and the natural language understanding. If you want to make sure this is true, turn your wifi off and try again! 😉

They only step left now is to tell your assistant how to respond to such queries.

Step 3. Handle weather requests

Objective: here, we simply want our assistant to respond when we ask it about the weather.

This one will be easy. Sign up into Open Weather Map. We are going to rely on their API to get information about the weather. Once you’re in, go to the API keys tab, and copy your key. Node that you may need to wait for the confirmation email before you can use the key. It can take a few minutes to be activated.

Now, download the following script, and replace the WEATHER_API_KEY and CITY_NAME parameters:

Copy it onto your Raspberry Pi 3:

$ scp PATH_TO_HANDLER pi@raspberrypi.local:.

And run your handler in a third tab:

(pi) $ sudo apt-get install -y python-pip
(pi) $ pip install paho-mqtt
(pi) $ pip install requests
(pi) $ python handler.py

🎯 Validate step 3:

We can now reproduce what we had done to validate step 2: “Hey Snips”, and then “How’s the weather today in Paris?”. Your assistant should now be responding to you!

Anything went wrong?

If anything went wrong, you can check our official documentation for more details. You can also ping us directly on our Discord, we’d love to help!

What’s next?

All the code you’ve been using is free for non-commecial use. Feel free to tinker around, add new intents to your assistant on www.console.snips.ai, and explore new hacks! In particular, if you’re into home automation, you’ll probably like what Snips and the Home-Assistant platform can do together!

On our side, we have some new features coming up soon that we think you’ll like: end-to-end support of French, Spanish, Italian, and German, custom hotwords, and support for other platforms than Raspberry Pi 3! We are also working on giving our assistant a voice that sounds nicer.

In the meantime, we’d love to hear from you through our Discord community. Don’t hesitate to ping us there if you have feedback! 🤖😜✨

If you enjoyed this article, it would really help if you hit recommend below :)

Follow us on Twitter @jodureau and @snips

If you want to work on AI + Privacy, check our jobs page!