Update README.md
Browse files123---license: mit---123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141---license: mitdatasets:- LanceaKing/asvspoof2019language:- enmetrics:- accuracy---# DeepVoiceGuard: Real-Time Audio Authenticity Detection**DeepVoiceGuard** is an advanced AI-powered tool for detecting whether an audio file is genuine or AI-generated. Built using RawNet-based architecture and trained on ASVspoof datasets, this model is optimized for real-time inference using ONNX format.---## π Features- **Real-Time Detection:** Analyze audio files quickly and efficiently to determine authenticity.- **Sliding Window Processing:** Processes long audio files in segments for accurate classification.- **ONNX Optimized:** Faster inference compared to traditional formats.- **Interactive Demo:** Test the model using our Streamlit application.---## π Model Overview- **Architecture:** RawNet-based Neural Network- **Frameworks Used:** PyTorch, ONNX- **Dataset:** Trained on ASVspoof 2019 Challenge dataset(LA)- **Classes:**- **Real:** Genuine human speech- **Fake:** AI-generated or spoofed audio---## π InstallationInstall the necessary dependencies:```bashpip install onnxruntime librosa numpy requests streamlit```π§ How to UseUsing the ONNX Model```import streamlit as stimport librosaimport numpy as npimport onnxruntime as ortimport osimport requests# Audio padding functiondef pad(x, max_len=64600):"""Pad or trim an audio segment to a fixed length by repeating or slicing."""x_len = x.shape[0]if x_len >= max_len:return x[:max_len] # Trim if longer# Repeat to fill max_lennum_repeats = (max_len // x_len) + 1padded_x = np.tile(x, (1, num_repeats))[:, :max_len][0]return padded_x# Preprocess audio for a single segmentdef preprocess_audio_segment(segment, cut=64600):"""Preprocess a single audio segment: pad or trim as required."""segment = pad(segment, max_len=cut)return np.expand_dims(np.array(segment, dtype=np.float32), axis=0) # Add batch dimension# Download ONNX model from Hugging Facedef download_model(url, local_path="RawNet_model.onnx"):"""Download the ONNX model from a URL if it doesn't already exist locally."""if not os.path.exists(local_path):with st.spinner("Downloading ONNX model..."):response = requests.get(url)if response.status_code == 200:with open(local_path, "wb") as f:f.write(response.content)st.success("Model downloaded successfully!")else:raise Exception("Failed to download ONNX model")return local_path# Sliding window prediction functiondef predict_with_sliding_window(audio_path, onnx_model_path, window_size=64600, step_size=64600, sample_rate=16000):"""Use a sliding window to predict if the audio is real or fake over the entire audio."""# Load ONNX runtime sessionort_session = ort.InferenceSession(onnx_model_path)# Load audio filewaveform, _ = librosa.load(audio_path, sr=sample_rate)total_segments = []total_probabilities = []# Sliding window processingfor start in range(0, len(waveform), step_size):end = start + window_sizesegment = waveform[start:end]# Preprocess the segmentaudio_tensor = preprocess_audio_segment(segment)# Perform inferenceinputs = {ort_session.get_inputs()[0].name: audio_tensor}outputs = ort_session.run(None, inputs)probabilities = np.exp(outputs[0]) # Softmax probabilitiesprediction = np.argmax(probabilities)# Store the resultspredicted_class = "Real" if prediction == 1 else "Fake"total_segments.append(predicted_class)total_probabilities.append(probabilities[0][prediction])# Final aggregationmajority_class = max(set(total_segments), key=total_segments.count) # Majority votingavg_probability = np.mean(total_probabilities) * 100 # Average probability in percentagereturn majority_class, avg_probability# Exampleresult = predict("example.wav")print(f"Prediction: {result}")```π Performance MetricsEqual Error Rate (EER): 4.21%Accuracy: 95.8%ROC-AUC: 0.986π‘ LicenseThis project is licensed under the MIT License.βοΈ ContactFor inquiries or support, please contact:- GitHub: (Mrkomiljon)[https://github.com/Mrkomiljon/DeepVoiceGuard]- Hugging Face: (DeepVoiceGuard)[https://huggingface.co/spaces/Mrkomiljon/DeepVoiceGuard]
README.md+141-3