Aswin337 commited on
Commit
e633ada
Β·
verified Β·
1 Parent(s): c87102d

Upload 3 files

Browse files
Files changed (3) hide show
  1. app_voice.py +91 -0
  2. requirements.txt +5 -0
  3. voice_verifier_model.h5 +3 -0
app_voice.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """app_voice.ipynb
3
+
4
+ Automatically generated by Colab.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1op-dtpDLHXAJm53Q-2S04nNsQGjcz18G
8
+ """
9
+
10
+ import os
11
+ import numpy as np
12
+ import librosa
13
+ import gradio as gr
14
+ from tensorflow.keras.models import load_model
15
+ from sklearn.preprocessing import LabelEncoder
16
+ import warnings
17
+ warnings.filterwarnings("ignore")
18
+
19
+ # Load trained model
20
+ model = load_model("voice_verifier_model.h5")
21
+
22
+ # Load label encoder
23
+ encoder = LabelEncoder()
24
+ encoder.classes_ = np.array(['Fake', 'Real']) # Adjust if your label order is different
25
+
26
+ # Feature extraction
27
+ def extract_features(file_path):
28
+ try:
29
+ audio, sample_rate = librosa.load(file_path, duration=3, offset=0.5)
30
+ mfccs = librosa.feature.mfcc(y=audio, sr=sample_rate, n_mfcc=40)
31
+ return np.mean(mfccs.T, axis=0)
32
+ except Exception as e:
33
+ print("Audio processing error:", e)
34
+ return None
35
+
36
+ # Prediction function
37
+ def predict_audio(file):
38
+ features = extract_features(file)
39
+ if features is None:
40
+ return "⚠️ **Oops! Couldn't understand the audio. Try again with a clear `.wav` file.**"
41
+
42
+ features = features.reshape(1, -1)
43
+ probs = model.predict(features)[0]
44
+ index = np.argmax(probs)
45
+ label = encoder.inverse_transform([index])[0]
46
+ confidence = round(probs[index] * 100, 2)
47
+
48
+ if label.lower() == "real":
49
+ emoji = "πŸ§ πŸ—£οΈ"
50
+ msg = f"{emoji} **Real Human Voice Detected!**\n🟒 Confidence: **{confidence}%**"
51
+ advice = "βœ… No robots here. It's a real person!"
52
+ else:
53
+ emoji = "πŸ€–πŸŽ™οΈ"
54
+ msg = f"{emoji} **AI-Generated Voice Detected!**\nπŸ”΄ Confidence: **{confidence}%**"
55
+ advice = "⚠️ Synthetic voice detected. Be cautious!"
56
+
57
+ return f"{msg}\n\n{advice}"
58
+
59
+ # App description
60
+ description = """
61
+ πŸŽ™οΈ Welcome to **Voice Verifier 3000**
62
+ πŸ” Detect whether a voice is **REAL** or **AI-generated** using a deep learning model trained on human vs synthetic audio.
63
+
64
+ ---
65
+
66
+ ### πŸ€– Why Use This?
67
+ - πŸ›‘οΈ Catch deepfake voices in seconds
68
+ - πŸŽ™οΈ Validate voiceovers, interviews, or online calls
69
+ - πŸ” Useful for researchers, content moderators, or just curious minds
70
+
71
+ ---
72
+
73
+ ### πŸ“‚ How to Use:
74
+ 1. Upload a `.wav` file (3–5 seconds)
75
+ 2. Click **Submit**
76
+ 3. Instantly see the voice verdict with confidence level!
77
+
78
+ ---
79
+
80
+ πŸ”₯ Built with ❀️ using TensorFlow + Librosa + Gradio
81
+ """
82
+
83
+ # Gradio UI
84
+ gr.Interface(
85
+ fn=predict_audio,
86
+ inputs=gr.Audio(type="filepath", label="πŸ“‚ Upload your voice (.wav only)"),
87
+ outputs="markdown",
88
+ title="🧠 Voice Verifier 3000: Human vs AI Voice Detector",
89
+ description=description,
90
+ theme="default"
91
+ ).launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ librosa
2
+ numpy
3
+ scikit-learn
4
+ gradio
5
+ tensorflow
voice_verifier_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:65963c05efc171691f7c869ff1a4949a1ad586d05f1e7a2bdec26702915d8f9b
3
+ size 197064