Building a voice-controlled home sound system using Snips and Sonos, Part 1: setup and installation
In the first part of this post, we will walk you through the process of controlling your Sonos speaker system using the Snips Voice Platform. The process is easy and quick, and does not require a single line of code. Once set up, you will be able to play music from Spotify and TuneIn. Part 2 of this post will explain how to teach your assistant about your personal favorite artists and songs, and add your own custom playlists.
Because Snips runs entirely on the device, your data stays in the room, and no one, including Snips, can have access to it. Furthermore, because Snips trains voice assistants specifically for the intended use-case, rather than a generic one, the setup will be really good at detecting your favorite artist names, tracks, albums, radio stations, or whatever data you provide for training. Here is a live demonstration:
For this assistant, you will need the following:
- Any Sonos speaker, for instance the Sonos Play:1 ($199 at Sonos)
- A Raspberry Pi Model 3 ($35 on Adafruit)
- A USB microphone. We recommend using a microphone array, such as the ReSpeaker or the PlayStation Eye. For an in-depth review of microphone solutions for far-field audio capture, have a look at our Microphone Array Benchmark
- Optionally, a small jack-connected speaker for audio feedback, such as the JBL Go ($25 on Amazon)
- An SD card ($8 on Amazon)
- A Spotify Premium account, to access your personal playlists
For this tutorial, it is not required to have a screen — adding visual feedback will be the subject of another post.
In this step, you will install a fresh version of Raspbian, as well as the Snips platform tools.
Download the latest image of the Raspbian operating system from the official Raspberry Pi download page. Any version (Desktop or Lite) will work.
Next, burn the image onto a blank SD card. On a Mac, a popular option to do this is Etcher. On Windows, Win32 Disk Imager will do. For more options including Linux, see the official Raspberry Pi guide.
In order to gain access to the Pi from a computer, you will need to set it up for SSH. To do so, first make sure your SD card is still plugged to your computer and accessible. Then create an empty file named
ssh, and copy it to the boot volume of your SD card (on macOS, this is
/Volumes/boot; on Windows, it will show up in Explorer as a removable drive).
If your Raspberry Pi is connected via Ethernet, you may skip the next step. Otherwise, create a file named
wpa_supplicant.conf, in the same folder as the
ssh file you just created, and paste the following, replacing
<Your wifi network name> and
<Your wifi network passphrase> with the appropriate values:
ssid="<Your wifi network name>"
psk="<Your wifi network passphrase>"
You may now insert the SD card into your Raspberry Pi, and boot it. After a few seconds, you can establish an SSH connection to your Pi. By default, the hostname will be
raspberrypi.local. Username is
pi, password is
$ ssh email@example.com
You can change the hostname by running
sudo raspi-config. Throughout this tutorial, we will assume that the hostname remains
Once logged in to your Pi, you can install the Snips platform tools with the following commands:
(pi) $ sudo apt-get updatesudo bash -c 'echo "deb https://raspbian.snips.ai/$(lsb_release -cs) stable main" > /etc/apt/sources.list.d/snips.list'
(pi) $ sudo apt-get install -y dirmngr
(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 snips-watch snipsmanager
Your device is ready to run a voice assistant! Let’s create one!
Head over to the Snips Console, create an account if you don’t have one yet, and create a new assistant with your name of choice. We will call it “Sonos”. We will use Snips’ On-Device ASR, and select Raspberry as the platform, “Hey Snips” as the hotword, and English as the assistant language:
Next, add the music bundle. This is a packaged and pretrained set of intents related to music queries, such as playing a track from an artist, or setting the volume:
Once added, the assistant will start training. This will take a few seconds, after which you can try textual queries in the right side bar:
At this point, you may want to customize your assistant with more intents, or special slot values, such as your own playlists or artists. We won’t dig deeper into this here, but if you want to know more, including how to obtain your playlists and favorite music from your Spotify account and add them to your assistant, head to Part 2 of this post.
Once you are satisfied with the queries that you assistant is able to make, you will need to run the training of the custom ASR model, which is done by clicking the “Download Assistant” button:
Time now to run the assistant on your device!
On the Console, note the ID of your assistant. It can be found in the URL:
In order to get access to your Spotify playlists, you will need a refresh token. For that, head over to the Snips Spotify token generator:
Save the token for the next step.
On your computer, create a file named
Snipsfile, and paste the following, replacing
<SPOTIFY_TOKEN> with the ID and token you just obtained:
- url: https://github.com/snipsco/snips-skill-sonos
Copy the Snipsfile to your Pi using
$ scp <path/to/Snipsfile> firstname.lastname@example.org:/home/pi
From your Pi, run
sudo snipsmanager install to install the assistant:
$ ssh email@example.com
(pi) $ sudo snipsmanager install
(You will need your Snips credentials for this step, as the assistant will be downloaded from the Console)
You may now start the assistant using the
sudo snipsmanager run command:
(pi) $ sudo snipsmanager run
Alternatively, you can just reboot the device, and the assistant will start automatically as a
Try it with a voice command by starting with the wakeword “Hey Snips”:
Hey Snips, play me a song by the Beatles
You should hear a nice tune playing straight from your Sonos! The Music Player bundle from the console contains a bunch of popular artists and songs. To find out how to customize these lists to fit your personal taste and add your own playlists, see Part 2 of this post. To be notified about other cool assistants that you can build with Snips, follow us on Medium or join our Slack community.
If nothing happens when talking to your assistant, this might be an issue with the microphone, which may need a custom configuration in order to work. Check out our Microphone Setup Guide for help setting up custom microphones, such as the ReSpeaker.
You can furthermore inspect what happens on the Snips Platform using the Snips Watch tool previously installed:
(pi) $ snips-watch
...play me a song by the beatles
INFO :snips_asr : ASR captured: "
INFO :snips_dialogue::services: Dialogue manager publish Intent("
Finally, to inspect all log messages from the Snips Platform,
journalctl is your friend:
(pi) $ sudo journalctl -f
That’s it! We hope you like your voice-controlled Sonos. We’d love to hear your feedback and ideas on our Slack community, where you can also find more ideas of what you can create with Snips!
If you liked this article and want to support Snips, please share it :)
Follow us on Twitter.
If you want to work on AI + Privacy, check our jobs page!