-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreeTyping.html
89 lines (83 loc) · 2.51 KB
/
freeTyping.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
79
80
81
82
83
84
85
86
87
88
89
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Multimodal typing</title>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
}
.hints {
margin-bottom: 5em;
margin-top: 20px;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
max-width: 600px;
margin-left: auto;
margin-right: auto;
background-color: #f9f9f9;
font-size: 1.5rem;
}
.typing-area {
font-size: 7rem;
}
</style>
</head>
<body>
<div id="app">
<div class="hints">
<h1>Freies Schreiben</h1>
Tippe auf der Tastatur. Backspace = letztes Zeichen löschen, Esc = alles löschen, Enter = gesamten Text sprechen
</div>
<div class="typing-area">{{ text }}</div>
</div>
<script type="module">
import { createApp } from './lib/vue.esm-browser.js'
createApp({
data() {
return {
text: '',
voices: speechSynthesis.getVoices()
}
},
methods: {
handleKeydown(event) {
let key = event.key;
let code = event.code;
if(!event.repeat && key.length === 1) {
key = key.toUpperCase();
this.text += key;
this.speak(key);
}
if (code === 'Backspace') {
this.speak("Löschen");
this.text = this.text.slice(0, -1);
}
if (code === 'Escape') {
this.speak("Alles gelöscht");
this.text = "";
}
if (code === 'Enter') {
this.speak(this.text);
}
if (code === 'Space') {
let words = this.text.split(" ").filter(word => !!word);
this.speak(words.pop());
}
},
speak(text) {
speechSynthesis.cancel();
this.voices = this.voices && this.voices.length > 0 ? this.voices : speechSynthesis.getVoices();
const utterThis = new SpeechSynthesisUtterance(text);
utterThis.voice = this.voices[0];
speechSynthesis.speak(utterThis);
}
},
mounted() {
addEventListener('keydown', this.handleKeydown);
}
}).mount('#app')
</script>
</body>
</html>