Tag Archives: Speech to Text

AI on the Edge LESSON 36: Select Active Camera in OpenCV With Voice Commands

Welcome back, makers, engineers, and AI enthusiasts! In our previous lessons, we built out robust multi-camera setups, streaming feeds from both Raspberry Pi cameras and high-definition USB cameras. But watching four feeds in separate tiles is only half the battle. What happens when you want to interact with your system hands-free?

In this lesson, we are taking our edge vision projects to the next level by integrating voice commands. You will learn how to run a dedicated speech-to-text thread in the background, catch voice triggers safely using a thread-safe queue, and dynamically switch your active main camera feed in OpenCV on the fly—just by speaking.

What You Will Learn in This Lesson

  • Multi-Threaded Speech Recognition: How to run the stt listener in a separate daemon thread so it never blocks or stutters your high-FPS video processing loop.

  • Thread-Safe Communication: Using Python’s Queue module to pass voice commands seamlessly from the background listening thread into your main application loop.

  • Handling STT Variations: Accounting for common speech-to-text homophone variations (like “two”, “to”, and “too”, or “four” and “for”) to make your voice control robust and reliable.

  • Dynamic Frame Routing: Mapping spoken commands to specific camera streams (piCam1, piCam2, usbCam1, and usbCam2) and updating your primary display window instantly.

  • Organized Window Layouts: Positioning and sizing multiple OpenCV windows on your desktop workspace for a clean, professional multi-camera dashboard.

Step-by-Step Breakdown of the Script

1. Setting Up the Background Voice Thread

When working with real-time video processing in OpenCV, blocking functions are your worst enemy. If you call a speech recognition listening function directly inside your main while loop, your video frames will freeze while waiting for audio input.

To prevent this, we initialize a background worker function (getCamera) and launch it as a daemon thread:

  • The thread continuously listens for your voice commands using the Fusion Hat STT module.

  • Once a command is captured, it strips whitespace, checks for exit triggers (like saying 'quit'), and pushes valid commands directly into our commandQ.

2. Initializing Multiple Cameras

Our setup harnesses the full power of the hardware by combining native Raspberry Pi camera interfaces with standard USB webcams:

  • Pi Cameras: Configured via Picamera2 at a crisp 1280x720 resolution with RGB888 formatting running smoothly at 60 frames per second.

  • USB Cameras: Initialized through OpenCV’s VideoCapture class, set to target resolution and optimized for 30 FPS.

3. Processing and Routing Commands in the Main Loop

Inside the primary application loop, our script handles three core tasks simultaneously:

  1. Calculate Performance: Continuously tracks and smooths out the frames-per-second (FPS) metric so you can monitor system load.

  2. Check the Command Queue: Non-blockingly checks if the background thread has dropped a new camera selection into commandQ. If a new command is waiting, it updates the mainCam variable.

  3. Route the Main Frame: Evaluates the active camera string—including clever fallback checks for common voice misinterpretations like 'camera to' or 'camera for'—and assigns the corresponding video stream to mainFrame.

4. Managing Your OpenCV Windows

To give you a complete command-center experience, the script generates a large primary display window for your active camera view, accompanied by a clean row of smaller preview tiles across the bottom of your screen for all four connected feeds.

 

Local Voice Control of NVIDIA Jetson Orin Nano with STT: Getting Started with Vosk

Engineering Your Own Local Voice Assistant: No Cloud, No Compromise

Most “smart” voice assistants are just glorified remote controls for someone else’s server. Today, we’re changing that. We are going to build a local, offline voice command pipeline. This isn’t just about saving data; it’s about ownership. When you can control your hardware—like opening and closing a farm gate—without an internet connection, you have built a system that is robust, private, and yours to control forever. Today you are going to get Speech to Text up and running on your NVIDIA Jetson Orin Nano running under Jetpack 7.2.

The “Why” Behind the Setup

You might ask, “Why not just use a cloud API?” Because cloud APIs are fragile. They rely on internet stability, external servers, and privacy-invasive data logging. By running Vosk locally, we keep the processing on your hardware (like the NVIDIA Jetson). It’s faster, it works in the middle of a power-isolated homestead, and it’s 100% secure.

Part 1: Preparing the Environment

