
Why rent a voice assistant from Big Tech when you can build your own? With a Raspberry Pi, a microphone, and some open-source AI, you can create a custom voice-controlled home assistant that flips lights, runs appliances, and responds to commands — all without sending your voice data to the cloud.
This project is perfect for tech hobbyists who want hands-on experience with speech recognition, home automation, and a little bit of AI magic.
What You’ll Need
Grab the following before you start:
- Raspberry Pi 4 (4GB or 8GB) — the extra RAM helps with speech processing
- MicroSD card (32GB+) with Raspberry Pi OS (64-bit)
- USB microphone (or a ReSpeaker 2-Mic HAT for better far-field audio)
- USB or 3.5mm speaker
- Relay module (2 or 4 channel) to control appliances
- Smart bulbs (Philips Hue, Tuya, or any Wi-Fi bulb) — optional if using relays
- Jumper wires and a breadboard
- Official Raspberry Pi power supply
- Wi-Fi connection
- ⚠️ (If switching mains appliances) — use a proper relay board with optocouplers and take serious safety precautions with high voltage wiring
Step 1: Set Up the Raspberry Pi
Flash Raspberry Pi OS (64-bit) with Raspberry Pi Imager, boot up, connect to Wi-Fi, and update:
sudo apt update && sudo apt full-upgrade -y
sudo apt install python3-pip portaudio19-dev python3-pyaudio -y
Plug in your microphone and speaker, then test them:
arecord -l # list microphones
aplay -l # list speakers
arecord -d 5 test.wav && aplay test.wav
Step 2: Install Speech Recognition
For fully offline speech recognition, use Vosk — it’s fast, accurate, and private.
pip3 install vosk sounddevice
Download a small English model from the Vosk website and unzip it into your project folder (~/voice-assistant/model).
Prefer cloud accuracy? You can swap in Google’s SpeechRecognition library instead, but Vosk keeps everything local.
Step 3: Wire Up the Relay Module
Connect the relay board to the Pi’s GPIO pins:
- VCC → 5V
- GND → GND
- IN1 → GPIO 17
- IN2 → GPIO 27
Then connect your lamp or appliance through the relay’s normally-open terminals. If you’re not comfortable with mains wiring, stick to low-voltage devices or smart bulbs controlled over Wi-Fi.
Test the relay with a quick Python snippet:
import RPi.GPIO as GPIO, time
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
GPIO.output(17, GPIO.HIGH); time.sleep(1)
GPIO.output(17, GPIO.LOW)
Step 4: Write the Voice Assistant Script
Create assistant.py that listens continuously, transcribes speech, and acts on commands:
import queue, sounddevice as sd, vosk, json
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
model = vosk.Model("model")
q = queue.Queue()
def callback(indata, frames, t, status):
q.put(bytes(indata))
def handle(cmd):
if "light on" in cmd:
GPIO.output(17, GPIO.HIGH)
print("💡 Light ON")
elif "light off" in cmd:
GPIO.output(17, GPIO.LOW)
print("💡 Light OFF")
with sd.RawInputStream(samplerate=16000, blocksize=8000, dtype='int16',
channels=1, callback=callback):
rec = vosk.KaldiRecognizer(model, 16000)
while True:
data = q.get()
if rec.AcceptWaveform(data):
text = json.loads(rec.Result()).get("text", "")
if text:
print("Heard:", text)
handle(text)
Run it and try saying “light on” and “light off” — your lamp should respond instantly.
Step 5: Add a Wake Word (Optional but Cool)
Always-on listening gets noisy. Add Porcupine (by Picovoice) for a custom wake word like “Hey Pi”:
pip3 install pvporcupine
Wrap your listening loop so it only transcribes after the wake word fires — far more elegant and power-efficient.
Step 6: Expand Into Full Home Automation
Once basic commands work, connect your assistant to Home Assistant (the open-source smart home platform). With its REST API, you can control hundreds of devices: smart plugs, thermostats, TVs, blinds, and more.
import requests
requests.post("http://homeassistant.local:8123/api/services/light/turn_on",
headers={"Authorization": "Bearer YOUR_TOKEN"},
json={"entity_id": "light.living_room"})
Add voice responses with espeak or pyttsx3 so your assistant can talk back:
sudo apt install espeak -y
Step 7: Make It Boot on Startup
Add the script to systemd so it runs automatically when your Pi powers on:
sudo nano /etc/systemd/system/assistant.service
Point it at your Python script, enable it, and your Pi becomes a permanent home assistant.
Tips for a Smoother Build
- Use a good mic — far-field arrays dramatically improve recognition
- Reduce background noise for better accuracy
- Keep commands short and distinctive (“lights on” beats “please turn on the lights”)
- Log transcripts while testing to debug misheard words
- Back up your SD card once everything works
Wrapping Up
You’ve just built your very own private, offline-capable voice assistant — no subscriptions, no data harvesting, and total control over what it can do. Expand it with more relays, integrate it with your entire smart home, or train it to recognize your favorite catchphrases.
Your Pi is listening. What will you tell it to do? 🎙️🏠
Loved this project? Follow @raspitips on Instagram for more Raspberry Pi builds, tips, and tutorials.



