Skip to content

Latest commit

Β 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PXL_20251117_143455765 PORTRAIT

πŸŽ™οΈπŸͺŸ Rubik Pi Audio Classification

Real-time glass-break detection with Machine Learning, Edge Impulse, and the Qualcomm-powered RUBIK Pi 3.

This project demonstrates how to deploy an audio classification model on a Thundercomm RUBIK Pi 3 and use the classification result to trigger physical hardware through GPIO.

A USB microphone continuously captures ambient sound. An Edge Impulse model classifies the audio as normal street noise or breaking glass. When the confidence for the glass class exceeds a configured threshold, a GPIO output is activated.

The example implementation lights an LED, but the same signal could trigger a siren, relay, notification service, recording system, or other automation.

⚠️ This is an experimental Machine Learning project. It should not be treated as a certified alarm or security system.


✨ Features

  • πŸŽ™οΈ Real-time audio classification
  • 🧠 Machine Learning with Edge Impulse
  • πŸͺŸ Glass-break detection
  • ⚑ Local inference on RUBIK Pi 3
  • πŸ‰ Qualcomm Dragonwing QCS6490 platform
  • 🐍 Python result parser
  • 🚨 Configurable confidence threshold
  • πŸ’‘ GPIO response when glass is detected
  • ⏱️ Configurable output activation time
  • 🎀 Standard USB microphone input
  • 🐧 Canonical Ubuntu environment
  • πŸ“œ MIT licensed

🎯 Objective

The original experiment was motivated by detecting the characteristic sound of a car window being broken.

Instead of continuously monitoring video footage, a dedicated edge device can listen for a particular acoustic event:

Street sound
      ↓
 Microphone
      ↓
Audio classifier
      ↓
Is it breaking glass?
      ↓
    YES
      ↓
GPIO alert

The same architecture can be adapted to many other acoustic-event detection tasks.


βš™οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      Ambient Sound        β”‚
β”‚                           β”‚
β”‚  traffic / voices / glass β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚
              β–Ό
      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
      β”‚ USB Microphoneβ”‚
      β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
              β”‚
              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚       RUBIK Pi 3          β”‚
β”‚                           β”‚
β”‚ Edge Impulse Linux Runner β”‚
β”‚                           β”‚
β”‚     Audio inference       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚
              β”‚ classifyRes
              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚        glass.py           β”‚
β”‚                           β”‚
β”‚ β€’ Parse probabilities     β”‚
β”‚ β€’ Read `glass` confidence β”‚
β”‚ β€’ Apply 75% threshold     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚
              β”‚ GPIO
              β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚    LED    β”‚
        β”‚  / Alarm  β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🧠 Machine Learning

The model is built and deployed with Edge Impulse.

Two main sound categories are used:

street
glass

The project trains an audio classifier using recordings of:

  • normal street noise
  • breaking glass

The resulting model is deployed to the RUBIK Pi through the Edge Impulse Linux runner.

Example inference output:

classifyRes 2ms. { street: 0.9999, glass: 0.0001 }
classifyRes 2ms. { street: 0.8629, glass: 0.1371 }

The Python script continuously parses these results.


🌐 Edge Impulse project

The Machine Learning project is publicly available in Edge Impulse Studio:

Open the public Edge Impulse project

The Edge Impulse project can be used to inspect the dataset, impulse configuration, training process, and deployment options.


πŸ–₯️ RUBIK Pi 3

The project runs on the Thundercomm RUBIK Pi 3, a Raspberry Pi-style edge-AI development platform based on the Qualcomm Dragonwing QCS6490.

Relevant specifications include:

Specification RUBIK Pi 3
Platform Qualcomm Dragonwing QCS6490
CPU Kryo / Cortex-A78 + Cortex-A55
GPU Adreno 643
AI performance Up to 12 TOPS
RAM 8 GB LPDDR4x
Storage 128 GB UFS 2.2
Network Gigabit Ethernet, Wi-Fi
GPIO 40-pin header
Audio USB / 3.5 mm interfaces

Official documentation:

RUBIK Pi 3 Documentation

ℹ️ The original tutorial instructs Edge Impulse users to select the unoptimized Linux deployment option. The RUBIK Pi hardware includes Qualcomm AI acceleration capabilities, but this particular example should not be assumed to use the NPU unless an optimized deployment is explicitly selected.


🧰 Hardware

Component Purpose
Thundercomm RUBIK Pi 3 Edge inference and GPIO control
RUBIK Pi active cooler Thermal management
12 V / 3 A USB-C PD supply Power
USB microphone Audio capture
LED Detection indicator
2 jumper wires LED connection
Ethernet cable Initial networking / SSH

A microphone connected to the 3.5 mm audio interface can also be used if appropriately configured.


πŸ”Œ GPIO

