Download feature_extraction.py from Ibrahim2017/scam-shield-logistic-regression: direct link, hf CLI and curl.
- Browser
- Download file 833 Bytes
-
https://huggingface.co/Ibrahim2017/scam-shield-logistic-regression/resolve/main/feature_extraction.py
- Command line
-
hf download hf://Ibrahim2017/scam-shield-logistic-regression/feature_extraction.py
-
curl -L -o feature_extraction.py https://huggingface.co/Ibrahim2017/scam-shield-logistic-regression/resolve/main/feature_extraction.py
833 Bytes
| # Scam Shield - Audio Feature Extraction | |
| # Prepare 26 MFCC-based features for Logistic Regression | |
| import librosa | |
| import numpy as np | |
| def extract_features(audio_file): | |
| # Load audio at 16 kHz in mono | |
| audio, sample_rate = librosa.load( | |
| audio_file, | |
| sr=16000, | |
| mono=True | |
| ) | |
| if len(audio) == 0: | |
| raise ValueError("The audio recording is empty.") | |
| # Extract 13 MFCC coefficients | |
| mfcc = librosa.feature.mfcc( | |
| y=audio, | |
| sr=sample_rate, | |
| n_mfcc=13 | |
| ) | |
| # Calculate mean and standard deviation | |
| mfcc_mean = np.mean(mfcc, axis=1) | |
| mfcc_std = np.std(mfcc, axis=1) | |
| # Combine into 26 features | |
| features = np.concatenate([ | |
| mfcc_mean, | |
| mfcc_std | |
| ]) | |
| # Return one sample containing 26 features | |
| return features.reshape(1, -1) | |