π₯ Fuzzu Voice AI - Real-Time Gender & Age Detector using Python | Viral Tech Demo
Demo :
Click Video πππ
Features:
-
Voice recording with
sounddevice
-
Feature extraction with
librosa
-
ML prediction using dummy models
-
Tkinter GUI interface
Code :
import os
import librosa
import numpy as np
import sounddevice as sd
import scipy.io.wavfile as wav
from sklearn.preprocessing import StandardScaler
from tkinter import *
from tkinter import messagebox
# Constants
DURATION = 5 # seconds
SAMPLE_RATE = 22050
FILENAME = "record.wav"
# Dummy model simulation (mocked for this example)
def load_models():
class DummyModel:
def predict(self, X):
return ["Male"] if np.mean(X) > 0 else ["Female"]
class DummyAgeModel:
def predict(self, X):
avg = np.mean(X)
if avg < -5:
return ["Child"]
elif avg < 0:
return ["Teen"]
elif avg < 5:
return ["Adult"]
else:
return ["Senior"]
return DummyModel(), DummyAgeModel()
gender_model, age_model = load_models()
# Record function
def record_audio():
print("Recording started...")
audio = sd.rec(int(DURATION * SAMPLE_RATE), samplerate=SAMPLE_RATE, channels=1)
sd.wait()
# Normalize and convert to int16 before saving
audio = audio.flatten()
audio = np.int16(audio / np.max(np.abs(audio)) * 32767)
wav.write(FILENAME, SAMPLE_RATE, audio)
print("Recording saved as record.wav")
# Extract MFCCs
def extract_features(file_path):
y, sr = librosa.load(file_path, sr=SAMPLE_RATE)
mfcc = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=13)
scaler = StandardScaler()
mfcc_scaled = scaler.fit_transform(mfcc.T)
mfcc_mean = np.mean(mfcc_scaled, axis=0)
return mfcc_mean.reshape(1, -1)
# Predict using dummy models
def predict():
if not os.path.exists(FILENAME):
messagebox.showwarning("Warning", "Please record audio first!")
return
features = extract_features(FILENAME)
gender = gender_model.predict(features)[0]
age = age_model.predict(features)[0]
result = f"Predicted Gender: {gender}\nPredicted Age Group: {age}"
messagebox.showinfo("Prediction", result)
# GUI setup
root = Tk()
root.title("Fuzzu Voice AI - Gender & Age Detector")
root.geometry("400x300")
root.config(bg="#1e1e2f")
title = Label(root, text="π€ Voice Gender & Age Detector", fg="white", bg="#1e1e2f", font=("Helvetica", 16))
title.pack(pady=20)
record_btn = Button(root, text="π️ Record", font=("Helvetica", 14), command=record_audio, bg="#4caf50", fg="white", padx=10, pady=5)
record_btn.pack(pady=10)
predict_btn = Button(root, text="π€ Predict", font=("Helvetica", 14), command=predict, bg="#2196f3", fg="white", padx=10, pady=5)
predict_btn.pack(pady=10)
root.mainloop()
Comments
Post a Comment