muzammil-eds commited on
Commit
9a9b4ca
·
verified ·
1 Parent(s): 9997b92

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +161 -41
index.html CHANGED
@@ -4,57 +4,116 @@
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Audio Transcription and Similarity Checker</title>
 
7
  <style>
8
  body {
9
- font-family: Arial, sans-serif;
10
  background-color: #f4f4f4;
11
  padding: 20px;
12
  }
13
  .container {
14
- max-width: 700px;
15
  margin: 0 auto;
16
  background: #fff;
17
- padding: 20px;
18
- box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
 
19
  }
20
  h1 {
21
  text-align: center;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  }
23
  .button {
24
- background-color: #e8b62c;
25
  color: white;
26
  padding: 10px 20px;
27
- text-align: center;
28
  cursor: pointer;
29
  border: none;
30
- margin-top: 10px;
 
31
  display: block;
32
  width: 100%;
 
33
  }
34
- .audio-upload {
35
- margin-top: 20px;
 
 
 
 
 
36
  text-align: center;
 
 
 
 
 
 
 
 
 
 
37
  }
38
  .result {
39
  margin-top: 20px;
40
  }
 
 
 
 
 
 
 
 
 
 
41
  </style>
42
  </head>
43
  <body>
44
  <div class="container">
45
  <h1>Audio Transcription and Similarity Checker</h1>
46
- <div id="original-audio" class="audio-upload">
 
47
  <h2>Upload Original Audio</h2>
 
48
  <input type="file" id="originalFile" accept="audio/*">
 
 
 
49
  </div>
50
 
51
- <div id="user-audio" class="audio-upload">
52
  <h2>Upload User Audio</h2>
 
53
  <input type="file" id="userFile" accept="audio/*">
 
 
 
54
  </div>
55
 
56
  <button id="transcribeButton" class="button">Perform Transcription and Testing</button>
57
 
 
 
 
 
58
  <div id="result" class="result"></div>
59
  </div>
60
 
@@ -62,6 +121,8 @@
62
  <script>
63
  const MODEL_ID = "facebook/wav2vec2-large-960h"; // Sample model, change if necessary
64
  let processor, model;
 
 
65
 
66
  // Load model and processor
67
  async function loadModel() {
@@ -69,10 +130,25 @@
69
  model = await transformers.Wav2Vec2ForCTC.from_pretrained(MODEL_ID);
70
  }
71
 
72
- async function transcribe(audioFile) {
73
- const arrayBuffer = await audioFile.arrayBuffer();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  const audioData = new Float32Array(arrayBuffer);
75
-
76
  const inputValues = processor(audioData, {return_tensors: "pt", padding: true}).input_values;
77
  const logits = await model(inputValues).logits;
78
  const predicted_ids = logits.argmax(-1);
@@ -81,39 +157,83 @@
81
  }
82
 
83
  document.getElementById("transcribeButton").addEventListener("click", async () => {
84
- const originalFile = document.getElementById("originalFile").files[0];
85
- const userFile = document.getElementById("userFile").files[0];
86
-
87
- if (originalFile && userFile) {
88
- const transcriptionOriginal = await transcribe(originalFile);
89
- const transcriptionUser = await transcribe(userFile);
90
-
91
- const levenshteinDistance = (a, b) => {
92
- let dp = Array.from({length: a.length + 1}, () => Array(b.length + 1).fill(0));
93
- for (let i = 0; i <= a.length; i++) dp[i][0] = i;
94
- for (let j = 0; j <= b.length; j++) dp[0][j] = j;
95
- for (let i = 1; i <= a.length; i++) {
96
- for (let j = 1; j <= b.length; j++) {
97
- dp[i][j] = a[i - 1] === b[j - 1] ? dp[i - 1][j - 1] : Math.min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]) + 1;
98
- }
 
 
 
 
 
 
 
 
 
 
 
99
  }
100
- return dp[a.length][b.length];
101
- };
 
102
 
103
- const similarityScore = 1 - levenshteinDistance(transcriptionOriginal, transcriptionUser) / Math.max(transcriptionOriginal.length, transcriptionUser.length);
104
 
105
- document.getElementById("result").innerHTML = `
106
- <h2>Transcription Results</h2>
107
- <p><strong>Original Transcription:</strong> ${transcriptionOriginal}</p>
108
- <p><strong>User Transcription:</strong> ${transcriptionUser}</p>
109
- <p><strong>Levenshtein Similarity Score:</strong> ${similarityScore.toFixed(2)}</p>
110
- `;
111
- } else {
112
- alert("Please upload both audio files.");
113
- }
114
  });
