Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
59 lines (54 loc) · 1.91 KB
/
Copy pathscript.js
File metadata and controls
59 lines (54 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import CustomMic from "./customMic.js";
document.addEventListener('DOMContentLoaded', (event) => {
// Function for button 1 click event
let mic = null;
function getChunkSize() {
const chunkSizeInput = document.getElementById('chunksize');
const chunkSize = parseInt(chunkSizeInput.value, 10);
if (isNaN(chunkSize) || chunkSize < 3) {
return null;
}
return chunkSize;
}
async function handleButton1Click() {
const chunkSize = getChunkSize();
const errorMessage = document.getElementById('error-message');
if (chunkSize === null) {
errorMessage.style.display = 'inline';
return;
}
errorMessage.style.display = 'none';
mic = new CustomMic(chunkSize);
await mic.startMic();
mic.on("recordedData", data => {
console.log(data);
let audioArray = data[0];
let endOfStream = data[1];
const audioFileInWav = new File([audioArray], `filename`, { type: "audio/wav" });
});
updateButtonStates();
}
// Function for button 2 click event
function handleButton2Click() {
if (mic) {
mic.stopMic();
}
mic = null;
updateButtonStates();
}
function updateButtonStates() {
const startButton = document.getElementById('startbutton');
const stopButton = document.getElementById('stopbutton');
if (mic === null) {
startButton.disabled = false;
stopButton.disabled = true;
} else {
startButton.disabled = true;
stopButton.disabled = false;
}
}
// Add event listeners to the buttons
document.getElementById('startbutton').addEventListener('click', handleButton1Click);
document.getElementById('stopbutton').addEventListener('click', handleButton2Click);
updateButtonStates();
});