Darth Vader Voice Assistant

by Luddo15 in Circuits > Raspberry Pi

986 Views, 4 Favorites, 0 Comments

Darth Vader Voice Assistant

IMG_20211229_120338_auto_x2_light_ai.jpg

I have been a Star Wars fan for as long as I can remember. Lately, I wanted a voice assistant, and I had a Raspberry Pi laying around. My two ideas combined into this, a Darth Vader Voice Assistant.

Supplies

saikyo_auto_x2_auto_x2_light_ai.jpg

You will need:

Raspberry Pi 3 or 4

USB Speaker

Microphone

Micro SD card with 16 GB+ space

Micro USB power switch

Darth Vader 3DLightFX Wall Deco

Power Supply for Pi 3 or 4

USB Keyboard or SSH

Monitor or TV w/ HDMI cable for Pi 3 or Micro HDMI for Pi 4 if you are using a keyboard

Glue

Getting a Voice Assistant

We could make this spew random quotes, but where's the fun in that? Using a voice assistant, we can command Lord Vader to do our bidding. '

For the voice assistant, I will use Mycroft, and I will set up a custom wake word later on. Let's go!

To start, we need to have a Mycroft account. Go to home.mycroft.ai and set up an account.

Now that we have our account, let's get Mycroft running. Go into the Picroft(the version of Mycroft for RPi) Docs and download the image. Flash it using the software of your choice onto the SD card. Once that is done, eject the SD card and plug it into your RPi, along with the speaker, microphone and keyboard

Now go through the Mycroft setup. Once you have finished connecting the mic and speaker, Mycroft will complain it is not paired. Now for me, the speaker didn't connect, so I skipped over the speaker setup and after going to the command line, did the following:

sudo nano /usr/share/alsa/alsa.conf
Replace defaults.ctl.card 0 & defaults.pcm.card 0 with:
defaults.ctl.card 1
defaults.pcm.card 1

pactl list sinks short
Find USB Soundcard

pactl set-default-sink whatever-the-number-from-the-last-step-was

sudo nano /etc/mycroft/mycroft.conf
place "play_wav_cmdline": "aplay %1",& "play_mp3_cmdline": "mpg123 %1", in place of the most similar thing

sudo reboot

Go to the Mycroft Account you just setup and pair the new device using the code it now says. Try telling Mycroft to tell you the time or similar to test that it works. Once you're done, proceed to the next step to setup the wake word.

Wake Word

Right now, the wake word is just the default "Hey Mycroft". Now let's make the wake word Lord Vader so we can talk like this: Lord Vader, check my email. We have two options, each with their pros and cons:

Precise:

The default listener. It is more accurate, but harder to set up. It works with accents better than the next option, which is:

PocketSphinx:

Another listener. Less accurate, easier to set up. It does not work well with accents


I'll be using PocketSphinx, you can go to the docs to learn how to set up Precise.


First thing is to find the phonemes for Lord Vader. To save you time, they are as follows:

L AO R D . V EY D ER .

Note: There are some spaces but it is hard to tell them in Instructables.


Next, we need to set up the Mycroft.conf user file to use the wake word.

Type in your shell:

mycroft-config edit user

Now replace whatever is in there with:

{
  "max_allowed_core_version": 21.2,
  "listener": {
    "wake_word": "lord vader"
  },
  "hotwords": {
    "lord vader": {
      "module": "pocketsphinx",
      "phonemes": "L AO R D . V EY D ER .",
      "threshold": 1e-70
    }
  }
}

Reboot and you should find Mycroft no longer responds to "hey Mycroft". If it does, tell it to set the listener to PocketSphinx. Then, you can say "Lord Vader" and it will respond. You might have to say the wake word again to make it read it correctly.

Shutdown Methods

Screenshot 2021-12-29 11.51.25 AM.png

Right now, Mycroft cannot shutdown without you going into a terminal. Let's fix that. Run the following commands to get the BlueDot package, which we will use a shutdown button:

WARNING: THE BLUEDOT METHOD ONLY WORKS IF YOU HAVE AN ANDROID DEVICE!

sudo apt-get upgrade && sudo apt-get update 
sudo apt-get install python3-pip
sudo pip3 install bluedot

This downloads BlueDot, which can connect to an Android device through Bluetooth. Go to your Android device and install BlueDot from the Google Play Store. Once that is done, run the following command:

sudo bluetoothctl

Then run the following:

agent on
scan on
discoverable on
pairable on

Then pair your phone with your Pi through Bluetooth. Then, create a python script called bdshutdown.py with the following inside:

import os
import time
from bluedot import BlueDot

BlueDot.wait_for_press()
os.system("aplay /home/pi/march.wav")
time.sleep(4)
os.system("sudo halt")

To run this script, you first need to connect your device to the Pi through Bluetooth. Then go into BlueDot and click on the name of your Pi. You may notice that it asks for a sound file that isn't in that directory. The sound file can be downloaded at the end of this step, and you can transfer it to your Pi. We are also going to setup a timed shutdown, just in case, soadd the following to a python file called timed shutdown.py:

import os
import time

time.sleep(3600)
os.system("aplay /home/pi/march.wav")
time.sleep(4)
os.system("sudo halt")

This script will just shutdown your Pi after an hour. Now run the following command:

sudo crontab -e

Then add the following in the file:

@reboot sudo python3 bdshutdown.py
@reboot sudo python3 timedshutdown.py

Now save your changes, and go on to the next step.

Downloads

Customization

tumblr_oopqeaVv5T1sl21koo1_500.gif

Since Mycroft has bits here and there that you can change, why don't we change them?

First, Mycroft has this sound that plays when it starts listening. Why don't we replace that with a real Darth Vader line? This is from 1980's The Empire Strikes Back. This will make him say "What is thy bidding my master" instead of making a ringtone-esque noise when you say the wake word to tell you it's listening. Copy the start_listening.wav file from this step into~/mycroft-core/mycroft/res/snd and overwrite the other file with the same name. That's all I did for customization, you could do more if you wanted. Now would also be a good time to download skills. Go the the Skills Marketplace and find some skills you want, then go into the docs and find out how to download them.

Putting It All Into the Helmet

IMG_20211229_120319_auto_x2_light_ai.jpg

Now we need to put Mycroft inside the wall mount. I first opened it up, then removed the LED circuit, then the batteries to make space. I then glued the Pi's case onto the plate that detaches, then removed the plastic plates on top of the grills. The bottom one didn't stay on, and I placed the speaker in there and then glued it in there. I then attached the micro-usb power switch where the LED switch used to be. I then attached the microphone on the outside, and ran the wires through the side. I then attached the power supply, and gave it a test.