115
 
 
116
  loadModel();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  </script>
118
  </body>
119
  </html>
 
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Audio Transcription and Similarity Checker</title>
7
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
8
  <style>
9
  body {
10
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
11
  background-color: #f4f4f4;
12
  padding: 20px;
13
  }
14
  .container {
15
+ max-width: 800px;
16
  margin: 0 auto;
17
  background: #fff;
18
+ padding: 30px;
19
+ border-radius: 10px;
20
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
21
  }
22
  h1 {
23
  text-align: center;
24
+ margin-bottom: 30px;
25
+ }
26
+ .audio-section {
27
+ text-align: center;
28
+ margin-bottom: 20px;
29
+ }
30
+ input[type="file"] {
31
+ display: none;
32
+ }
33
+ .upload-btn {
34
+ background-color: #007bff;
35
+ color: white;
36
+ padding: 10px 20px;
37
+ cursor: pointer;
38
+ border-radius: 5px;
39
+ margin: 10px;
40
+ border: none;
41
+ display: inline-block;
42
  }
43
  .button {
44
+ background-color: #28a745;
45
  color: white;
46
  padding: 10px 20px;
 
47
  cursor: pointer;
48
  border: none;
49
+ border-radius: 5px;
50
+ margin-top: 20px;
51
  display: block;
52
  width: 100%;
53
+ font-size: 16px;
54
  }
55
+ .button:hover {
56
+ background-color: #218838;
57
+ }
58
+ #progress-bar {
59
+ width: 0;
60
+ height: 20px;
61
+ background-color: #4caf50;
62
  text-align: center;
63
+ line-height: 20px;
64
+ color: white;
65
+ border-radius: 5px;
66
+ display: none;
67
+ }
68
+ #progress-container {
69
+ width: 100%;
70
+ background-color: #ddd;
71
+ border-radius: 5px;
72
+ margin-top: 20px;
73
  }
74
  .result {
75
  margin-top: 20px;
76
  }
77
+ .recorder {
78
+ cursor: pointer;
79
+ background-color: #dc3545;
80
+ color: white;
81
+ padding: 10px 20px;
82
+ border-radius: 50%;
83
+ font-size: 24px;
84
+ display: inline-block;
85
+ margin-top: 20px;
86
+ }
87
  </style>
88
  </head>
89
  <body>
90
  <div class="container">
91
  <h1>Audio Transcription and Similarity Checker</h1>
92
+
93
+ <div id="original-audio" class="audio-section">
94
  <h2>Upload Original Audio</h2>
95
+ <label class="upload-btn" for="originalFile">Choose Audio File</label>
96
  <input type="file" id="originalFile" accept="audio/*">
97
+ <div id="originalRecorder" class="recorder">
98
+ <i class="fas fa-microphone"></i>
99
+ </div>
100
  </div>
101
 
102
+ <div id="user-audio" class="audio-section">
103
  <h2>Upload User Audio</h2>
104
+ <label class="upload-btn" for="userFile">Choose Audio File</label>
105
  <input type="file" id="userFile" accept="audio/*">
106
+ <div id="userRecorder" class="recorder">
107
+ <i class="fas fa-microphone"></i>
108
+ </div>
109
  </div>
110
 
111
  <button id="transcribeButton" class="button">Perform Transcription and Testing</button>
112
 
113
+ <div id="progress-container">
114
+ <div id="progress-bar">0%</div>
115
+ </div>
116
+
117
  <div id="result" class="result"></div>
118
  </div>
119
 
 
121
  <script>
122
  const MODEL_ID = "facebook/wav2vec2-large-960h"; // Sample model, change if necessary
123
  let processor, model;
124
+ let originalAudioBlob = null;
125
+ let userAudioBlob = null;
126
 
127
  // Load model and processor
128
  async function loadModel() {
 
130
  model = await transformers.Wav2Vec2ForCTC.from_pretrained(MODEL_ID);
131
  }
132
 
