-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.html
78 lines (63 loc) · 2.31 KB
/
code.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
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Listenning skill</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
</head>
<body class="text-white" style="background-color: black;">
<div class="container">
<div class="row">
<div class="col-md-6 mx-auto">
<h3>Listen to the text and write the translation below</h3>
<button id="play-btn" class="btn btn-light btn-lg btn-block">Play</button>
<br>
<div class="form-group">
<textarea id="text-input" class="form-control form-control-lg" placeholder="Type the answer...."></textarea>
</div>
<br>
<br>
<button id="submit-btn" class="btn btn-light btn-lg btn-block">Submit</button>
</div>
</div>
</div>
<script>
const synth = window.speechSynthesis;
let voices = []
let current = 0
const words = [
]
const text = document.getElementById('text-input')
const play = document.getElementById('play-btn')
const submit = document.getElementById('submit-btn')
const getVoices = () => {
voices = synth.getVoices()
voices.forEach(voice => {
voices.push(voice)
})
}
getVoices()
if(synth.onvoiceschanged !== undefined)
synth.onvoiceschanged = getVoices
play.onclick = () => {
speak('ほ')
}
const speak = (input) => {
if(synth.speaking)
{
console.error('Already speaking')
}
const speachText = new SpeechSynthesisUtterance(input)
speachText.onend = () => {
console.log('ended')
}
voices.forEach(voice => {
if(voice.lang === "ja-JP")
speachText.voice = voice
})
synth.speak(speachText)
}
</script>
</body>
</html>