The reference build connects an LED between:

RUBIK Pi GPIO header pin 13
          β”‚
          β–Ό
         LED
          β”‚
          β–Ό
Pin 6 / GND

The RUBIK Pi Linux GPIO mapping used by the Python program is:

GPIO_PIN = 571

This corresponds to header pin 13 in the project configuration.


🐍 glass.py

The repository contains a single Python application:

glass.py

It performs four main tasks:

Start Edge Impulse runner
        ↓
Read inference output
        ↓
Extract classification scores
        ↓
Trigger GPIO when glass is detected

🎚️ Detection threshold

The current source defines:

CONFIDENCE_THRESHOLD = 75.0

This means the GPIO alert is activated when:

glass confidence β‰₯ 75%

For example:

street: 18.00%
glass: 82.00%

results in:

🚨 WINDOW BREAK SOUND DETECTED!

πŸ’‘ GPIO response

When detection exceeds the threshold, the script activates the output:

out_gpio.write(True)

The LED remains on for:

LED_ON_TIME = 3

seconds.

Then the output returns low:

out_gpio.write(False)

Conceptually:

Glass confidence
       β”‚
       β”‚ β‰₯ 75%
       β–Ό
GPIO HIGH
       β”‚
       β”‚ 3 seconds
       β–Ό
GPIO LOW

🧾 Parsing Edge Impulse output

glass.py launches the Edge Impulse runner directly:

RUNNER_PATH = "/home/ubuntu/edge-impulse-tools/node/bin/edge-impulse-linux-runner"

and writes its output to:

output.txt

The script monitors the file and searches for lines matching:

classifyRes ... { ... }

It then converts the classification result into JSON-compatible data and reads the individual scores.

For example:

classifyRes 53ms. {'glass': 0.91, 'street': 0.09}

becomes approximately:

{
  "glass": 0.91,
  "street": 0.09
}

The glass value is converted to a percentage before being compared with the configured threshold.


πŸš€ Installation

1. Clone the repository

git clone https://github.com/ronibandini/Rubik-Pi-AudioClassification.git
cd Rubik-Pi-AudioClassification

Repository structure:

Rubik-Pi-AudioClassification/
β”œβ”€β”€ LICENSE
β”œβ”€β”€ README.md
└── glass.py

🐧 Operating system

The project tutorial assumes the RUBIK Pi is running:

Canonical Ubuntu for Qualcomm platforms

Connect:

  • power supply
  • USB microphone
  • Ethernet

Boot the RUBIK Pi and obtain its IP address from your router or local console.

Then connect through SSH:

ssh ubuntu@RUBIK_PI_IP

⚑ Install Edge Impulse

Update the system:

sudo apt update

Download the Qualcomm Linux setup script:

wget https://cdn.edgeimpulse.com/firmware/linux/setup-edge-impulse-qc-linux.sh

Install the SELinux utility required by the setup:

sudo apt install selinux-utils

Then:

source ~/.profile
chmod +x setup-edge-impulse-qc-linux.sh
./setup-edge-impulse-qc-linux.sh

Official Edge Impulse documentation:

Audio Classification and GPIO Response β€” RUBIK Pi 3


πŸŽ™οΈ Configure the microphone

Connect the USB microphone and run:

alsamixer

Press:

F6

to select the USB input.

Increase the recording level if required using the arrow keys.


🐍 Install Python GPIO support

Install:

sudo apt install python3-pip
sudo apt install python3-periphery

The script imports:

from periphery import GPIO

πŸ” Configure GPIO permissions

Create a GPIO user group:

sudo groupadd -f gpio
sudo usermod -aG gpio ubuntu

Edit:

sudo nano /etc/udev/rules.d/99-gpio.rules

Add rules granting the gpio group access to GPIO devices.

After saving the file:

sudo udevadm control --reload-rules
sudo udevadm trigger
sudo reboot

Reconnect to the board after reboot.


πŸ§ͺ Test Edge Impulse inference

Run:

edge-impulse-linux-runner --clean

Log in with your Edge Impulse account.

Select:

  1. the audio-classification project
  2. the unoptimized model
  3. the USB microphone

You should begin seeing output similar to:

classifyRes 2ms. { street: 0.9999, glass: 0.0001 }

Stop the runner with:

CTRL-C

🚨 Run the detector

Start:

python3 glass.py

The application displays:

Machine Learning with Edge Impulse
Monitoring for glass breaking sounds...
Stop with CTRL-C

When a classification arrives, the scores are printed:

--- Inference ---
 street: 4.23%
 glass: 95.77%

If the confidence exceeds 75%:

🚨 WINDOW BREAK SOUND DETECTED!
🟒 Alert LED activated on GPIO 571

Three seconds later:

πŸ”΄ Alert LED deactivated

