Build a Talking AI Dictionary with Raspberry Pi

Build a Talking AI Dictionary with Raspberry Pi | Fun DIY STEM Project for Kids
🧑‍🔬 Beginner-Friendly STEM Build

Build a Talking AI Dictionary with Raspberry Pi 🐰📖

Turn a Raspberry Pi, a tiny camera, and a touch screen into a gadget that looks at any object, tells you what it is, and reads the answer out loud — like your own robot teacher!

⏱️ Weekend Project 🎓 Ages 10+ (with a grown-up) 🛠️ Beginner Friendly 🐍 Uses Python

📖 What is an AI Visual Dictionary?

Imagine holding up an apple to a little box, and instead of typing anything, the box looks at the apple, thinks for a second, and then says out loud: "This is an Apple! A round fruit that grows on trees. Fun fact — apples float in water!"

That's exactly what we're building. It uses:

  • A camera to see the world (or a microphone to hear a question)
  • A smart AI model (Google Gemini) to understand what it sees or hears
  • A touch screen to show the answer
  • A speaker to say the answer out loud
Why this project is great for learning 🌟 You'll practice electronics (wiring), coding (Python), and even a little bit of real artificial intelligence — all in one fun build!

🧰 Gather Your Materials

Here's everything you need. Most of these plug in — no soldering required!

🖥️
Raspberry Pi 5The mini computer "brain"
📷
Pi Camera ModuleConnects via ribbon cable
🖐️
4.3" Touch DisplayShows the dictionary card
🎙️
USB MicrophoneSo it can hear your questions
🔊
Bluetooth SpeakerReads the answer out loud
🔘
Push Button (optional)A physical "Scan" button
💳
MicroSD Card (32GB+)Holds the Raspberry Pi OS
🔋
Official Power SupplyPi 5 needs a strong 27W adapter
🧑‍🏫 Ask a grown-up to help with the power supply and any cable connecting — some ribbon cable connectors are delicate!

🔌 Wire It Up

Good news: almost everything on this build is plug-and-play. Here's how each part connects to the Raspberry Pi 5:

Raspberry Pi 5 (the brain) GPIO pins 📷 Camera CSI ribbon port 🖐️ Touch Display HDMI + USB touch 🎙️ USB Mic Any USB port 🔊 BT Speaker Pairs wirelessly GO GPIO 17 + GND
Camera → CSI port · Display → HDMI + USB · Mic → USB · Speaker → Bluetooth · Button → GPIO 17 & GND
2.1

Connect the camera

Gently lift the black clip on the Pi's camera port, slide the ribbon cable in (blue side facing the USB ports), then push the clip back down.

2.2

Connect the touch display

Plug the display's HDMI cable into the Pi's HDMI port, and its separate USB touch cable into any USB port — this lets your finger taps register as clicks.

2.3

Plug in the mic

Plug your USB microphone into any free USB port on the Pi.

2.4

Add the push button (optional)

Connect one leg of the button to GPIO 17 and the other leg to any GND (ground) pin.

🧑‍🏫 Double-check the button legs go to GPIO 17 and GND, not a power pin — a grown-up can help you check the pinout diagram printed on the Pi.

💻 Set Up the Software

Now let's wake up the "brain." Open a Terminal on your Raspberry Pi and type these commands one at a time.

3.1

Update the Pi & install tools

terminal
sudo apt update && sudo apt upgrade -y
sudo apt install -y python3-pip python3-venv mpg123 portaudio19-dev python3-picamera2
3.2

Create your project folder

terminal
mkdir ~/AI_Dictionary
cd ~/AI_Dictionary
python3 -m venv venv --system-site-packages
source venv/bin/activate
3.3

Install the Python packages

terminal
pip install google-genai gtts pillow gpiozero sounddevice scipy faster-whisper numpy
3.4

Add your AI key

Get a free Gemini API key from Google AI Studio, then save it:

terminal
nano config.py
config.py
API_KEY = "paste_your_key_here"
🧑‍🏫 An adult should help create the free Google account and API key.

🐍 Write the Code, Piece by Piece

We'll build seven small files. Each one has a single job — like separate departments in a tiny robot company!

4.1

📷 camera.py — takes the photo

camera.py
from picamera2 import Picamera2
from time import sleep
import os

class Camera:
    def __init__(self):
        self.picam2 = Picamera2()
        config = self.picam2.create_still_configuration()
        self.picam2.configure(config)
        self.picam2.start()
        sleep(2)
        os.makedirs("temp", exist_ok=True)
        self.filename = "temp/capture.jpg"

    def capture(self):
        self.picam2.capture_file(self.filename)
        return self.filename

    def stop(self):
        self.picam2.stop()
4.2

🧠 ai_engine.py — the AI brain

ai_engine.py
import json
from PIL import Image
from google import genai
from config import API_KEY

class AIEngine:
    def __init__(self):
        self.client = genai.Client(api_key=API_KEY)

    def object_prompt(self):
        return """Identify ONLY the main object nearest the
center of the image. Return ONLY JSON:
{"word":"","pronunciation":"","meaning":"",
"example":"","fun_fact":""}
Meaning suitable for Grade 5. Max 30 words."""

    def identify_object(self, image_path):
        image = Image.open(image_path)
        response = self.client.models.generate_content(
            model="gemini-2.5-flash",
            contents=[image, self.object_prompt()]
        )
        text = response.text.strip().replace("```json","").replace("```","")
        return json.loads(text)
4.3

🔊 speech.py — makes it talk

speech.py
import os, threading
from gtts import gTTS

class Speaker:
    def speak(self, text):
        threading.Thread(target=self._play, args=(text,), daemon=True).start()

    def _play(self, text):
        tts = gTTS(text=text, lang="en")
        tts.save("temp/speech.mp3")
        os.system("mpg123 -q temp/speech.mp3")
