A local prototype that detects a user-defined safe word and triggers protective actions (record audio, alert contacts). Built with Mycroft Precise for keyword spotting, Flask backend, and React frontend.
# Navigate to backend directory
cd backend
# Create and activate virtual environment
python3 -m venv .venv
source .venv/bin/activate # On macOS/Linux
# .venv\Scripts\activate # On Windows
# Install Python dependencies
pip install -r requirements.txt
# Install Mycroft Precise
pip install precise-runner
# Copy environment template (optional - for SMS/Email features)
cp .env.example .env
# Edit .env with your credentials if needed
# Start Flask server
python app.py
The backend will start on http://127.0.0.1:5000
# Open a new terminal and navigate to frontend directory
cd frontend
# Install dependencies
npm install
# Start React development server
npm start
The frontend will open automatically at http://localhost:3000
http://localhost:3000Tip: The more varied samples you provide, the better the detection accuracy.
Tip: Use βTest Triggerβ to test actions without speaking.
safeword/
βββ backend/
β βββ app.py # Flask REST API
β βββ precise_runner.py # Mycroft Precise subprocess manager
β βββ actions.py # Action triggers (record, alert, etc.)
β βββ audio_utils.py # Audio recording and encryption
β βββ requirements.txt # Python dependencies
β βββ .env.example # Environment variables template
β βββ data/
β β βββ wake-word/ # Training samples for safe word
β β βββ not-wake-word/ # Training samples for other phrases
β β βββ recordings/ # Alert recordings (created automatically)
β βββ models/
β βββ wake-word.net # Trained model (created by training)
βββ frontend/
βββ package.json
βββ public/
β βββ index.html
βββ src/
βββ App.js # Main React app
βββ index.js
βββ index.css
βββ components/
βββ RecordSamples.js # Sample recording UI
βββ ModelTrainer.js # Model training UI
βββ DetectionControl.js # Detection controls
βββ ActionsConfig.js # Action configuration
http://127.0.0.1:5000| Endpoint | Method | Description |
|---|---|---|
/health |
GET | Health check |
/check-precise |
GET | Check if Precise is installed |
/record-sample |
POST | Upload audio sample for training |
/dataset-stats |
GET | Get training dataset statistics |
/train |
POST | Train wake word model |
/start-detection |
POST | Start listening for wake word |
/stop-detection |
POST | Stop listening |
/status |
GET | Get system status |
/trigger-action |
POST | Manually trigger actions (testing) |
/configure-actions |
POST | Update action configuration |
curl -X POST -F "file=@sample.wav" -F "label=wake-word" http://127.0.0.1:5000/record-sample
curl -X POST -H "Content-Type: application/json" \
-d '{"epochs": 10}' \
http://127.0.0.1:5000/train
curl -X POST -H "Content-Type: application/json" \
-d '{"threshold": 0.5}' \
http://127.0.0.1:5000/start-detection
curl -X POST http://127.0.0.1:5000/trigger-action
curl http://127.0.0.1:5000/status
.env)# Flask
FLASK_APP=app.py
FLASK_ENV=development
# Encryption (for recording encryption)
ENCRYPTION_KEY=your-secure-key-here
# Twilio (for SMS - optional, not yet implemented)
TWILIO_ACCOUNT_SID=your-twilio-sid
TWILIO_AUTH_TOKEN=your-twilio-token
TWILIO_FROM_NUMBER=+1234567890
# SMTP (for Email - optional, not yet implemented)
SMTP_SERVER=smtp.gmail.com
SMTP_PORT=587
SMTP_USERNAME=your-email@gmail.com
SMTP_PASSWORD=your-app-password
Configure via the React UI or POST to /configure-actions:
{
"record_duration": 30,
"encrypt_recordings": true,
"grace_period": 0,
"contacts": [
{"phone": "+1234567890", "email": "contact@example.com"}
]
}
Error: precise-train or precise-listen command not found
Solution:
pip install precise-runner
# Or install from source: https://github.com/MycroftAI/mycroft-precise
macOS:
brew install portaudio
pip install pyaudio
Ubuntu/Debian:
sudo apt-get install portaudio19-dev
pip install pyaudio
Windows:
pip install pipwin
pipwin install pyaudio
β οΈ Disclaimer: This is a prototype for educational/personal use. For production safety applications, conduct thorough testing and security audits.
This project is provided as-is for educational and personal use.
Contributions welcome! Areas for improvement:
Stay Safe! π‘οΈ
For questions or issues, please open a GitHub issue.