-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
66 lines (58 loc) · 1.8 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>Trans-lateR</title>
<meta charset="UTF-8" />
</head>
<body>
<form action="none">
<select name="Language" id="Lang">
<option value="hi">Hindi</option>
<option value="es">Spanish</option>
</select>
<input type="text" placeholder="Enter text here" id="text" />
<input type="submit" value="Submit" id="submit" />
</form>
<script>
var Lang = document.getElementsByTagName("select")[0];
var form = document.getElementsByTagName("form")[0];
var speech = window.speechSynthesis;
var voices = speech.getVoices();
// console.info(voices.length());
var utter;
var url = `https://www.gunpreetsingh.cf/Trans-lateR/Translate.php`;
// console.log(form);
form.addEventListener("submit", (e) => {
e.preventDefault();
var inputText = document.querySelector("#text");
// form.style.background = "red";
// 'sl=de&tl=en&q=Hurra.'
var FD = new URLSearchParams();
FD.append("fl", "en");
FD.append("tl", Lang.value);
FD.append("query", inputText.value);
// alert("yo");
var callOPt = {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
body: FD
};
fetch(url, callOPt)
.then((response) => response.text())
.then((res) => {
console.log(res);
// utter = new SpeechSynthesisUtterance(res.sentences[0].trans);
utter = new SpeechSynthesisUtterance("Hello");
// utter.voice = voices[0];
speech.speak(utter);
inputText.blur();
});
});
</script>
<script>
import "./styles.css";
</script>
</body>
</html>