Spaces:
Sleeping
Sleeping
Update static/js/design.js
Browse files- static/js/design.js +16 -10
static/js/design.js
CHANGED
@@ -2,9 +2,12 @@ let isRecording = false;
|
|
2 |
let mediaRecorder;
|
3 |
let recordedChunks = [];
|
4 |
|
|
|
5 |
const micContainer = document.getElementsByClassName('mic-container')[0];
|
6 |
const circle = micContainer.getElementsByClassName('circle')[0];
|
|
|
7 |
|
|
|
8 |
micContainer.addEventListener('click', function () {
|
9 |
if (!isRecording) {
|
10 |
startRecording();
|
@@ -25,7 +28,7 @@ function startRecording() {
|
|
25 |
|
26 |
// Update UI for recording
|
27 |
circle.classList.add('active');
|
28 |
-
|
29 |
isRecording = true;
|
30 |
})
|
31 |
.catch(function (err) {
|
@@ -43,29 +46,32 @@ function stopRecording() {
|
|
43 |
|
44 |
// Update UI after recording
|
45 |
circle.classList.remove('active');
|
46 |
-
|
47 |
|
48 |
-
//
|
49 |
-
|
50 |
-
|
51 |
-
});
|
52 |
|
53 |
isRecording = false;
|
54 |
};
|
55 |
}
|
56 |
|
57 |
-
function
|
|
|
|
|
|
|
|
|
|
|
58 |
const formData = new FormData();
|
59 |
formData.append('audio', blob, 'audio.webm');
|
60 |
|
61 |
-
|
62 |
-
fetch('https://jikoni-semabox.hf.space/transcribe', { // https://tri4-semalab.hf.space/transcribe
|
63 |
method: 'POST',
|
64 |
body: formData
|
65 |
})
|
66 |
.then(response => response.json())
|
67 |
.then(data => {
|
68 |
-
|
69 |
})
|
70 |
.catch(error => {
|
71 |
console.error('Error:', error);
|
|
|
2 |
let mediaRecorder;
|
3 |
let recordedChunks = [];
|
4 |
|
5 |
+
// Get the elements
|
6 |
const micContainer = document.getElementsByClassName('mic-container')[0];
|
7 |
const circle = micContainer.getElementsByClassName('circle')[0];
|
8 |
+
const outputContainer = document.getElementById('output');
|
9 |
|
10 |
+
// Handle the click event for the microphone container
|
11 |
micContainer.addEventListener('click', function () {
|
12 |
if (!isRecording) {
|
13 |
startRecording();
|
|
|
28 |
|
29 |
// Update UI for recording
|
30 |
circle.classList.add('active');
|
31 |
+
outputContainer.textContent = 'Recording...';
|
32 |
isRecording = true;
|
33 |
})
|
34 |
.catch(function (err) {
|
|
|
46 |
|
47 |
// Update UI after recording
|
48 |
circle.classList.remove('active');
|
49 |
+
outputContainer.textContent = 'Click to Transcribe';
|
50 |
|
51 |
+
// Ensure only one event listener is attached
|
52 |
+
outputContainer.removeEventListener('click', handleTranscribeClick);
|
53 |
+
outputContainer.addEventListener('click', handleTranscribeClick);
|
|
|
54 |
|
55 |
isRecording = false;
|
56 |
};
|
57 |
}
|
58 |
|
59 |
+
function handleTranscribeClick() {
|
60 |
+
transcribeAudio();
|
61 |
+
}
|
62 |
+
|
63 |
+
function transcribeAudio() {
|
64 |
+
const blob = new Blob(recordedChunks, { type: 'audio/webm' });
|
65 |
const formData = new FormData();
|
66 |
formData.append('audio', blob, 'audio.webm');
|
67 |
|
68 |
+
fetch('https://tri4-semalab.hf.space/transcribe', {
|
|
|
69 |
method: 'POST',
|
70 |
body: formData
|
71 |
})
|
72 |
.then(response => response.json())
|
73 |
.then(data => {
|
74 |
+
outputContainer.textContent = `Transcription: ${data.transcription}`;
|
75 |
})
|
76 |
.catch(error => {
|
77 |
console.error('Error:', error);
|