Introduction: VoiceLantern - the Voice Controlled Lantern!
The miniDSP UMA-8 microphone array, with onboard direction detection, echo cancellation, and noise reduction, has a wide variety of applications. In this instructable we'll run through its use with IBM Watson’s Speech-to-Text service to control an LED lantern.
Why use the UMA-8?
Any voice controlled appliance requires a microphone to capture audio and one could say you could use a random 2 dollar microphone. This is fine if you are sitting at the computer, directly in front of the microphone, but for "far field", hands-free control a more sophisticated microphone is needed. The UMA-8 has:
- Beam-forming running across an array of 7 microphones to improve voice detection and eliminate extraneous noises.
- Echo cancellation and noise reduction to reduce the effects of non-voice sounds (like music playing) and noise (traffic, kitchen noises etc).
The UMA-8 is "plug and play" – you do not have to configure anything to make it work with RPi. If you wish, however, you can use the miniDSP plugin to tweak the processing parameters of the microphone array (recommended for advanced users only!)
Step 1: What You Need
What you need to HAVE
- 1 x Raspberry Pi 2 or 3 along with a USB power supply for your Pi
- 1 x Keyboard
- 1 x HDMI Display
- An internet connection
- 1 x Small LED Lantern (~ $10)
What you need to KNOW
- Some basic experience with the Raspberry Pi platform
- Some basic Bash skills (cd, ls, etc.)
- Basic Nano text editor skills (opening and saving)
- An eager mind, ready to learn how to make a voice controlled lantern!
Step 2: Connecting Everything Up
First up, let’s wire up our contraption! Take your Raspberry Pi and connect up the keyboard and HDMI display.
Now we need to take the lantern apart to reveal its power wires. As you can see, after removing the 4 screws on the battery-holding base, we gain access to the RED (5v) and BLUE (GND) wires. To turn the lantern on or off, all we need to do is send 5v down these wires!
We will be using a transistor send this voltage and turn the lantern on and off. Why not just connect the input of the lamp straight to the RPi, you ask? Well, this is because the RPi’s control pins (also called “GPIOs”) are unable to output the power we will need to illuminate the lantern. The transistor works in a similar way to a relay, like an electronic switch which passes current through it when a voltage is applied.
We will toggle the pin which is connected to the purple wire HIGH and LOW to control the transistor which will, in turn send the 5v down the line to the lantern. The transistor must be wired up to intersect the BLUE (GND) wire to work correctly.
Pay close attention to the diagrams and images below when wiring the lantern up.
We soldered female headers to the lantern’s wires to make it easier to connect this up. If you havem’t soldered before, have a look at this instructable which gives a good explanation.
Finally, you’ll need to plug in the power and the miniDSP UMA-8 USB Microphone Array, simply plug it into a USB port! That’s all there is to it as the UMA-8 is plug&play with RPi.
Step 3: Preparing the Pi
Before powering on the Pi, you’ll need to download Raspbian Stretch LITE from the Raspberry Pi Foundation. Ensure you get the LITE version which doesn’t include a desktop. Burn the downloaded image onto a micro-SD card. Plug the micro-SD card into the Pi and plug in the power. You will see your monitor or TV come up with the a login prompt.
To log in, use the default Raspberry Pi login details.
If you have an Ethernet (wired) internet connection available, you're all set. Otherwise, you’ll need to setup the Wifi. Follow this guide to configure the Wifi on your Pi.
Downloading and Installing NodeJS
First, install NodeJS using the package manager. Here's a handy guide which explains the current commands required. At the time of writing, these are the commands I used:
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -<br>sudo apt-get install -y nodejs
Next up, we need to install the application that NodeJS will run to allow our lantern to hear (via the UMA-8) and control the lamp (via the GPIO headers). First download the repository which contains the code: (get the <> by copying the URL of the zip file attached to this step)
Now, let’s install all of the extra bits and bobs this application requires to run:
Once the installation is complete, you’ll be ready to jump into IBM Watson.
Step 4: Configuring IBM Watson
Now that our lantern is all wired up, we can start working on the voice recognition! If you haven’t already, sign up for IBM BlueMix. Once you’re logged in, navigate to the BlueMix Services Dashboard.
Click the big “Create Watson service” button in the middle of the screen. See image 1.
Next, you’ll be presented with a catalogue of all the service IBM BlueMix has to offer. Let’s skip down to the “Watson” section in the sidebar. See image 2.
We now need to add the “Speech-to-Text” service. This will allow us to send a stream of speech audio to WATSON, and have it stream back text (converted from the incoming audio). See image 3.
To do this, click the tile (outlined in red above). Once the page has loaded, we can leave the default settings and choose the “Create” button in the bottom left corner. See image 4.
Lastly, we need to get the “Service credentials”. These details are used by our app will to connect to Watson. See image 5.
Click the “View credentials” button to expand the tile and then copy the lines which contain the “username” and “password” into a text document on your computer. We’ll need these later, so make sure that they’re clearly labelled as “WATSON Creds” or similar. See image 6.
Step 5: Adding Our WATSON Credentials Into the App
Now that we have finished the process of retrieving our Watson credentials, we need to let our lantern know how to login to Watson. Jump back in front of your Pi and ensure you’re in the voice-light directory which contains the app. We need to edit the “settings.js” file to include these details. Open the file with this command:
Now, replace each of the settings outlined in this file, with the settings you recorded earlier.
Step 6: Running Our Voice Controlled Lantern
Once your app is configured, it’s ready to run!
To turn on the lantern, say “Let there be light!”, to turn it off say “Let there be darkness!”. Keep an eye on the Raspberry Pi’s console output to see how WATSON is interpreting what you’re saying.
sudo node app.js
We have a be nice policy.
Please be positive and constructive.