Spaces:
Running
Running
Update script.js
Browse files
script.js
CHANGED
@@ -1,6 +1,22 @@
|
|
1 |
let mediaRecorder;
|
2 |
let audioChunks = [];
|
3 |
let recording = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
// Function to start recording
|
6 |
async function startRecording() {
|
@@ -17,19 +33,16 @@ async function startRecording() {
|
|
17 |
|
18 |
reader.onloadend = async () => {
|
19 |
let audioURL = reader.result;
|
|
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
// Transcribe audio
|
30 |
-
let output = await transcriber(audioURL);
|
31 |
-
document.getElementById("output").innerText = output.text;
|
32 |
-
document.getElementById("status").innerText = "Done!";
|
33 |
};
|
34 |
|
35 |
reader.readAsDataURL(audioBlob);
|
@@ -39,7 +52,7 @@ async function startRecording() {
|
|
39 |
audioChunks = [];
|
40 |
recording = true;
|
41 |
document.getElementById("recordButton").innerText = "βΉ Stop Recording";
|
42 |
-
document.getElementById("status").innerText = "Recording...";
|
43 |
}
|
44 |
|
45 |
// Function to stop recording
|
@@ -48,7 +61,7 @@ function stopRecording() {
|
|
48 |
mediaRecorder.stop();
|
49 |
recording = false;
|
50 |
document.getElementById("recordButton").innerText = "π€ Start Recording";
|
51 |
-
document.getElementById("status").innerText = "Processing...";
|
52 |
}
|
53 |
}
|
54 |
|
@@ -60,3 +73,6 @@ document.getElementById("recordButton").addEventListener("click", () => {
|
|
60 |
stopRecording();
|
61 |
}
|
62 |
});
|
|
|
|
|
|
|
|
1 |
let mediaRecorder;
|
2 |
let audioChunks = [];
|
3 |
let recording = false;
|
4 |
+
let transcriber;
|
5 |
+
|
6 |
+
// Function to load the model
|
7 |
+
async function loadModel() {
|
8 |
+
document.getElementById("modelStatus").innerText = "β³ Loading Whisper model...";
|
9 |
+
|
10 |
+
transcriber = await window.Transformers.pipeline(
|
11 |
+
'automatic-speech-recognition',
|
12 |
+
'Xenova/whisper-tiny.en'
|
13 |
+
);
|
14 |
+
|
15 |
+
document.getElementById("modelStatus").innerText = "β
Model loaded!";
|
16 |
+
document.getElementById("recordButton").innerText = "π€ Start Recording";
|
17 |
+
document.getElementById("recordButton").disabled = false;
|
18 |
+
document.getElementById("status").innerText = "Press the button to record.";
|
19 |
+
}
|
20 |
|
21 |
// Function to start recording
|
22 |
async function startRecording() {
|
|
|
33 |
|
34 |
reader.onloadend = async () => {
|
35 |
let audioURL = reader.result;
|
36 |
+
document.getElementById("status").innerText = "β³ Transcribing...";
|
37 |
|
38 |
+
try {
|
39 |
+
let output = await transcriber(audioURL);
|
40 |
+
document.getElementById("output").innerText = output.text;
|
41 |
+
document.getElementById("status").innerText = "β
Done!";
|
42 |
+
} catch (error) {
|
43 |
+
document.getElementById("status").innerText = "β Error during transcription.";
|
44 |
+
console.error(error);
|
45 |
+
}
|
|
|
|
|
|
|
|
|
46 |
};
|
47 |
|
48 |
reader.readAsDataURL(audioBlob);
|
|
|
52 |
audioChunks = [];
|
53 |
recording = true;
|
54 |
document.getElementById("recordButton").innerText = "βΉ Stop Recording";
|
55 |
+
document.getElementById("status").innerText = "ποΈ Recording...";
|
56 |
}
|
57 |
|
58 |
// Function to stop recording
|
|
|
61 |
mediaRecorder.stop();
|
62 |
recording = false;
|
63 |
document.getElementById("recordButton").innerText = "π€ Start Recording";
|
64 |
+
document.getElementById("status").innerText = "β³ Processing audio...";
|
65 |
}
|
66 |
}
|
67 |
|
|
|
73 |
stopRecording();
|
74 |
}
|
75 |
});
|
76 |
+
|
77 |
+
// Load the model on page load
|
78 |
+
loadModel();
|