Views
No views yet
Common-Voice-Gender-Detection is a fine-tuned version offacebook/wav2vec2-base-960hfor binary audio classification, specifically trained to detect speaker gender as female or male. This model leverages theWav2Vec2ForSequenceClassificationarchitecture for efficient and accurate voice-based gender classification.
[!note] Wav2Vec2: Self-Supervised Learning for Speech Recognition : https://arxiv.org/pdf/2006.11477
1Classification Report:
2
3 precision recall f1-score support
4
5 female 0.9705 0.9916 0.9809 2622
6 male 0.9943 0.9799 0.9870 3923
7
8 accuracy 0.9846 6545
9 macro avg 0.9824 0.9857 0.9840 6545
10weighted avg 0.9848 0.9846 0.9846 6545Class 0: female
Class 1: malepip install gradio transformers torch librosa hf_xet1import gradio as gr
2from transformers import Wav2Vec2ForSequenceClassification, Wav2Vec2FeatureExtractor
3import torch
4import librosa
5
6# Load model and processor
7model_name = "prithivMLmods/Common-Voice-Geneder-Detection"
8model = Wav2Vec2ForSequenceClassification.from_pretrained(model_name)
9processor = Wav2Vec2FeatureExtractor.from_pretrained(model_name)
10
11# Label mapping
12id2label = {
13 "0": "female",
14 "1": "male"
15}
16
17def classify_audio(audio_path):
18 # Load and resample audio to 16kHz
19 speech, sample_rate = librosa.load(audio_path, sr=16000)
20
21 # Process audio
22 inputs = processor(
23 speech,
24 sampling_rate=sample_rate,
25 return_tensors="pt",
26 padding=True
27 )
28
29 with torch.no_grad():
30 outputs = model(**inputs)
31 logits = outputs.logits
32 probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
33
34 prediction = {
35 id2label[str(i)]: round(probs[i], 3) for i in range(len(probs))
36 }
37
38 return prediction
39
40# Gradio Interface
41iface = gr.Interface(
42 fn=classify_audio,
43 inputs=gr.Audio(type="filepath", label="Upload Audio (WAV, MP3, etc.)"),
44 outputs=gr.Label(num_top_classes=2, label="Gender Classification"),
45 title="Common Voice Gender Detection",
46 description="Upload an audio clip to classify the speaker's gender as female or male."
47)
48
49if __name__ == "__main__":
50 iface.launch()[!note] male
[!note] female
Common-Voice-Gender-Detection is designed for: