README.md
4.3 KB · 146 lines · markdown Raw
1 ---
2 license: apache-2.0
3 language:
4 - en
5 base_model:
6 - facebook/wav2vec2-base-960h
7 pipeline_tag: audio-classification
8 library_name: transformers
9 tags:
10 - voice-gender-detection
11 - male
12 - female
13 - biology
14 - SFT
15 ---
16
17 ![1](https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/PRzOX8J8j0q_7ruSI9VZx.png)
18
19 # Common-Voice-Gender-Detection
20
21 > **Common-Voice-Gender-Detection** is a fine-tuned version of `facebook/wav2vec2-base-960h` for **binary audio classification**, specifically trained to detect speaker gender as **female** or **male**. This model leverages the `Wav2Vec2ForSequenceClassification` architecture for efficient and accurate voice-based gender classification.
22
23 > [!note]
24 Wav2Vec2: Self-Supervised Learning for Speech Recognition : [https://arxiv.org/pdf/2006.11477](https://arxiv.org/pdf/2006.11477)
25
26 ```py
27 Classification Report:
28
29 precision recall f1-score support
30
31 female 0.9705 0.9916 0.9809 2622
32 male 0.9943 0.9799 0.9870 3923
33
34 accuracy 0.9846 6545
35 macro avg 0.9824 0.9857 0.9840 6545
36 weighted avg 0.9848 0.9846 0.9846 6545
37 ```
38
39 ![download.png](https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/pBnrVbG8uyZYq6Nb4GOuG.png)
40
41 ![download (1).png](https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/QtZdfaXE-W-C4QDZUWuVC.png)
42
43 ---
44
45 ## Label Space: 2 Classes
46
47 ```
48 Class 0: female
49 Class 1: male
50 ```
51
52 ---
53
54 ## Install Dependencies
55
56 ```bash
57 pip install gradio transformers torch librosa hf_xet
58 ```
59
60 ---
61
62 ## Inference Code
63
64 ```python
65 import gradio as gr
66 from transformers import Wav2Vec2ForSequenceClassification, Wav2Vec2FeatureExtractor
67 import torch
68 import librosa
69
70 # Load model and processor
71 model_name = "prithivMLmods/Common-Voice-Geneder-Detection"
72 model = Wav2Vec2ForSequenceClassification.from_pretrained(model_name)
73 processor = Wav2Vec2FeatureExtractor.from_pretrained(model_name)
74
75 # Label mapping
76 id2label = {
77 "0": "female",
78 "1": "male"
79 }
80
81 def classify_audio(audio_path):
82 # Load and resample audio to 16kHz
83 speech, sample_rate = librosa.load(audio_path, sr=16000)
84
85 # Process audio
86 inputs = processor(
87 speech,
88 sampling_rate=sample_rate,
89 return_tensors="pt",
90 padding=True
91 )
92
93 with torch.no_grad():
94 outputs = model(**inputs)
95 logits = outputs.logits
96 probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
97
98 prediction = {
99 id2label[str(i)]: round(probs[i], 3) for i in range(len(probs))
100 }
101
102 return prediction
103
104 # Gradio Interface
105 iface = gr.Interface(
106 fn=classify_audio,
107 inputs=gr.Audio(type="filepath", label="Upload Audio (WAV, MP3, etc.)"),
108 outputs=gr.Label(num_top_classes=2, label="Gender Classification"),
109 title="Common Voice Gender Detection",
110 description="Upload an audio clip to classify the speaker's gender as female or male."
111 )
112
113 if __name__ == "__main__":
114 iface.launch()
115 ```
116
117 ---
118
119 ## Demo Inference
120
121 > [!note]
122 male
123
124 <audio controls src="https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/7woMf3_bgX_D99-1Uy3jH.mpga"></audio>
125
126 ![Screenshot 2025-05-31 at 20-19-39 Common Voice Gender Detection.png](https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/h1LqWmWbyi3ao2yvSWQSI.png)
127
128
129 > [!note]
130 female
131
132 <audio controls src="https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/0d2rDf_DT-gjRWBwiPbm_.mpga"></audio>
133
134 ![Screenshot 2025-05-31 at 20-21-57 Common Voice Gender Detection.png](https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/TTAKrOOZ2sCS846wZWani.png)
135
136 ---
137
138 ## Intended Use
139
140 `Common-Voice-Gender-Detection` is designed for:
141
142 * **Speech Analytics** – Assist in analyzing speaker demographics in call centers or customer service recordings.
143 * **Conversational AI Personalization** – Adjust tone or dialogue based on gender detection for more personalized voice assistants.
144 * **Voice Dataset Curation** – Automatically tag or filter voice datasets by speaker gender for better dataset management.
145 * **Research Applications** – Enable linguistic and acoustic research involving gender-specific speech patterns.
146 * **Multimedia Content Tagging** – Automate metadata generation for gender identification in podcasts, interviews, or video content.