Before we can make the machine listen, we have to prepare the battlefield. We aren’t just downloading files; we are setting up a stable environment where your dependencies won’t conflict with your OS.

This is IMPORTANT!

Now you can post the code below. You also have to point Thonny to run in the virtual environment. Open Thonny, and under run –  select interpreter. Then you must point it to /home/yourUserName/STT/ttsVenv/bin/python3. For me, my username is pjm, but you put in your user name in path above. Here is what mine looked like:

Part 2: Solving the PipeWire Challenge

The biggest headache in modern Linux audio is PipeWire. If you try to open a microphone stream using a hardcoded sample rate that doesn’t match your hardware, your program won’t just fail—it will segfault. We use the validation script below to programmatically query the hardware, asking it: “What sample rate are you running at?” before we even try to open a stream.

Homework: Your Gate Controller

You now have a system that identifies audio input, resamples it to 16kHz, and outputs text. Your assignment: Transform this text output into an action.

I want you to add a conditional statement to the main loop. If the recognized text is “open”, print an ASCII art representation of an open gate. If it’s “close”, print the closed version. This is the first step in closing the loop between your AI and the physical world. Go get ’em, and don’t just copy the code—understand how the data flows from the microphone to your decision logic!

AI on the Edge LESSON 34: Project Combining TTS, STT, Face Recognition and Servos on Pi 5

In our previous lessons, we built individual components. We got our machine to listen locally using Speech-to-Text (STT), we got it to talk back cleanly with Text-to-Speech (TTS), and we learned how to manipulate physical hardware using precision servos. Today, we bridge the gap between software and the physical world. We are building a multi-threaded, autonomous edge system that tracks humanoids in real time.

The Engineering Mindset: Concurrency & Threading

If you try to build a system like this sequentially—running camera capture, object detection, audio listening, and audio speaking in a single while True: loop—your project will fail completely. Why? Because tasks like waiting for a voice command (stt.listen()) or synthesizing a voice line are blocking operations. If your code is stuck waiting for you to finish speaking a command, your camera frames freeze, your servo adjustments drop to zero, and your humanoid target escapes.

To solve this, we architect our software using Multi-threading. We spawn independent execution paths that run concurrently, passing data back and forth safely using thread-safe Queues:

  • The Main Thread: Handles the high-speed Picamera2 video capture loop, executes Haar Cascade face/eye calculations, and updates the servo angles via mathematical error tracking.
  • The Speak Thread: Idles quietly in the background until a message lands in the speakQ, instantly triggering the local Piper TTS engine without stalling our camera frame rate.
  • The Command Thread: Keeps a continuous ear open via our local STT engine. When it parses a voice command like “track”, “release”, or “quit”, it safely pops that token into the commandQ for the main loop to execute on its next pass.

The Complete Fusion Architecture Code

Below is the complete Python pipeline developed in today’s lesson. Make sure your hardware connections for the pan-and-tilt servos match pins 2 and 3 on your expansion setup, and verify your fusion_hat software stack is completely updated.


Breaking Down the Math & Logic

Pro-Tip on State Debouncing: Notice how we handle messages using the cnt variable and the msgOld buffer. If we simply asked the system to say “Humanoid Detected” every single time the frame loops, the TTS engine would crash from queue overflow, stuttering continuously. By checking if msgOld != msg, we ensure the system speaks a notification exactly once upon transition. The 25-frame hysteresis buffer ensures that a single missed frame doesn’t cause a false “No Humanoid” trigger.

Proportional Error Tracking

Look carefully at how the servo angles are adjusted:

We are calculating the error vector—how many pixels the center of the bounding box (xBoxC) is from the absolute center of our camera stream (xFrameC). Instead of moving the servo by a fixed step, we move it proportionally to the size of the error. Big error? Fast movement. Small error? Gentle, microscopic correction. Dividing by 50 dampens our proportional gain loop so our servos don’t violently oscillate and throw our camera system completely out of alignment.

Your Homework Assignment

You have the system reading frames, listening asynchronously, and adjusting angles proportionally. Now it’s time to earn your stripes as an edge systems designer.

Your Assignment: Look at our msg tracking logic. Right now, if a humanoid is detected, it simply asks, “Shall I track?”. Your task is to tie our speech input directly to this state. Modify the control flow so that the tracking logic requires verification. If a humanoid is detected, the system must wait until the commandQ yields a verified verbal confirmation—like “execute” or “yes”—before the proportional servo tracking begins. If it hears “abort”, it must break off and look away.

