Acoustic Event Detection API (Gunfire, Explosions, Distress Sounds)

Core Concept:

  • Continuously monitor microphone input for high-energy acoustic signatures (e.g., gunfire, explosions, screams).
  • If matched, trigger a local event, optionally queue for IPFS broadcast, and/or activate SafeSignal Defender alerts.

Detection Methods

  • FFT-based acoustic fingerprinting
  • Machine learning (lightweight CNN/RNN)
  • Optional: spectrogram pattern matching
  • All processing done locally, to preserve privacy and reduce latency

Endpoints (API Spec)

yamlPOST /acoustic/start
- Begins audio monitoring with specified detection sensitivity
- Payload: { sensitivity: 0.0–1.0, filters: [“gunshot”, “scream”], offlineMode: true }

POST /acoustic/event
- Accepts a manually tagged acoustic event (e.g., from hardware button or AI engine)
- Payload: { type: “gunshot”, location: "lat,long", timestamp: "...", cid: "..." }

GET /acoustic/logs
- Retrieves detected acoustic events from local or synced logs

POST /acoustic/report
- Broadcasts CID of event report to validators / OTA network

🛠️Device Support

  • Raspberry Pi + external mic array
  • Thetis SDR w/ audio input
  • Windows-based validator nodes (more compute for AI filtering)

Relay & Response (Optional)

  • Relay detection via:
    • HF SDR (if no internet)
    • IPFS broadcast
    • Edge-pinned CID log
  • Trigger:
    • Silent alerts
    • Push to Defender node
    • Nearby validator notification

Privacy & Verification

  • MAC-auth for source device
  • CID-signed audio hash (optional)
  • Local-only retention or timed broadcast delay (for safety)

Sample sdk

Core Hardware Nodes

PurposePartNotes
SDR ReceiverHermes Lite 2High-quality HF SDR for accurate capture + MAC registration
Companion PiRaspberry Pi 4B (4GB or 8GB)Runs Thetis or Pi Router w/ gunshot logic
Outdoor EnclosureIP67-rated case with antenna portWeatherproof for pole or rooftop mount
Power12V solar + battery packFor uninterrupted operation in remote areas

Acoustic Gunshot Detection System

SensorModelIntegration
Microphone ArrayReSpeaker 4-Mic Array for PiSupports basic triangulation
Analog Mic (alt)Adafruit Electret Mic + PreampLower-cost sensor per node
ProcessingBuilt-in to Pi via gunshot_analyzer.pyUses FFT + envelope detection

Communications

MediumPartNotes
Primary RelayOTR Mesh (MAC-router + SDR)CID relay of gunshot + timestamp
BackupLoRa 915MHz GatewayRange-based fallback; not ideal for high volume
Long-HaulIridium GO! or LTE Stick (optional)Fallback IPFS sync when internet present

Logic + Storage

TaskPart/SoftwareNotes
CID loggingPi + gunshot_logger.pyLogs + pushes gunfire CIDs to IPFS
Event syncSafeSignal or /eventsync.pyBroadcasts to other trusted nodes
Mode switchband_matrix_ui.pyEnables dedicated gunshot mode (e.g., listen-only)

Security + Auth

FunctionPartNotes
MAC AuthBuilt-in OTR node logicAuto-verifies validator relay and logs
Device Auth/device/verify + alias_api_server.pyPrevent rogue node injection
Tamper SensorOptional IMU or reed switchTriggers alert if box opened or moved

Operator Panel (Optional)

InterfaceToolDescription
Local Admingunshot_dashboard.htmlWeb dashboard from LAN or VPN
Remote Sync/gunshot/view APIPulls CID log, shows map, waveform, time

Core Node Hardware

PartDescriptionLink (Example)Approx Price
Raspberry Pi 4 (4GB or 8GB)Main controller with USB supportAmazon$60–$85
MicroSD Card (32–128GB)Boot + storageAmazon$10–$25
USB Microphone (Omni-directional)Acoustic captureAmazon$15–$40
GPS Module (e.g., u-blox NEO-6M)Location for triangulation + syncAmazon$12–$18
Real-Time Clock (RTC) module (DS3231)Timestamp accuracy offlineAmazon$8–$15
LoRa Module (e.g., RFM95W SX1276)OTR comms layerAmazon$10–$18
LoRa Hat or USB adapterInterface to PiPiHat$14–$22
Weatherproof Outdoor CaseField deployment enclosureAmazon$25–$50
Power Bank or Solar + Battery PackPower for remote unitsAmazon$25–$70

Network + Software Stack

FeatureTool / PackageNotes
Acoustic ClassifierTensorFlow Lite or PyTorchTrained to detect gunshot vs. other impulse noise
Triangulation EngineCustom OTA Python moduleBased on timestamp and GPS across 3+ nodes
LoRa OTR Relaylora_node_api + ipfshttpclientMesh+IPFS bridge
IPFS LoggingGo-IPFS binary or embedded clientFor CID-based event audit trail
CLI/GUI Ops Toollora_gui.py (you approved this)Manual ops or debug

Optional Add-ons

  • AI camera module (OpenCV compatible) — For visual correlation
  • Acoustic MEMS mic array — For more precise detection (e.g., SPH0645LM4H)
  • Remote OTAwallet uplink node — Automatically logs CIDs and payout on match (trigger alert → mint)

/gunshot/view Endpoint (FastAPI Example)

pythonfrom fastapi import FastAPI
from pydantic import BaseModel
from typing import List
import json
from datetime import datetime
import os

app = FastAPI()

# Simulated local log file
LOG_FILE = "gunshot_events.json"

class GunshotEvent(BaseModel):
timestamp: str
latitude: float
longitude: float
confidence: float
cid: str
node_id: str

@app.get("/gunshot/view", response_model=List[GunshotEvent])
def view_gunshot_events(limit: int = 20):
if not os.path.exists(LOG_FILE):
return []

with open(LOG_FILE, "r") as f:
events = json.load(f)

return sorted(events, key=lambda e: e["timestamp"], reverse=True)[:limit]

Example Log File (gunshot_events.json)

json[
{
"timestamp": "2025-06-04T21:14:55Z",
"latitude": 34.0522,
"longitude": -118.2437,
"confidence": 0.92,
"cid": "QmExampleCID123",
"node_id": "node-west01"
},
{
"timestamp": "2025-06-04T20:59:31Z",
"latitude": 34.0500,
"longitude": -118.2450,
"confidence": 0.87,
"cid": "QmExampleCID456",
"node_id": "node-west02"
}
]

Optional Add-ons

  • /gunshot/push: Upload log to IPFS and return CID
  • /gunshot/geo: Return all points as GeoJSON for map overlay
  • /gunshot/node-stats: Count per-node detection and confidence level summary