4.4

🎙️ voice.py — listens to your questions

voice.py
import sounddevice as sd
from scipy.io.wavfile import write
from faster_whisper import WhisperModel
import numpy as np, tempfile, os

class VoiceRecognizer:
    def __init__(self):
        self.model = WhisperModel("tiny", device="cpu", compute_type="int8")

    def listen(self):
        rec = sd.rec(int(5*16000), samplerate=16000, channels=1, dtype="int16")
        sd.wait()
        path = os.path.join(tempfile.gettempdir(), "voice.wav")
        write(path, 16000, rec)
        segments, _ = self.model.transcribe(path, language="en")
        return "".join(s.text for s in segments).strip()
4.5

🗂️ history.py — remembers past words

history.py
import json, os
from datetime import datetime

class History:
    def __init__(self, filename="history.json"):
        self.filename = filename
        if not os.path.exists(filename):
            json.dump([], open(filename, "w"))

    def add(self, data):
        entries = json.load(open(self.filename))
        entries.insert(0, {
            "word": data.get("word",""),
            "time": datetime.now().strftime("%Y-%m-%d %H:%M")
        })
        json.dump(entries[:50], open(self.filename, "w"), indent=2)
4.6

🖐️ gui.py — the touch screen face

This file builds the on-screen dictionary card with two big buttons: Scan Object and Ask Word. It uses Python's built-in tkinter library to draw the layout full-screen on your 4.3" display.

Tip 💡 Keep the font large and buttons big — little fingers (and nervous exhibition-day fingers!) need bigger tap targets.
4.7

🚦 main.py — connects everything

main.py
from camera import Camera
from ai_engine import AIEngine
from speech import Speaker
from voice import VoiceRecognizer
from history import History
from gui import DictionaryGUI

camera = Camera()
ai = AIEngine()
speaker = Speaker()
voice = VoiceRecognizer()
history = History()

def handle_scan():
    photo = camera.capture()
    result = ai.identify_object(photo)
    history.add(result)
    speaker.speak(result["meaning"])
    gui.show_result(result)

def handle_ask():
    question = voice.listen()
    result = ai.ask_word(question)
    history.add(result)
    speaker.speak(result["meaning"])
    gui.show_result(result)

gui = DictionaryGUI(on_scan=handle_scan, on_ask=handle_ask)
gui.run()

🚀 Run Your AI Dictionary!

5.1

Launch it

terminal
cd ~/AI_Dictionary
source venv/bin/activate
python main.py

Your screen should light up full-screen, and you'll hear "AI Dictionary is ready" 🎉

5.2

Try it out

  • Point the camera at something like an apple, a toy, or a pencil and press Scan Object
  • Or press Ask Word and speak a question out loud, like "What is a volcano?"
Volcano 🌋
A mountain that can explode and pour out hot melted rock called lava!

🔧 Fix Common Hiccups

No camera foundCheck the ribbon cable is fully clipped in, and enable the camera in sudo raspi-config → Interface Options.
Mic not detectedRun lsusb to check the Pi actually sees it — try a different USB port if not.
No sound from speakerRe-pair it with bluetoothctl connect [address] and set it as default with pactl set-default-sink.
AI gives an errorCheck your internet connection and that your API key in config.py is correct and active.
Voice hears the wrong wordsAdd language="en" to the transcribe call, and speak clearly and close to the mic.

❓ Frequently Asked Questions

Do I need to know how to code already?

Not much! This project teaches you as you go. If you can type and follow instructions carefully, you can build this.

Does this work without internet?

The camera, screen, and speaker all work offline, but the "thinking" part uses Google's Gemini AI, which needs an internet connection.

Can I enter this in a school science fair?

Absolutely! It's a great blend of electronics, coding, and artificial intelligence — a real crowd-pleaser at exhibitions.

How much does this cost to build?

Costs vary by region and where you buy parts, but a Raspberry Pi 5, camera, small touch display, USB mic, and Bluetooth speaker are all affordable, widely available components.

🎉 You built a real talking AI!

Show it off, teach a friend, and keep experimenting — try new objects, funnier fun-facts, or even a second language!

Made with 💙 for curious young makers everywhere.

Comments

Product Cards
Buddy Bot eBook
⭐ New 2026 Release
Build Your
Own Robot!
3D design, wiring &
Arduino coding.
Young inventors love it!
🖨️
3D Print
All parts
Wire it
Circuit guide
💻
Code it
Arduino IDE
🤖
Watch it
Walk & react
📋 Your Details
Enter your name
Valid 10-digit no.
Enter a valid email
Special Website Offer
₹499 300
🌍 International: $5 USD
One-time · Instant digital delivery
🔒 Secured by Razorpay · Your data is safe
📄 Download Free Sample Copy
🔒 Secured by Razorpay · Your data is safe
🍓
Raspberry Pi Pico Mastery
21 Projects
⚡ Launch Price — 80% OFF
Learn Pico
Build 21 Projects!
MicroPython · Wokwi
IoT · Certificate
Perfect for beginners!
🖥️
Wokwi
No hardware
🐍
MicroPy
From zero
🔨
21 Projects
IoT + sensors
📄
Certificate
Verified cert
📋 Your Details
Enter your name
Valid 10-digit no.
Enter a valid email
Special Launch Offer
₹999 200 80% OFF
🌍 International: $5 USD
One-time · Lifetime access · No subscription
🔒 Secured by Razorpay · UPI · Cards · NetBanking
🎉

You're in!

Payment successful! Your Buddy Bot eBook is ready. Time to build!

📖 Access Your eBook Now
🎉

Enrolled!

Payment successful! Lifetime access to all 21 Pico Projects is yours!

🍓 Go to My Course