vakodiya commited on
Commit
7ba16e7
1 Parent(s): 8d6648d

Update mic_component.js

Browse files
Files changed (1) hide show
  1. mic_component.js +27 -27
mic_component.js CHANGED
@@ -1,34 +1,34 @@
1
  const recordButton = document.getElementById("recordButton");
2
- const stopButton = document.getElementById("stopButton");
3
- const audioChunks = [];
4
 
5
- let mediaRecorder;
6
-
7
- navigator.mediaDevices.getUserMedia({ audio: true })
8
- .then(function(stream) {
9
- mediaRecorder = new MediaRecorder(stream);
10
 
11
- recordButton.onclick = function() {
12
- mediaRecorder.start();
13
- console.log("Recording started...");
14
- };
15
 
16
- stopButton.onclick = function() {
17
- mediaRecorder.stop();
18
- console.log("Recording stopped...");
19
- };
20
 
21
- mediaRecorder.ondataavailable = function(e) {
22
- audioChunks.push(e.data);
23
- };
 
 
 
 
 
24
 
25
- mediaRecorder.onstop = function(e) {
26
- const audioBlob = new Blob(audioChunks, { type: "audio/wav" });
27
- const reader = new FileReader();
28
- reader.readAsDataURL(audioBlob);
29
- reader.onloadend = function() {
30
- const base64data = reader.result.split(',')[1];
31
- Streamlit.setComponentValue(base64data);
32
- };
33
  };
34
- });
 
 
1
  const recordButton = document.getElementById("recordButton");
2
+ const stopButton = document.getElementById("stopButton");
3
+ const audioChunks = [];
4
 
5
+ let mediaRecorder;
 
 
 
 
6
 
7
+ navigator.mediaDevices.getUserMedia({ audio: true })
8
+ .then(function(stream) {
9
+ mediaRecorder = new MediaRecorder(stream);
 
10
 
11
+ recordButton.onclick = function() {
12
+ mediaRecorder.start();
13
+ console.log("Recording started...");
14
+ };
15
 
16
+ stopButton.onclick = function() {
17
+ mediaRecorder.stop();
18
+ console.log("Recording stopped...");
19
+ };
20
+
21
+ mediaRecorder.ondataavailable = function(e) {
22
+ audioChunks.push(e.data);
23
+ };
24
 
25
+ mediaRecorder.onstop = function(e) {
26
+ const audioBlob = new Blob(audioChunks, { type: "audio/wav" });
27
+ const reader = new FileReader();
28
+ reader.readAsDataURL(audioBlob);
29
+ reader.onloadend = function() {
30
+ const base64data = reader.result.split(',')[1];
31
+ Streamlit.setComponentValue(base64data);
 
32
  };
33
+ };
34
+ });