krishna195 commited on
Commit
35c66c7
Β·
verified Β·
1 Parent(s): 8ec810b

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +30 -14
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
- document.getElementById("status").innerText = "Processing...";
22
-
23
- // Load Whisper model
24
- let transcriber = await window.Transformers.pipeline(
25
- 'automatic-speech-recognition',
26
- 'Xenova/whisper-tiny.en'
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();