Create script.js
Browse files- templates /script.js +40 -0
templates /script.js
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const startButton = document.getElementById('startButton');
|
2 |
+
const output = document.getElementById('output');
|
3 |
+
const copyButton = document.getElementById('copyButton');
|
4 |
+
const clearButton = document.getElementById('clearButton');
|
5 |
+
|
6 |
+
copyButton.onclick = function() {
|
7 |
+
const textToCopy = output.innerText;
|
8 |
+
navigator.clipboard.writeText(textToCopy).then(() => {
|
9 |
+
alert('Text copied to clipboard!');
|
10 |
+
}).catch(err => {
|
11 |
+
console.error('Failed to copy: ', err);
|
12 |
+
});
|
13 |
+
};
|
14 |
+
|
15 |
+
clearButton.onclick = function() {
|
16 |
+
output.innerText = '';
|
17 |
+
};
|
18 |
+
|
19 |
+
startButton.addEventListener('click', function() {
|
20 |
+
var speech = true;
|
21 |
+
window.SpeechRecognition = window.webkitSpeechRecognition;
|
22 |
+
|
23 |
+
const recognition = new SpeechRecognition();
|
24 |
+
recognition.interimResults = true;
|
25 |
+
|
26 |
+
recognition.addEventListener('result', e => {
|
27 |
+
const transcript = Array.from(e.results)
|
28 |
+
.map(result => result[0])
|
29 |
+
.map(result => result.transcript)
|
30 |
+
.join('')
|
31 |
+
|
32 |
+
output.innerHTML = transcript;
|
33 |
+
|
34 |
+
console.log(transcript);
|
35 |
+
});
|
36 |
+
|
37 |
+
if (speech == true) {
|
38 |
+
recognition.start();
|
39 |
+
}
|
40 |
+
});
|