Spaces:
Sleeping
Sleeping
Update static/js/design.js
Browse files- static/js/design.js +13 -32
static/js/design.js
CHANGED
@@ -2,14 +2,12 @@ let isRecording = false;
|
|
2 |
let mediaRecorder;
|
3 |
let recordedChunks = [];
|
4 |
|
5 |
-
// Get elements
|
6 |
const micContainer = document.querySelector('.mic-container');
|
7 |
const circle = document.querySelector('.circle');
|
8 |
const outputContainer = document.getElementById('output');
|
9 |
const audioPlayerContainer = document.getElementById('audioPlayerContainer');
|
10 |
const audioPlayer = document.getElementById('audioPlayer');
|
11 |
|
12 |
-
// Handle click event for the microphone container
|
13 |
micContainer.addEventListener('click', function () {
|
14 |
if (!isRecording) {
|
15 |
startRecording();
|
@@ -21,28 +19,17 @@ micContainer.addEventListener('click', function () {
|
|
21 |
function startRecording() {
|
22 |
navigator.mediaDevices.getUserMedia({ audio: true })
|
23 |
.then(function (stream) {
|
24 |
-
mediaRecorder = new MediaRecorder(stream);
|
25 |
-
|
26 |
-
mediaRecorder.ondataavailable = function (e) {
|
27 |
-
if (e.data.size > 0) {
|
28 |
-
recordedChunks.push(e.data);
|
29 |
-
}
|
30 |
-
};
|
31 |
-
|
32 |
-
mediaRecorder.onstart = function () {
|
33 |
-
// Update UI for recording
|
34 |
-
circle.classList.add('active');
|
35 |
-
outputContainer.textContent = 'Recording...';
|
36 |
-
audioPlayerContainer.style.display = 'none'; // Hide audio player initially
|
37 |
-
isRecording = true;
|
38 |
-
};
|
39 |
|
40 |
-
mediaRecorder.
|
41 |
-
|
42 |
-
stopRecording(); // Stop recording on error
|
43 |
};
|
44 |
|
45 |
-
|
|
|
|
|
|
|
46 |
})
|
47 |
.catch(function (err) {
|
48 |
console.error('The following error occurred: ' + err);
|
@@ -50,24 +37,18 @@ function startRecording() {
|
|
50 |
}
|
51 |
|
52 |
function stopRecording() {
|
53 |
-
|
54 |
-
mediaRecorder.stop();
|
55 |
-
}
|
56 |
|
57 |
mediaRecorder.onstop = function () {
|
58 |
-
const blob = new Blob(recordedChunks, { type: 'audio/
|
59 |
recordedChunks = [];
|
60 |
const audioURL = window.URL.createObjectURL(blob);
|
61 |
|
62 |
-
// Update UI after recording
|
63 |
circle.classList.remove('active');
|
64 |
outputContainer.textContent = 'Click to Transcribe';
|
65 |
-
|
66 |
-
// Display audio player
|
67 |
audioPlayer.src = audioURL;
|
68 |
-
audioPlayerContainer.style.display = 'block';
|
69 |
|
70 |
-
// Handle transcription
|
71 |
outputContainer.addEventListener('click', handleTranscribeClick, { once: true });
|
72 |
isRecording = false;
|
73 |
};
|
@@ -78,9 +59,9 @@ function handleTranscribeClick() {
|
|
78 |
}
|
79 |
|
80 |
function transcribeAudio() {
|
81 |
-
const blob = new Blob(recordedChunks, { type: 'audio/
|
82 |
const formData = new FormData();
|
83 |
-
formData.append('audio', blob, 'audio.
|
84 |
|
85 |
fetch('https://jikoni-semabox.hf.space/transcribe', {
|
86 |
method: 'POST',
|
|
|
2 |
let mediaRecorder;
|
3 |
let recordedChunks = [];
|
4 |
|
|
|
5 |
const micContainer = document.querySelector('.mic-container');
|
6 |
const circle = document.querySelector('.circle');
|
7 |
const outputContainer = document.getElementById('output');
|
8 |
const audioPlayerContainer = document.getElementById('audioPlayerContainer');
|
9 |
const audioPlayer = document.getElementById('audioPlayer');
|
10 |
|
|
|
11 |
micContainer.addEventListener('click', function () {
|
12 |
if (!isRecording) {
|
13 |
startRecording();
|
|
|
19 |
function startRecording() {
|
20 |
navigator.mediaDevices.getUserMedia({ audio: true })
|
21 |
.then(function (stream) {
|
22 |
+
mediaRecorder = new MediaRecorder(stream, { mimeType: 'audio/webm' });
|
23 |
+
mediaRecorder.start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
+
mediaRecorder.ondataavailable = function (e) {
|
26 |
+
recordedChunks.push(e.data);
|
|
|
27 |
};
|
28 |
|
29 |
+
circle.classList.add('active');
|
30 |
+
outputContainer.textContent = 'Recording...';
|
31 |
+
audioPlayerContainer.style.display = 'none'; // Hide audio player initially
|
32 |
+
isRecording = true;
|
33 |
})
|
34 |
.catch(function (err) {
|
35 |
console.error('The following error occurred: ' + err);
|
|
|
37 |
}
|
38 |
|
39 |
function stopRecording() {
|
40 |
+
mediaRecorder.stop();
|
|
|
|
|
41 |
|
42 |
mediaRecorder.onstop = function () {
|
43 |
+
const blob = new Blob(recordedChunks, { type: 'audio/webm' });
|
44 |
recordedChunks = [];
|
45 |
const audioURL = window.URL.createObjectURL(blob);
|
46 |
|
|
|
47 |
circle.classList.remove('active');
|
48 |
outputContainer.textContent = 'Click to Transcribe';
|
|
|
|
|
49 |
audioPlayer.src = audioURL;
|
50 |
+
audioPlayerContainer.style.display = 'block'; // Show audio player
|
51 |
|
|
|
52 |
outputContainer.addEventListener('click', handleTranscribeClick, { once: true });
|
53 |
isRecording = false;
|
54 |
};
|
|
|
59 |
}
|
60 |
|
61 |
function transcribeAudio() {
|
62 |
+
const blob = new Blob(recordedChunks, { type: 'audio/webm' });
|
63 |
const formData = new FormData();
|
64 |
+
formData.append('audio', blob, 'audio.webm');
|
65 |
|
66 |
fetch('https://jikoni-semabox.hf.space/transcribe', {
|
67 |
method: 'POST',
|