Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ hs_err_pid*
replay_pid*

# pycache
*.pyc
*.pyc

#
/.conda
/.venv
44 changes: 43 additions & 1 deletion Audio_Classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# Option 1
# Create a virtual environment
# $ python -m venv .venv
# Activate the virtual environment
# Run "python install_packages.py" to install the necessary packages

Expand All @@ -32,6 +33,7 @@
from feature_extraction.Feature_Extractor import generate_csv
from classifier.classifier import train_model
import joblib
from sklearn.metrics import classification_report

class AudioClassifierGUI:
def __init__(self, root):
Expand Down Expand Up @@ -107,11 +109,15 @@ def load_folder(self):
def extract_features_and_train(self, folder_path):
generate_csv(folder_path)
x_train, x_test, y_train, y_test, self.model, self.train_files, self.test_files, self.test_labels = train_model()

# Save the model for later use
joblib.dump(self.model, 'audio_classifier_model.pkl')

self.update_file_lists()

# Evaluate after training
self.evaluate_model_on_test_set()


def update_file_lists(self):
# Clear existing lists
self.train_listbox.delete(0, tk.END)
Expand Down Expand Up @@ -187,6 +193,42 @@ def play_audio(self):
# Play the audio file using pygame
pygame.mixer.music.load(file_path)
pygame.mixer.music.play()


def evaluate_model_on_test_set(self):
if not self.model:
self.model = joblib.load('audio_classifier_model.pkl')
scaler = joblib.load('scaler.pkl')

# Load all feature data
features_data = pd.read_csv('feature_extraction/features.csv')

y_true = []
y_pred = []

for file in self.test_files:
row = features_data[features_data['fileName'] == file]
if not row.empty and file in self.test_labels:
features = row.drop(["Label", "fileName"], axis=1)
normalized_features = scaler.transform(features)
prediction = self.model.predict(normalized_features)[0]

# Store ground truth and prediction
y_pred.append(prediction)
y_true.append(1 if self.test_labels[file] == "yes" else 0)
else:
print(f"Skipping {file} — missing features or label.")

# Create and print/save the report
report = classification_report(y_true, y_pred, target_names=["Speech", "Music"])

print("\n=== Evaluation Metrics ===")
print(report)

# Save to file
with open("evaluation_metrics.txt", "w") as f:
f.write("=== Evaluation Metrics ===\n")
f.write(report)

def print_summary(self):
print("File, Model Output, Ground Truth Label")
Expand Down
Binary file modified SVM_model.pkl
Binary file not shown.
Binary file modified audio_classifier_model.pkl
Binary file not shown.
9 changes: 9 additions & 0 deletions evaluation_metrics.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
=== Evaluation Metrics ===
precision recall f1-score support

Speech 1.00 0.78 0.88 9
Music 0.71 1.00 0.83 5

accuracy 0.86 14
macro avg 0.86 0.89 0.85 14
weighted avg 0.90 0.86 0.86 14
80 changes: 40 additions & 40 deletions feature_extraction/features.csv

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion install_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def install_package(package_name):
def main():
print("Checking and installing necessary Python packages for the Audio Classifier project...")

packages = ["pygame", "librosa", "scikit-learn"]
packages = ["pygame", "librosa", "scikit-learn", "pandas"]

for package in packages:
if is_package_installed(package):
Expand Down
Binary file modified scaler.pkl
Binary file not shown.