- Scam Shield β Human vs AI-Generated Voice Detection
Scam Shield β Human vs AI-Generated Voice Detection
Overview
Scam Shield is an Agile Processes group project developed to help identify potentially suspicious voice communications.
As part of our project, we developed and trained machine-learning models to distinguish between human and AI-generated speech.
We trained and evaluated Logistic Regression and Support Vector Machine (SVM) models using 58 labelled audio recordings (30 human and 28 AI-generated). Each recording was processed to extract 26 MFCC-based audio features.
Following model evaluation, we selected Logistic Regression as our preferred model based on its performance on the held-out test dataset.
Our trained model is stored on Hugging Face and integrated with a Flask prediction API, which processes WAV recordings and returns either:
- HUMAN VOICE (0)
- AI-GENERATED VOICE (1)
The API has been successfully tested using recordings from both categories and is ready for integration with the Scam Shield Admin Website.
Important distinction: Our machine-learning model identifies whether speech is human or AI-generated. It does not directly determine whether a call is fraudulent. Our separate Speech-to-Text and suspicious-language detection components analyse potential scam indicators.
Files in this model repository
| File | Purpose |
|---|---|
logistic_regression.joblib |
Trained StandardScaler + LogisticRegression pipeline. |
feature_extraction.py |
Converts an audio file into the 26 features expected by the model. |
requirements.txt |
Python packages required for inference and downloading from Hugging Face. |
README.md |
Model information and integration instructions. |
How input audio is processed
The model does not accept a raw WAV file directly. Its input must be generated using the same feature-extraction procedure used for training:
- Load audio with Librosa, resample to 16,000 Hz, and convert to mono.
- Extract 13 MFCC coefficients (
librosa.feature.mfcc(..., n_mfcc=13)). - Calculate the mean of each MFCC coefficient across frames (13 values).
- Calculate the standard deviation of each MFCC coefficient across frames (13 values).
- Concatenate means first, standard deviations second, yielding 26 features with array shape
(1, 26). - Pass the features into the saved pipeline, which already includes
StandardScaler.
The returned class is 0 = HUMAN or 1 = AI-GENERATED.
Training and evaluation summary
Original labelled dataset: 58 recordings (30 human, 28 AI-generated).
Training / held-out test split: 46 / 12 recordings (80% / 20%, stratified;
random_state=42).Logistic Regression held-out accuracy: 83.33% (10 of 12 correct).
Held-out confusion matrix (rows = true; columns = predicted, order Human, AI-generated):
Actual / predicted Human (0) AI-generated (1) Human (0) 5 1 AI-generated (1) 1 5 Compared SVM model: 66.67% (8 of 12) held-out accuracy on the same split.
The Logistic Regression model was selected provisionally based on these held-out results. The test set is small, so these numbers should not be treated as reliable real-world performance estimates.
Installation and Dependencies
The Scam Shield machine-learning component uses Python, Scikit-learn, Librosa, NumPy and Joblib.
We successfully tested our trained Logistic Regression model in Google Cloud Shell using Python 3.12 and Scikit-learn 1.9.1.
The required libraries are listed in requirements.txt and can be installed using:
python -m pip install -r requirements.txt
We use compatible library versions to ensure that the trained model can be loaded correctly without retraining.
Local Model Testing
We developed and tested our Logistic Regression model using human and AI-generated voice recordings.
The local prediction process involves:
- Loading our saved
logistic_regression.joblibmodel. - Processing a WAV recording using
feature_extraction.py. - Extracting 26 MFCC-based audio features.
- Predicting whether the recording contains HUMAN (0) or AI-GENERATED (1) speech.
Our model was successfully tested with both recording categories.
For the Admin Website integration, we developed prediction_api.py, which connects the trained model to a Flask API. This allows our application to receive audio recordings and return classification results in JSON format.
import joblib
from feature_extraction import extract_features
model = joblib.load("logistic_regression.joblib")
features = extract_features("recording.wav") # shape: (1, 26)
prediction = int(model.predict(features)[0])
label = "AI-GENERATED VOICE" if prediction == 1 else "HUMAN VOICE"
print(label)
Only load .joblib files from a trusted source. This serialization format can execute code when loaded.
Download the Model from Hugging Face in a Python Backend
For the Scam Shield application, we use the huggingface_hub Python library to download our trained Logistic Regression model from our public Hugging Face repository.
The feature_extraction.py file is used alongside the model to extract 26 MFCC-based features from uploaded audio recordings.
Our Flask prediction API (prediction_api.py) connects these components, processes WAV recordings and returns either HUMAN (0) or AI-GENERATED (1).
This allows us to integrate our trained machine-learning model with the Scam Shield Admin Website without retraining it.
import joblib
from huggingface_hub import hf_hub_download
from feature_extraction import extract_features
model_path = hf_hub_download(
repo_id="Ibrahim2017/scam-shield-logistic-regression",
filename="logistic_regression.joblib",
)
model = joblib.load(model_path)
features = extract_features("recording.wav")
prediction = int(model.predict(features)[0])
result = "AI-GENERATED VOICE" if prediction == 1 else "HUMAN VOICE"
print(result)
Public Model Access
The Scam Shield Logistic Regression model repository is public.
Our Agile Processes team can download the trained model, feature-extraction code and supporting files without authentication.
The model has been successfully tested using human and AI-generated recordings.
To connect the Admin Website, the team must run or deploy the Flask prediction API. The website can then send WAV recordings to the /predict endpoint and receive Human or AI-generated predictions.
Connecting the Scam Shield Admin Website
The integration is not a hosted inference API. A Hugging Face model repository stores files but does not run the Python classifier for you.
The Admin Website's Python backend (or a separate inference service) must:
- Receive an uploaded audio recording securely.
- Validate the file and convert it to the 26 MFCC-derived features using
extract_features. - Load the trusted model using Joblib, ideally once when the server starts.
- Call
model.predict(features). - Send the predicted class (
0/1) and human-readable label to the website.
The web frontend should call the team's backend API, not attempt to execute the .joblib model in a browser. The team must provide the API route, authentication, input limits and error handling as part of website integration.
Demonstrated functionality and limitations
- The saved pipeline was successfully loaded in Google Cloud Shell and accepts 26 features.
- A human-labelled recording (
1001.wav) produced HUMAN VOICE. - An AI-generated-labelled recording (
1.wav) produced AI-GENERATED VOICE. - These individual examples demonstrate that inference runs; they are not independent accuracy tests because the recordings may have appeared in model training.
- Performance needs further evaluation on a larger, independent, speaker-disjoint dataset and real deployment conditions before relying on predictions.
- The model cannot determine the safety of a call or establish whether a speaker is committing fraud.
Project Source
The Scam Shield application was developed collaboratively as part of our MTU Agile Processes group project.
Our source code, machine-learning scripts, audio preprocessing, feature extraction and application components are maintained in our shared GitHub repository:
GitHub Repository: Agile-Processes-
The main Python files associated with our machine-learning implementation include:
python/models/logisticRegression.pyβ Trains and evaluates our Logistic Regression model.python/models/SVM.pyβ Trains and evaluates our Support Vector Machine model.python/features/extract_58_features.pyβ Extracts MFCC-based features from the labelled audio dataset.python/features/feature_extraction.pyβ Prepares 26 features from individual recordings for prediction.python/features/prediction_api.pyβ Provides the Flask API for connecting our trained Hugging Face model to the Scam Shield Admin Website.
We use GitHub for version control, code collaboration and Pull Request reviews. Our selected trained model and supporting documentation are also available in our public Hugging Face model repository.