An end-to-end Machine Learning and Audio Signal Processing pipeline for Spoken Language Identification (SLID) across four distinct human languages: German, Italian, Korean, and Spanish.
The system implements automated audio cleaning, silence removal, acoustic feature extraction (MFCCs, spectral moments, temporal zero-crossing rates), dimensionality reduction (PCA & LDA), unsupervised clustering analysis, and high-accuracy supervised classification reaching
graph TD
A[Raw Speech Audio .mp3 / .wav] --> B[Audio Preprocessing & Resampling 22.05 kHz]
B --> C[Silence Removal & Amplitude Normalization]
C --> D[Acoustic Feature Extraction 36 Dimensions]
subgraph Feature Space
D --> D1[13 MFCCs Mean & Std = 26 features]
D --> D2[Spectral Centroid, Bandwidth, Rolloff = 6 features]
D --> D3[Zero-Crossing Rate & RMS Energy = 4 features]
end
D1 & D2 & D3 --> E[StandardScaler Normalization]
E --> F[Dimensionality Reduction PCA / LDA]
subgraph Modeling & Evaluation
F --> G1[Unsupervised Clustering: K-Means & Agglomerative]
F --> G2[Supervised Classifiers: KNN, SVM-RBF, Random Forest]
end
G2 --> H[Final Prediction: German / Italian / Korean / Spanish]
-
Monophonic Resampling: All recordings are converted to single-channel mono and resampled to
$f_s = 22,050\text{ Hz}$ . -
Silence Removal: Trimming low-energy silence segments using an adaptive threshold set
$20\text{ dB}$ below peak frame amplitude (librosa.effects.trim). -
Amplitude Normalization: Peak normalization scaling amplitude vectors to
$[-1.0, +1.0]$ to eliminate volume bias across microphone hardware. -
Length Validation: Discarding truncated audio segments below
$1.0\text{ second}$ after trimming.
-
Mel-Frequency Cepstral Coefficients (MFCCs): 13 cepstral coefficients capturing vocal tract resonance shapes; both mean (
$\mu$ ) and standard deviation ($\sigma$ ) computed across temporal frames ($26\text{ features}$ ). -
Spectral Centroid (
$\mu, \sigma$ ): Frequency center of mass, reflecting perceived spectral sharpness/brightness ($2\text{ features}$ ). -
Spectral Bandwidth (
$\mu, \sigma$ ): Spectral spread around the centroid ($2\text{ features}$ ). -
Spectral Rolloff (
$\mu, \sigma$ ): Frequency below which$85%$ of total spectral energy is contained ($2\text{ features}$ ). -
Zero-Crossing Rate (ZCR) (
$\mu, \sigma$ ): Rate of sign alternation per frame, separating voiced vowels from unvoiced fricatives ($2\text{ features}$ ). -
Root-Mean-Square (RMS) Energy (
$\mu, \sigma$ ): Signal power envelope over time ($2\text{ features}$ ).
Standardized feature vectors (
- The first 9 principal components capture
$> 85%$ of cumulative variance. - The first 16 principal components capture
$95.32%$ of cumulative variance. - Projecting into reduced orthogonal subspaces effectively eliminates multi-collinearity and suppresses noise.
Clustering algorithms were evaluated without class labels to examine natural phonetic grouping:
-
K-Means Clustering (
$k = 4$ ):-
Silhouette Score:
$0.2733$ -
Overall Cluster Purity:
$61.38%$ - Spanish exhibited an isolated, pure cluster (
$100%$ purity,$90/90$ samples).
-
Silhouette Score:
-
Agglomerative Hierarchical Clustering (
$k = 4$ ):-
Silhouette Score:
$0.2547$ -
Overall Cluster Purity:
$58.99%$
-
Silhouette Score:
Models were trained on 520 balanced samples and evaluated on a holdout test set of 192 samples:
| Model Architecture | Hyperparameters | Test Accuracy | Macro Precision | Macro Recall | Macro F1-Score |
|---|---|---|---|---|---|
| K-Nearest Neighbors (KNN) |
|
||||
| Support Vector Machine (SVM) | RBF Kernel, |
||||
| Random Forest |
|
| Language | Precision | Recall | F1-Score | Support |
|---|---|---|---|---|
| German | 42 | |||
| Italian | 51 | |||
| Korean | 53 | |||
| Spanish | 46 | |||
| Overall / Macro Avg | 192 |
Spoken-Language-Identification-Audio-ML/
├── README.md
├── .gitignore
├── data/
│ ├── dataset_train.csv
│ ├── dataset_test.csv
│ └── features.csv
├── models/
│ ├── knn_model.pkl
│ ├── svm_model.pkl
│ ├── rf_model.pkl
│ ├── classes.npy
│ ├── X_test_processed.npy
│ └── y_test.npy
├── notebooks/
│ ├── 1_Data_Cleaning_and_Feature_Extraction.ipynb
│ ├── 2_Clustering_and_Unsupervised_Analysis.ipynb
│ ├── 3_Supervised_Classification.ipynb
│ └── 4_Model_Evaluation_and_Comparison.ipynb
└── src/
└── clip.py
Clone the repository and install required dependencies:
pip install numpy pandas scipy scikit-learn librosa soundfile matplotlib seaborn tqdmNavigate to the notebooks/ directory and execute sequentially:
1_Data_Cleaning_and_Feature_Extraction.ipynb: Cleans audio files and extracts 36 acoustic features.2_Clustering_and_Unsupervised_Analysis.ipynb: Runs PCA variance sweeps, K-Means, and Agglomerative clustering.3_Supervised_Classification.ipynb: Trains KNN, SVM, and Random Forest models and serializes checkpoints.4_Model_Evaluation_and_Comparison.ipynb: Computes confusion matrices, precision/recall curves, and cluster purity.
- Author: Danial Ghorbani
- LinkedIn: Danial Qorbani
- Degree: B.Sc. in Electrical Engineering (Electronics), Minor in Computer Engineering
- Course: Machine Learning
- Institution: School of Electrical and Computer Engineering, University of Tehran
- Contact: daniel.ghorbani.work@gmail.com