-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
66 lines (57 loc) · 1.96 KB
/
script.js
File metadata and controls
66 lines (57 loc) · 1.96 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
60
61
62
63
64
65
66
// Speech Recognition
const startBtn = document.getElementById("start");
const stopBtn = document.getElementById("stop");
const transcript = document.getElementById("transcript");
let recognition;
if ("webkitSpeechRecognition" in window) {
recognition = new webkitSpeechRecognition();
recognition.continuous = true;
recognition.interimResults = false;
recognition.onresult = (event) => {
const result = event.results[event.results.length - 1][0].transcript;
transcript.value += result + " ";
};
startBtn.onclick = () => recognition.start();
stopBtn.onclick = () => recognition.stop();
} else {
transcript.value = "Speech Recognition not supported.";
}
// Clear
document.getElementById("clear").onclick = () => {
transcript.value = "";
};
// Save .txt
document.getElementById("saveTxt").onclick = () => {
const blob = new Blob([transcript.value], { type: "text/plain" });
const link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = "transcript.txt";
link.click();
};
// Save .md
document.getElementById("saveMd").onclick = () => {
const blob = new Blob([transcript.value], { type: "text/markdown" });
const link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = "transcript.md";
link.click();
};
// Generate Image
document.getElementById("generateImage").onclick = async () => {
const prompt = transcript.value.trim();
if (!prompt) return alert("Enter or say something first.");
const response = await fetch("https://api.deepai.org/api/text2img", {
method: "POST",
headers: {
"Api-Key": "YOUR_DEEPAI_API_KEY"
},
body: new URLSearchParams({ text: prompt })
});
const data = await response.json();
const img = document.createElement("img");
img.src = data.output_url;
img.alt = "Generated";
img.style.maxWidth = "100%";
document.getElementById("imageContainer").innerHTML = "";
document.getElementById("imageContainer").appendChild(img);
};