How to Make a Custom Wake Word for Alexa Devices
by mogrinz in Circuits > Raspberry Pi
5138 Views, 40 Favorites, 0 Comments
How to Make a Custom Wake Word for Alexa Devices
Finally! PERSONAL WAKE WORDS and wake phrases for your Alexa device. Bored with the default choices Amazon gives you? Now you can create your own custom wake words for almost every Alexa product.
Almost every Alexa device has a button that can be pressed instead of speaking the default wake word. So we're going to build an off-line wake-word detection circuit using a Raspberry Pi and the free Porcupine Wake Word detection engine. When the Pi hears the wake word, our circuit will trigger a solenoid that will "push" the button on the Alexa device. Once it "wakes up", your Alexa will listen to and process the rest of your request.
Supplies
Shopping List:
- Raspberry Pi Zero 2W (https://www.sparkfun.com/products/18713)
- You’ll also need an SD (8 to 32mb) card for the Pi OS, and a power supply for the Pi
- Mini 5v solenoid (such as https://www.sparkfun.com/products/11015)
- Small USB microphone (https://www.sparkfun.com/products/18488)
- Micro-USB adaptor to connect microphone (I like this one: https://www.amazon.com/dp/B01C6032G0)
- TIP120 Power Transistor (https://www.adafruit.com/product/976)
- 1N4001 Diode (https://www.adafruit.com/product/755)
- A 18V/2A power supply for the relay (such as https://www.amazon.com/Adapter-Regulated-Switching-Interchangeable-Equipment/dp/B0BHWPFDXV)
You'll also need a breadboard and some wires to connect everything together. If you use the solenoid above, it comes with a JST PH female connector. You may want to purchase a JST PH male connector (https://www.amazon.com/Connector-SIM-NAT-connectors-Inductrix/dp/B08SC3F658) to hook it up to the circuit, or you can just cut the wires if you are making a soldered version (I'm using a solderless breadboard in my example)
Access to a 3D printer to make solenoid the holder for your particular Alexa device is also necessary. Many libraries and maker spaces have 3D printers for public use, and there are also online services that will print and mail you a file that you upload.
Set Up the Pi O/S
There are many great Instructables already out there for setting up a Pi, so I'll cover this step rather briefly.
Visit https://www.raspberrypi.com/software/ and install the Raspberry Pi imaging program for your particular operating system. I'm using Windows, so that's the version I'm using. I'm also going to be using some other free Windows programs in the following steps, but there are free equivalents for other platforms.
Once you've downloaded the Pi OS imager, run the program. Select the Raspberry Pi device you are using. In this example. I am using a Pi Zero 2W. Next, select the Operating System to install. Since this device is going to run "headless" (without a monitor) there's no reason to choose one with a desktop environment. First, I clicked "Raspberry Pi (other)" and on the next screen I selected "Raspberry Pi OS (Legacy) Lite" because the description notes there is "no desktop environment".
Now, insert your SD card into your computer, and choose it under the "Storage" dropdown. But we're not ready to create our OS image yet! When you click Next, you will be asked if you want to "Use OS customisation?". Click "Edit Settings". This will let us set some important options for how the Pi is configured.
On the General tab of the next screen, you can set the default login account for your Pi. In this example I am using "mike" as my Username, and "password" as the password (Shhhh.. don't tell anyone). I've also set up the name and password for my local network so the Pi should automatically connect to it wirelessly.
Now click on the Services tab. It's very important that you check the box for "Enable SSH" and make sure "User password authentication" is selected. This will allow us to connect to the Pi remotely later on and upload files to it.
You can click Save on this screen and proceed with writing the OS to your SD card. This will take about 2 minutes and will completely destroy any existing files on that card - so make sure you don't have anything on it that you want to save!
Boot Up the Pi (Complete WiFi Setup)
There's always a wrinkle... Technically, you should be able to plug in the Pi without a monitor and keyboard and it should connect to your network automatically (that's why we entered the network name and password in the previous step). If that had happened, you'd need to find out what the IP address of your Pi is on your local network and could progress to Step 3. But, after some checks I realized that the Pi was not automatically connecting. Maybe the OS image we selected was to blame. But in any case, I had to hook my Pi up to a monitor and USB keyboard so that I could sign into it directly and complete the WiFi setup.
The Pi will prompt you for a Username and password. Use the information you provided in the previous step. Once you are signed in, type the command:
sudo raspi-config
When the Pi Configuration tool loads, select Option 1 for "Configure System Settings" (and press Enter). On the next screen, select the first option for "Wireless LAN" (and press Enter). You will then be prompted to enter your SSID and password (if any). As soon as you complete this step, your Pi should join your wireless network.
To confirm you have a network connection, exit the setup utility and type
ifconfig
If everything is correct, you should see a section in the output for "wlan0:" and in the line just below, the IP address of your Pi on the local network (it will probably start with 192.168.1. and a unique number at the end). Write this number down as we're going to need it again shortly.
While we're connected, we might as well set up some other software we need on the Pi. Our program for custom wake word detection is written in Python, and that's already installed. But we need to install two other libraries using an app called "pip" . To install pip, type:
sudo apt-get install python3-pip -y
Once pip is installed, we can install our two other packages.
The first is called "pvrecorder" and it will allow our Pi to use our USB microphone. To install it, type:
pip3 install pvrecorder
The other package is for the offline wake-word voice detection capability on the Pi. It's called the "Porcupine Wake Word Engine" and you can visit their homepage if you are interested in learning more about it. To install it, type:
pip3 install pvporcupine
At this point, since the Pi is on our network we'll be able to connect to it remotely in the future. You can disconnect the monitor and keyboard for now (but leave the Pi powered on)
Creating Your Wake Word
Let's step away from the Pi for a second and back to your regular PC. Let's create the custom wake word we are going to be using for this example.
Open a browser and visit https://console.picovoice.ai/
Create a free account and login. This site will allow us to create a custom wake word file to use with pvporcupine. Under the free account plan, you are allowed to create up to 3 wake words (or wake phrases) per month.
Once you are signed in, you will see an Access Key on your homepage. Paste this someplace temporary because we're going to need it later. This key is just used to ensure you haven't exceeded the usage limits on the free account.
Now, click the Create Wake Word button on this page.
Enter the custom wake word or wake phrase you would like to use. In this example, I am using the ever-popular "Jarvis".
Tip: PicoVoice knows a lot of words, but it might not know something unusual or made-up. For example, for I wanted to use "Theopolis" as a wake word for a project, and that wasn't a word in it's dictionary. But I was able to spell it phonetically ("The-Opolis") - "Opolis" being the greek word for a city - and then PicoVoice accepted it.
If you have a USB mic (or webcam with a Mic) connected to your computer, you can test PicoVoice now by clicking the microphone in the middle of the screen. It's fun to keep saying your wake word and watch it get detected correctly. If you want to see how accurate Picovoice it, you can try saying words close to your wake word and see if you can get it to make a mistake. I've found it to be amazingly accurate.
When you're done playing around, click the Train button. Download the file for the platform "Raspberry Pi" to your computer. It will have a name that looks something like "Jarvis_en_raspberry-pi_v3_0_0.ppn".
Plug in the Microphone
This is as good a time as any to plug in your USB microphone (before powering up the Pi).
Don't forget you'll need the adaptor to convert the Pi's micro-USB ports into a full-sized USB connector. By the way, it doesn't matter which port (of the two) on the Pi has the power connector, and which has the microphone.
If you forget this step and plug in the mic later on, that's OK. You might need to reboot the Pi though before the mic is recognized. You can always reboot the Pi by connecting with Putty and typing the command
sudo reboot
Copy Files to the Pi
Download the CustomWake.py program and open it in a plain text editor (not a word processor). In your local copy, enter the access_key value (highlighted yellow in the sample image) from the PicoVoice console. Set the keyword_paths variable (highlighted purple in the sample image) to the name of the .ppn file you downloaded in the previous step. Note the pink highlighted text in the sample image. This is a "sensitivity" value pvporcupine uses when listening for your wake word. I'm using 0.6 in my code and I suggest you keep that value to start. You can always go back and play with other values later.
Now we've got to get CustomWake.py and your .ppn file copied onto your Pi. We're going to transfer them over using a program called "WinSCP". You can download it from https://winscp.net/eng/index.php
Create a new profile (I've called mine "CustomWakeWord") and set up the IP address for your Pi that you copied down in Step 2. You can also enter your Pi Username and Password. Then press the Login button. If all of your information is correct, you'll see a screen with the files from your local computer on the left, and the home directory for your Pi account on the right.
Navigate to where you have stored your downloaded .ppn and CustomWake.py files and drag them over to the right pane to copy them onto your Pi. When you're finished, you can close the WinSCP program.
Downloads
Listen to My Voice!
We've far enough along now that we can actually test our custom wake word with the Pi.
We're going to remotely connect to the Pi using a terminal program called Putty, which you can download for free at https://www.puttygen.com/.
Create a profile for your Pi using the IP address from Step 2, and then click the Open button. A connection window will open, and you can enter your Username and Password to sign in.
Enter the Linux command:
ls
to view the files in your home directory. If you've copied the files over correctly, you should see:
CustomWake.py
Jarvis_en_raspberry-pi_v3_0_0.ppn
Now run the CustomWake.py script by typing:
python CustomWake.py
The program should run, and almost immediately display the line:
Listening...
Say your wake word ("Jarvis!") in earshot of your microphone, and you should see the message:
I heard the wake word!
AWESOME!
If you receive an error message when you try and execute the program, retrace the previous steps and make sure you didn't miss anything. There could also be a chance your microphone wasn't recognized and you need to reboot the Pi. You can press Ctrl-C to halt the program and then reboot the Pi as shown in Step 4.
Start Me Up
When you're tired of testing the wake word, press Ctrl-C to stop the program. This is all fantastic, but we don't want to have to manually run the program every time our Pi is powered on. We want to turn it on and have it automatically start listening for the wake word. So let's set that up next.
Type the command:
sudo nano .bashrc
This will launch the nano text editor program on your Pi. Move all the way to the end of the file, and add this line:
python3 /home/mike/CustomWake.py
(of course, use your Username instead of mine :))
Then press Ctrl-X to exit, respond Y to "Save Changes", and press enter to use the name .bashrc
We also need to configure the Pi to auto-logon when powered up.
Type the command
sudo raspi-config
This once again takes us to the Pi's configuration menu. Select Option 1 (System Options), then Option 5 (Boot/Auto Login), and finally Option 2 ("Text console, automatically logged in as 'you' user)
Now your Pi will automatically sign in as you and start the CustomWake.py script whenever it's powered on.
You're probably going to leave it on all the time (just like you do with Alexa, right?) - but this way if the power goes out you won't have to do anything special when it comes back on.
Build the Circuit
Now that our Pi can listen to our wake word, we need it to take action in the physical world. When the Pi hears the wake word, we want it to trigger a solenoid that will "Push" the button on an Alexa device. A solenoid is an electromagnetic device that converts electricity into physical movement. When current is applied, a small coil of wire becomes a miniature magnet, and this "pulls" a metal plunger forcing it to push (or sometimes pull) in one direction.
Please make sure to power off the Pi while you are building and connecting the circuit.
The circuit we are using here is very similar to the one user jts3k created in this Instructable. However, his version used an Arduino and his solenoid was powered by two external 9v batteries. Two 9v batteries aren't going to be strong enough for our needs. I'm using an external 18v power supply (see shopping list) to drive the solenoid. Don't be alarmed that we're using this to drive a 5v solenoid. It's only for .3 seconds but when it activates all this current rushes in to charge the electromagnet, so we need something robust. And your Pi is protected too, thanks to the diode in the circuit. I've found that different versions of Alexa require a different amount of force to press the button, so you might be able to get away with a 12v power supply or even less. If you have a spare power supply around, try it out and you can always move to more voltage later.
The CustomWake.py script as written already sends 5v down GPIO pin 23 on the Pi when it hears the wake word. This will basically "close the switch" (the transistor in the circuit) and send the 18v to the solenoid. You can use a different pin on the Pi, but if you choose to do so, make sure you update the code appropriately. Remember: The physical pin # on the Pi is not the same as the GPIO pin # used in your code. See the attached diagram that maps physical pins to GPIO pins.
Once you've connected built the circuit and connected it to your Pi, power up the Pi and wait a minute or so for it to boot. You should be able to speak your wake work and see the solenoid fire!
Hold Me (AKA the 3D Print)
You'll need to print the 3D holder that will position the solenoid in the right spot for your particular Alexa model. This page on Amazon will help you identify what model Alexa you have and therefore which file to use.
My designs work, but they are pretty basic. If you're a creative person skilled with CAD, I've also included STEP files with this Instructable to use as starting point for designing your own solenoid holder.
If your solenoid is still connected to your circuit from the previous step, unplug it now. You'll need to feed the connector cable through the back of the holder. Push the solenoid tightly into the holder and give the plunger a couple of taps to make sure it moves freely. If it doesn't, you might need to carefully trim away a little plastic from your print.
Once the solenoid is installed, carefully slide/place your Alexa device in the holder. Make sure that the solenoid's plunger is positioned over the "action" button on your device (the small circle symbol). Reconnect the solenoid to your circuit. You can also plug in your Alexa device at this time.
You've Done It!
When you speak your wake word (or wake phrase), the Pi will now fire the solenoid which will press the "action" button on your Alexa. The blue "listening" light should turn on. At this point, your Alexa's built-in microphone will take over and listen to the rest of your request and reply. Amazing!
If the solenoid is triggered but the blue light does not come one, it could be because of 2 problems.
First, the solenoid might not be directly over the button. This is easy to test. Gently push down on the plunger with your hand and see if it triggers the button press. If not, rotate your Alexa until the button is in the correct location.
Second, the solenoid might not be pressing down with enough force. If this is the case, try a power supply with a slightly higher voltage and amp rating. I would not recommend over 18v 2a for this particular solenoid.
Final Suggestions
If you don't like the "tapping" sound the solenoid makes when it impacts the device, you can try cutting a small piece of self-adhesive velvet and placing it on top of the button to reduce the sound.
Alexa is capable of speaking in a few different voices. You can say "Alexa, Change your voice" to change it. Try and pick a voice that is appropriate to the wake word or phrase that you have chosen. For example, for my personal "Jarvis", I have changed Alexa's voice to a male British accent.