133
+ // Simulate progress bar loading
134
+ function updateProgressBar(percentComplete) {
135
+ const progressBar = document.getElementById("progress-bar");
136
+ progressBar.style.width = percentComplete + "%";
137
+ progressBar.innerHTML = percentComplete + "%";
138
+ if (percentComplete === 100) {
139
+ setTimeout(() => {
140
+ progressBar.style.display = "none";
141
+ progressBar.style.width = "0%";
142
+ }, 500);
143
+ } else {
144
+ progressBar.style.display = "block";
145
+ }
146
+ }
147
+
148
+ async function transcribe(audioBlob) {
149
+ const arrayBuffer = await audioBlob.arrayBuffer();
150
  const audioData = new Float32Array(arrayBuffer);
151
+
152
  const inputValues = processor(audioData, {return_tensors: "pt", padding: true}).input_values;
153
  const logits = await model(inputValues).logits;
154
  const predicted_ids = logits.argmax(-1);
 
157
  }
158
 
159
  document.getElementById("transcribeButton").addEventListener("click", async () => {
160
+ if (!originalAudioBlob || !userAudioBlob) {
161
+ alert("Please upload or record both audio files.");
162
+ return;
163
+ }
164
+
165
+ updateProgressBar(0);
166
+ let percentComplete = 0;
167
+ const progressInterval = setInterval(() => {
168
+ percentComplete += 10;
169
+ updateProgressBar(percentComplete);
170
+ if (percentComplete >= 100) clearInterval(progressInterval);
171
+ }, 200);
172
+
173
+ const transcriptionOriginal = await transcribe(originalAudioBlob);
174
+ const transcriptionUser = await transcribe(userAudioBlob);
175
+
176
+ clearInterval(progressInterval);
177
+ updateProgressBar(100);
178
+
179
+ const levenshteinDistance = (a, b) => {
180
+ let dp = Array.from({length: a.length + 1}, () => Array(b.length + 1).fill(0));
181
+ for (let i = 0; i <= a.length; i++) dp[i][0] = i;
182
+ for (let j = 0; j <= b.length; j++) dp[0][j] = j;
183
+ for (let i = 1; i <= a.length; i++) {
184
+ for (let j = 1; j <= b.length; j++) {
185
+ dp[i][j] = a[i - 1] === b[j - 1] ? dp[i - 1][j - 1] : Math.min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]) + 1;
186
  }
187
+ }
188
+ return dp[a.length][b.length];
189
+ };
190
 
191
+ const similarityScore = 1 - levenshteinDistance(transcriptionOriginal, transcriptionUser) / Math.max(transcriptionOriginal.length, transcriptionUser.length);
192
 
193
+ document.getElementById("result").innerHTML = `
194
+ <h2>Transcription Results</h2>
195
+ <p><strong>Original Transcription:</strong> ${transcriptionOriginal}</p>
196
+ <p><strong>User Transcription:</strong> ${transcriptionUser}</p>
197
+ <p><strong>Levenshtein Similarity Score:</strong> ${similarityScore.toFixed(2)}</p>
198
+ `;
 
 
 
199
  });
200
 
201
+ // Initialize model
202
  loadModel();
203
+
204
+ // Handle voice recording (using browser APIs)
205
+ const recordAudio = () => {
206
+ return new Promise(async resolve => {
207
+ const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
208
+ const mediaRecorder = new MediaRecorder(stream);
209
+ const audioChunks = [];
210
+
211
+ mediaRecorder.addEventListener("dataavailable", event => {
212
+ audioChunks.push(event.data);
213
+ });
214
+
215
+ mediaRecorder.addEventListener("stop", () => {
216
+ const audioBlob = new Blob(audioChunks);
217
+ resolve(audioBlob);
218
+ });
219
+
220
+ mediaRecorder.start();
221
+
222
+ setTimeout(() => {
223
+ mediaRecorder.stop();
224
+ }, 3000); // Record for 3 seconds
225
+ });
226
+ };
227
+
228
+ document.getElementById("originalRecorder").addEventListener("click", async () => {
229
+ originalAudioBlob = await recordAudio();
230
+ alert("Original audio recorded!");
231
+ });
232
+
233
+ document.getElementById("userRecorder").addEventListener("click", async () => {
234
+ userAudioBlob = await recordAudio();
235
+ alert("User audio recorded!");
236
+ });
237
  </script>
238
  </body>
239
  </html>