Stop the program with:

CTRL-C

The script closes the GPIO cleanly before terminating.


πŸ”§ Configuration

The main configuration values are at the beginning of glass.py:

CONFIDENCE_THRESHOLD = 75.0
GPIO_PIN = 571
LED_ON_TIME = 3
Variable Default Purpose
CONFIDENCE_THRESHOLD 75.0 Minimum glass probability
GPIO_PIN 571 Linux GPIO number
LED_ON_TIME 3 Output duration in seconds

πŸ”¬ Ideas for extending the project

  1. πŸ“² Send notifications β€” call a webhook when glass is detected to trigger WhatsApp, email, Telegram, n8n, Home Assistant, or another automation system.

  2. πŸ“Ή Trigger video recording β€” connect the detector to a security camera and preserve footage from immediately before and after the acoustic event.

  3. 🎧 Add more sound classes β€” extend the model to distinguish breaking glass from alarms, impacts, car horns, shouting, or other urban acoustic events.


πŸ“° External references

This project is documented and indexed outside GitHub on both Edge Impulse and the official RUBIK Pi / Thundercomm documentation.


⚑ Edge Impulse

Expert Network project

Audio Classification and GPIO Response β€” RUBIK Pi 3

Edge Impulse hosts the complete project in its official Expert Network documentation.

The page covers:

  • project motivation
  • RUBIK Pi 3 specifications
  • hardware setup
  • Edge Impulse installation
  • audio dataset
  • USB microphone setup
  • GPIO configuration
  • Python parser
  • alert output
  • possible webhook integration

Most importantly, the Edge Impulse page explicitly references this repository:

github.com/ronibandini/Rubik-Pi-AudioClassification


Edge Impulse project directory

Edge Impulse Expert Network β€” Project List

Edge Impulse also lists:

Audio Classification and GPIO Response - Rubik Pi 3

among its Featured Machine Learning Projects.


Public Edge Impulse project

Rubik Pi Audio Classification β€” Edge Impulse Studio

Public Edge Impulse Studio project associated with the audio-classification experiment.


πŸ‰ Thundercomm / RUBIK Pi

Official RUBIK Pi documentation

Audio Classification and GPIO Response β€” RUBIK Pi 3

Thundercomm includes the project directly in the official RUBIK Pi 3 documentation.

The page identifies:

Created By: Roni Bandini

and explicitly links to:

  • the public Edge Impulse project
  • this GitHub repository

It documents the complete workflow from hardware setup through audio inference and GPIO activation.


RUBIK Pi AI & Machine Learning index

RUBIK Pi β€” AI & Machine Learning

Thundercomm also indexes the project as one of the official RUBIK Pi AI/ML examples alongside other edge-AI applications.


πŸ“š Useful references


πŸ”— You may also be interested in...

Other projects by Roni Bandini involving Edge Impulse, audio classification, and the RUBIK Pi.

πŸ“ˆπŸ€– RUBIK Pi 3 Anomaly Detection

Anomaly detection on the RUBIK Pi 3 using Edge Impulse and n8n.

The closest companion project in terms of hardware: it also explores Machine Learning deployment on the Qualcomm-powered RUBIK Pi 3, with n8n handling the higher-level automation workflow.

github.com/ronibandini/rubikpi3-anomaly-detection


πŸ—‚οΈπŸ€– PunchedCards

Punched-card recognition using computer vision, Edge Impulse, and LattePanda IOTA.

Another Edge Impulse project demonstrating how local inference results can be consumed by a small Python application running on Linux edge hardware.

github.com/ronibandini/PunchedCards


🎧🚫 Reggaeton Be Gone

Machine Learning audio classification with a Raspberry Pi and Edge Impulse.

Another project centered on real-time audio classification, where the detected sound class triggers a physical/wireless response.

github.com/ronibandini/reggaetonBeGone


⚠️ Detection limitations

Audio classification is probabilistic.

Factors that can affect accuracy include:

  • microphone sensitivity
  • microphone placement
  • distance from the sound source
  • room acoustics
  • background noise
  • audio clipping
  • sounds similar to breaking glass
  • differences between training and real-world environments

The 75% confidence threshold is an experimental value, not a guaranteed security threshold.

For a real alarm application, consider combining audio classification with additional evidence such as:

audio detection
      +
camera event
      +
vibration sensor
      +
multiple consecutive classifications

πŸ“œ License

Rubik-Pi-AudioClassification is released under the MIT License.

See LICENSE for details.


πŸ‘€ Author

Roni Bandini

Maker, AI developer, electronic artist and writer.

Contributions, forks, alternative sound models, notification integrations, and other RUBIK Pi experiments are welcome.

About

Machine Learning audio classification with Thundercomm Rubik Pi and Edge Impulse

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages