Document Audio_ML repository structure and architecture - #1
Document Audio_ML repository structure and architecture#1MehediEEE45 with Copilot wants to merge 6 commits into
Conversation
|
@copilot # 🎤 Audio Classification on STM32F746G-DISCO Real-Time Speaker Identification using MFCC + TensorFlow Lite MicroAuthor: Mehedi 📌 Project OverviewThis project implements a real-time speaker recognition system on the STM32F746G-DISCO board. 🔥 Key Features
🛠️ Hardware Used
🧰 Software & Libraries
📂 Project Structure. yaml 🎙️ Dataset Collection
pgsql 🔧 Split Audio into 1-Second Clipsfrom pydub import AudioSegment
import math, os
audio = AudioSegment.from_file("fa him.wav")
chunk_length_ms = 1000
os.makedirs("fa_him", exist_ok=True)
for i in range(math.ceil(len(audio)/chunk_length_ms)):
start = i * chunk_length_ms
end = start + chunk_length_ms
audio[start:end].export(f"fa_him/clip_{i+1:03}.wav", format="wav")
🎵 MFCC Feature Extraction
Extracted 40 MFCC coefficients per clip
Used librosa.feature.mfcc()
MFCC extraction pipeline:
Pre-emphasis
Framing
Hamming window
FFT
Mel filter banks
Log energy
DCT → MFCC
🤖 Model Training (Python)
Neural Network Architecture
text
Copy code
Input: 40 MFCC features
Layer 1: Dense(100) + ReLU + Dropout(0.20)
Layer 2: Dense(200) + ReLU + Dropout(0.20)
Layer 3: Dense(100) + ReLU + Dropout(0.20)
Output: Softmax (5 classes)
Training Script (simplified)
python
Copy code
model.compile(
loss='categorical_crossentropy',
optimizer='adam',
metrics=['accuracy']
)
model.fit(X_train, y_train, epochs=100, batch_size=32)
model.save("audio_classification_100.keras")
Achieved Accuracy
Type Accuracy
Offline training 99.8%
On-device ~70%
🧪 Converting Keras Model → TFLite Micro
Int8 Quantization
python
Copy code
converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.representative_dataset = rep_dataset_gen
converter.inference_input_type = tf.int8
converter.inference_output_type = tf.int8
tflite_model = converter.convert()
open("audio_class_quant.tflite", "wb").write(tflite_model)
TFLite Model Size
Copy code
audio_class_quant.tflite → 57.3 KB
Converted to C array:
Copy code
xx_model_data.cc
🧵 FreeRTOS Integration
Major Tasks
record.c → audio recording from WM8994
mfcc.c → MFCC extraction on MCU
ai_on() → run inference
display.c → show predicted speaker on LCD
role.c → application state machine
System Workflow
css
Copy code
Microphone → WM8994 → PCM → MFCC → NN Model → LCD Display
📊 Results
Metric Value
Real-time latency ~300 ms
Embedded accuracy ~70%
Max distance tested ~1 meter
Challenges
Background noise
Inconsistent speech loudness
RAM limitations for MFCC buffer + TFLite model
📸 Project Output
(Add images to docs/ and link here)
scss
Copy code




📎 References
STM32F746G-DISCO Reference Manual
TensorFlow Lite Micro Documentation
CMSIS-DSP
STM32CubeIDE, STM32CubeMX
📬 Contact
For contributions, issues, or discussions, feel free to open a GitHub issu |
Repository analysis per user request to understand the Audio_ML codebase.
Repository Overview
Embedded audio classification system for STM32F746G-Discovery board implementing real-time speaker recognition pipeline: audio capture → MFCC extraction → quantized neural network inference → LCD display.
Key Components Documented
Embedded C Application (~7.3K LOC)
AI Model (X-CUBE-AI)
Dataset: 416MB WAV files across 5 speaker classes
Python Training Pipeline: Jupyter notebooks for model training and audio preprocessing
Architecture
.iocconfigurationOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.