|
<!DOCTYPE html> |
|
<html lang="en"> |
|
<head> |
|
<meta charset="UTF-8"> |
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
<title>SKYNET Voice Authentication</title> |
|
<style> |
|
body, html { |
|
height: 100%; |
|
margin: 0; |
|
font-family: Arial, sans-serif; |
|
color: white; |
|
text-align: center; |
|
} |
|
.bg { |
|
background-image: url('/static/skynet.png'); |
|
height: 100%; |
|
background-position: center; |
|
background-repeat: no-repeat; |
|
background-size: cover; |
|
position: relative; |
|
} |
|
.content { |
|
position: absolute; |
|
bottom: 10%; |
|
width: 100%; |
|
} |
|
.controls { |
|
display: flex; |
|
justify-content: center; |
|
align-items: center; |
|
} |
|
.button { |
|
background-color: red; |
|
color: white; |
|
padding: 10px 20px; |
|
border: none; |
|
border-radius: 5px; |
|
font-size: 16px; |
|
cursor: pointer; |
|
margin: 5px; |
|
} |
|
.button:hover { |
|
background-color: darkred; |
|
} |
|
audio { |
|
margin: 0 20px; |
|
} |
|
</style> |
|
</head> |
|
<body> |
|
|
|
<div class="bg"> |
|
<div class="content"> |
|
<h1>Voice Authentication</h1> |
|
<div class="controls"> |
|
<button id="recordButton" class="button">Record</button> |
|
<button id="stopButton" class="button" disabled>Stop</button> |
|
<audio id="audioPlayback" controls style="display:none;"></audio> |
|
<button id="submitButton" class="button" style="float:right; display:none;">Submit</button> |
|
</div> |
|
<p id="result"></p> |
|
</div> |
|
</div> |
|
|
|
<script> |
|
let recordButton = document.getElementById('recordButton'); |
|
let stopButton = document.getElementById('stopButton'); |
|
let audioPlayback = document.getElementById('audioPlayback'); |
|
let submitButton = document.getElementById('submitButton'); |
|
|
|
let mediaRecorder; |
|
let audioBlob; |
|
let audioChunks = []; |
|
|
|
recordButton.onclick = function() { |
|
navigator.mediaDevices.getUserMedia({ audio: true }) |
|
.then(stream => { |
|
mediaRecorder = new MediaRecorder(stream); |
|
mediaRecorder.start(); |
|
audioChunks = []; |
|
|
|
document.getElementById("result").innerHTML = "recording started"; |
|
stopButton.disabled = false; |
|
recordButton.disabled = true; |
|
|
|
mediaRecorder.ondataavailable = function(event) { |
|
audioChunks.push(event.data); |
|
}; |
|
|
|
mediaRecorder.onstop = function() { |
|
document.getElementById("result").innerHTML = "recording stopped"; |
|
audioBlob = new Blob(audioChunks); |
|
let audioUrl = URL.createObjectURL(audioBlob); |
|
audioPlayback.src = audioUrl; |
|
audioPlayback.style.display = 'block'; |
|
}; |
|
}); |
|
}; |
|
|
|
stopButton.onclick = function() { |
|
mediaRecorder.stop(); |
|
stopButton.disabled = true; |
|
recordButton.disabled = false; |
|
submitButton.style.display = 'block'; |
|
}; |
|
|
|
|
|
submitButton.onclick = async function() { |
|
document.getElementById("result").innerHTML = "Processing..." |
|
|
|
console.log('Submit the audio for processing'); |
|
let formData = new FormData(); |
|
formData.append('audio_data', audioBlob); |
|
fetch('/compare_audio2', { |
|
method: 'POST', |
|
body: formData |
|
}) |
|
.then(response => response.json()) |
|
.then(data => { |
|
document.getElementById("result").innerHTML = data.result; |
|
}) |
|
.catch(error => console.error('Error:', error)); |
|
}; |
|
</script> |
|
|
|
</body> |
|
</html> |
|
|
|
|