-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex-mfcc.html
171 lines (148 loc) · 5.63 KB
/
index-mfcc.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<!DOCTYPE html>
<html>
<head>
<!-- <script src=”https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tf.min.js"></script>-->
<meta charset="UTF-8">
<title>BioPred</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="icon" type="image/png" href="img/icon.png">
</head>
<body>
<!-- <img src="img\menu.png" class="menu" onclick="togglemenu()">-->
<nav id="menu">
<ul>
<li><a href="about.html">ABOUT</a></li>
<li><a href="us.html">THE RESEARCHERS</a></li>
<li><a href="how.html">HOW IT WORKS</a></li>
</ul>
<h1>KBD: BIOPRED</h1>
</nav>
<!-- <div id="controls">-->
<!--<!– <button id="recordButton">RECORD</button>–>-->
<!-- <button id="uploadButton">UPLOAD FILES</button>-->
<!-- </div>-->
<!-- inserting these scripts at the end to be able to use all the elements in the DOM -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]"></script>
<div id="controls">
<div id="upload-form">
<div class="custom-file-input-wrapper">
<input type="file" id="audio-file" name="audio-file" accept="audio/*" class="custom-file-input">
<label for="audio-file" class="custom-file-input-label">Choose file</label>
</div>
<button id="process-btn" onclick="processAudio()">Process</button>
<button id="play-btn" disabled onclick="toggleAudioPlayback()">Play</button>
</div>
<p id="extractor-name-label">MFCC</p>
<p id="file-name-label">AUDIO FILE</p>
<p id="file-name"></p>
</div>
<div id="result">
<p id="age-label">Age:</p>
<p id="sex-label">Sex:</p>
<p id="weight-label">Weight:</p>
<p id="height-label">Height:</p>
</div>
<script>
//audio file
const fileInput = document.getElementById('audio-file');
const fileNameDisplay = document.getElementById('file-name');
const audioPlayer = document.createElement('audio');
audioPlayer.controls = true;
audioPlayer.style.display = 'none';
document.body.appendChild(audioPlayer);
fileInput.addEventListener('change', () => {
const file = fileInput.files[0];
fileNameDisplay.textContent = file ? file.name : '';
audioPlayer.src = URL.createObjectURL(file);
document.getElementById('play-btn').disabled = false;
});
function toggleAudioPlayback() {
if (audioPlayer.paused) {
audioPlayer.play();
} else {
audioPlayer.pause();
}
}
</script>
<script>
async function processAudio() {
console.log("sklkdsjf")
try {
// Load the model
console.log("processing")
const model = await tf.loadLayersModel('../mfcc_cnn_model/model.json');
console.log(model)
console.log("sdfsdf")
const fileInput = document.getElementById('audio-file');
const fileNameDisplay = document.getElementById('file-name');
const processButton = document.getElementById('process-btn');
fileInput.addEventListener('change', function() {
fileNameDisplay.textContent = fileInput.files[0].name;
});
console.log("processing started")
if (!fileInput.value) {
alert('Please select a file');
return;
}
processButton.textContent = 'Processing...';
processButton.disabled = true;
const file = fileInput.files[0];
const url = document.getElementById("audio-file").value
console.log("FIELLEFLWEKAFAWEKFLWE", url)
// fetch("http://localhost:8000/plp?path=" + url)
// .then(res => res.json())
// .then(data => console.log(data))
const formData = new FormData();
formData.append("audio_file", file);
const response = await fetch("http://localhost:8000/mfcc", {
method: "POST",
body: formData,
});
if (response.ok) {
const data = await response.json();
console.log("Predictions:", data);
console.log("type of data", typeof data)
// const age = predictionArray[0][0];
// const sex = predictionArray[0][1];
// const weight = predictionArray[0][2];
// const height = predictionArray[0][3];
// console.log("sd", age, sex, weight, height)
const resultDisplay = document.getElementById('result');
let ageLabel = document.getElementById('age-label');
let sexLabel = document.getElementById('sex-label');
let weightLabel = document.getElementById('weight-label');
let heightLabel = document.getElementById('height-label');
ageLabel.innerHTML = `Age: ${data["age"]}`;
sexLabel.innerHTML = `Sex: ${data["gender"] === "1.0" ? "Female" : "Male"}`;
weightLabel.innerHTML = `Weight: ${data["weight"]}`;
heightLabel.innerHTML = `Height: ${data["height"]}`;
processButton.textContent = 'Process';
processButton.disabled = false;
} else {
console.error("Failed to upload audio file.");
}
// // Add the following code to display the result section:
// document.getElementById('result').style.display = 'block';
// const audioContext = new AudioContext();
// const audioBuffer = await audioContext.decodeAudioData(await file.arrayBuffer());
// const audioTensor = tf.tidy(() => {
// const waveform = tf.tensor(audioBuffer.getChannelData(0));
// const batched = waveform.reshape([1, -1, 1]);
// const normalized = batched.div(32768.0);
// return normalized;
// });
//
// const prediction = await model.predict(audioTensor);
// const predictionArray = await prediction.array();
} catch (error) {
console.error('Error loading the model:', error);
}
}
</script>
</body>
<footer>
<!-- <p>KOBEDELTAPHI © 2023</p>-->
</footer>
</html>