Drop your custom implementation script in the comments section below, explain the logic behind your state modifications, and let’s see how you optimize your loop efficiency. Go get ’em!

AI on the Edge LESSON 13: Control LED Brightness with Voice Commands on Raspberry Pi 5

Hey everyone, welcome back to the AI on the Edge series!

In today’s lesson, we’re taking another big step forward in building truly interactive AI projects that run right on our Raspberry Pi 5. We’re going to give our hardware a voice — literally. You’ll learn how to control the brightness of an LED using simple voice commands like “low”, “medium”, “high”, “on”, and “off”.

This lesson builds directly on the speech-to-text skills we learned earlier. Using the Fusion Hat’s microphone and the excellent STT library, we create a system where you can speak naturally to your Pi and it responds instantly by changing the LED brightness. We also bring in Python threading so the voice listening doesn’t block the main program — which is a critical skill as our projects get more complex.

One of the things I really like about this project is how it shows the power of combining AI with real hardware. You’re not just making the LED turn on and off anymore — you’re giving it smooth, adjustable brightness control using nothing but your voice. It’s a perfect example of the kind of interactive, intelligent edge computing we’re working toward in this class.

By the end of this lesson, you’ll have a solid understanding of how to use voice commands to control hardware, how to manage multiple things happening at the same time with threading, and how to create a much more natural and user-friendly interface for your projects.

This is the kind of thing that makes your Raspberry Pi projects feel alive and responsive. Whether you eventually want to control motors, lights, robots, or entire systems with your voice, the techniques you learn in this lesson will serve as a strong foundation.

So grab your SunFounder Fusion AI Hat, hook up that red LED, and let’s get your Raspberry Pi listening and responding to your voice commands like a proper smart device!

As always, I encourage you to type the code along with me in the video, then play around with it. Try adding more commands, change the LED color, or combine it with other sensors. That’s where the real learning and creativity happens.

I’m really excited to see what you build with this one!

This is the schematic we are using, from LESSON #5.

Fusion Hat Circuit Diagram
This is the circuit we will use moving forward in the class

In the video, this is the code we developed:

 

AI on the Edge LESSON 11: Control LED on Raspberry Pi With Voice Commands

In today’s lesson, we’re taking our first exciting step into giving our Raspberry Pi the ability to understand and respond to our voice. That’s right — we’re going to control a physical LED using nothing but spoken commands! This is a huge milestone in the class because it marks the beginning of building truly interactive AI projects that can listen to us and take action in the real world.

Using the SunFounder Fusion AI Hat’s built-in microphone and the excellent STT (Speech-to-Text) library, we create a simple but powerful voice assistant that can turn an LED on and off with commands like “on”, “off”, and “quit”. I walk you through every single line of the code so you can clearly see how we capture voice input, process the command, and control real hardware.

This lesson is intentionally straightforward because I want you to build a strong foundation. Once you understand how to take a voice command and turn it into physical action, we can start adding more complexity — like controlling multiple devices, adjusting brightness, or even combining voice control with computer vision in future lessons.

One of the things I love most about this project is how it makes the Raspberry Pi feel “alive.” Instead of clicking buttons or typing commands, you can now talk directly to your project. This is the kind of interaction that makes edge AI projects so much fun and so powerful.

By the end of this lesson, you’ll have a working voice-controlled LED and the confidence to start expanding your voice control skills. This is exactly the kind of capability we need as we move forward in the AI on the Edge journey — giving our intelligent systems natural, human-friendly ways to interact with us.

So grab your Fusion AI Hat, hook up that LED, and let’s turn your Raspberry Pi into a voice-controlled device! As always, I strongly encourage you to code along with me in the video and then play around with the program. Try adding more commands, control multiple LEDs, or even have it say something back to you.

This is where things start getting really fun. Let’s get that LED responding to your voice!

This is the schematic of the circuit we are using for our AI class. We go into great detail on this schematic in LESSON #5 if you want to learn more about it.

Fusion Hat Circuit Diagram
This is the circuit we will use moving forward in the class

Now this is the code we developed in this lesson: