Background
During my day job I spend much of my time implementing Microsoft IT software. My company has a dedicated onsite TAM (Technical account manager) tasked with guiding us through the Microsoft support organization whenever there are issues. The unfortunate part for him is that his job is to basically act as the on site Microsoft whipping boy.After a particularly brutal couple weeks of issues we decided to give him a break and throw him a little event to show our appreciation for all he does (and put a few of us on his good side in case he ever cracks and goes postal). His last name is Deeter so the first annual "Deeter Day" was born.
Having a pile of $3 Google AIY voice kits and pi zeros from the recent Microcenter pi day sale I built a gag compliment box for the event which when pressed would speak/play a random compliment directed at our guest of honor. In my head I pictured Stuart Smalley doing his daily affirmation from classic SNL so I labeled the box "Deeter's Daily Affirmations"
If you want to build something similar to either play random audio clips, songs or speak one of various statements here is how to build it:
Items needed:
- Raspberry Pi - 2/3/Zero/ZeroW
- If using a zero - 2x20 header needs to be soldered on
- Google AIY Kit to provide the button, speaker and amplifier board
If you don't have the Google AIY kit you can make it work with another form of audio out (bluetooth/headphone jack or I2S Amplifier board) you will also need a push button
Step 1 - Collect audio files or statements to convert into audio files
If you already have MP3 or WAV files you can skip to step 3. I couldn't find prerecorded compliments so decided to create my own audio files via text to speech.Googling around I found a starter list of compliments here
https://www.happier.com/blog/nice-things-to-say-100-compliments/
To add a bit of humor I found some Chuck Norris 'facts' and copy/paste and search and replace generated a list of personalized Deeter facts.
Some here http://codesqueeze.com/the-ultimate-top-25-chuck-norris-the-programmer-jokes/
Another source https://www.telegraph.co.uk/films/2016/04/19/the-20-best-chuck-norris-facts/
Compile all your statements/jokes/compliments into a single file (one statement per line.)
Step 2: Convert any text to Audio Files
The Pi has a few speech libraries info here but in quick testing the speech wasn't great on a zero so I decided to preprocess them all into spoken audio files on my PC using Powershell and the Windows SAPI componentsUse this powershell to convert to wav files:
Step 3: Setup your Pi/Google AIY voice board
Since I'm using the Google AIY audio board I downloaded the Google AIY Raspian image since it has integrated audio drivers.- Download the AIY image to an SD Card
- Connect your pi to a monitor, keyboard and mouse (make sure hdmi is connected before boot)
- Boot into the image - after a minute or two you should have a google desktop
- Connect to your network and note the assigned IP (you can hover over the wireless icon)
- To make the following steps easier Enable VNC under Preferences ->Raspberry Pi Configuration->Interfaces and EnablingVNC.
- Set a fixed resolution to use via VNC under the System tab (1280 x 720 works well)
- If using MP3 files - install mpg123 (the image has integrated wav file support) sudo apt-get install mpg123
- I used Node-red to run the project so make sure to upgrade the included node-red by opening the console and running: update-nodejs-and-nodered Note: Don't update any other components as I had something break the audio driver.
- Also configure Node-red to run as a service. Reboot when complete with sudo reboot sudo systemctl enable nodered.service
Step 4: Copy audio files to the Pi
Get the files onto the Pi using your tool of choice. I find it easiest to use the file transfer built into VNC viewer. You can find info on it here: https://www.realvnc.com/en/connect/docs/file-transfer.htmlThe node-red flow you will import is configured to look for them under Documents\Audio but you can place them anywhere as long as you edit the code.
Step 5: Create a Node-Red flow to play a file/compliment upon press of the Google AIY Kit button
- Fire up node-red. On a different system connect to the webpage it hosts (http://IPAddress:1880). You will be presented with the node red flow designer.
- In the upper right there is an icon with 3 lines (I will call the hamburger), select that and go to Manage Palette
- Select the install tab and install the nodes:
- node-red-contrib-fs
- node-red-dashboard
- Open the flow file found here and copy the entire contents to the clipboard: https://github.com/lawrence-jeff/PiComplimentGenerator
- Open the Hamburger -> Select Import from Clipboard. Paste in the flow code.
Step 6: Enjoy
The simple usage is to just use the integrated button and get a random file, you can also go to the webpage on the device (http://IPAddress:1880/ui) and select a compliment from the dropdown which will play it remotely.
The flow also supports attaching a USB keyboard and if you press a key it will look for a file containing the keycode of the pressed button.