-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
262 lines (234 loc) · 7.31 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TTS for Listening</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style>
body {
margin-top: 50px;
}
.text {
text-align: center;
}
.text__display {
font-size: 40px;
}
.texts {
font-family: monospace;
}
.show {
opacity: 1;
}
.noshow {
opacity: 0;
}
.library-item {
margin-right: 1em;
}
</style>
</head>
<body>
<div id="app">
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="./">TTS for Listening</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#about">Instructions</a></li>
<li><a href="#settings">Settings</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="container">
<div class="text">
<h3 class="text__title">{{ currentTextId }}</h3>
<div class="jumbotron">
<div class="text__display">
<span v-bind:class="{show: show, noshow: !show}">{{ text }} </span>
</div>
<p class="text__control">
<button class="btn btn-primary speech-btn" v-on:click="speech">Repeat</button>
<button class="btn btn-warning ko-btn" v-on:click="ko">Pass</button>
<button class="btn btn-info speech-btn" v-on:click="show=true;">Show</button>
<button class="btn btn-success ok-btn" v-on:click="ok">OK</button>
</p>
</div>
</div>
<div id="about">
<h2>Instructions</h2>
<p>
Simple Text To Speech for listening.
</p>
<ul>
<li>
Listen and figure out what he is saying.
</li>
<li>
<strong>Repeat</strong>: Repeat again.
</li>
<li>
<strong>Pass</strong>: Next.
</li>
<li>
<strong>Show</strong>: Show the text.
</li>
<li>
<strong>OK</strong>: No repeat again and next.
</li>
<li>
You can load text picking an item of library. <br>
Also you can paste a new text in textarea and add a new item to library.
</li>
</ul>
</div>
<div id="settings">
<h2>Settings</h2>
<h3>Text</h3>
<h4>Library</h4>
<p>
<div is="library-item" v-for="item in library" v-bind:id="item.id" v-on:load="loadText(item.id)"
v-on:remove="removeFromLibrary(item.id)"></div>
</p>
<p>
<textarea v-model="textsString" class="form-control texts" rows="10" wrap="soft"
placeholder="Text to listen. One line for sentence."></textarea>
</p>
<div class="input-group">
<input type="text" class="form-control" id="libraryItemId" placeholder="id of item for library">
<div class="input-group-btn">
<button class="btn btn-primary" v-on:click="addToLibrary">Add to library</button>
</div>
</div>
</div>
</div>
</div><!-- #app -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script>
Vue.component('library-item', {
template: '\
<div class="btn-group library-item">\
<button class="btn btn-default btn-xs active" v-on:click="$emit(\'load\')">{{ id }}</button>\
<button class="btn btn-danger btn-xs" v-on:click="$emit(\'remove\')">X</button>\
</div>\
',
props: ['id']
});
var app = new Vue({
el: '#app',
data: {
show: false,
text: '',
textsString: '',
i: 0,
library: [],
currentTextId: '',
showInstructions: false,
showSettings: false,
},
methods: {
init: function (textsString) {
var texts = this.getTextsFromString(this.textsString);
this.text = texts[this.i];
this.speechText(this.text);
},
getTextsFromString: function (s) {
return s.split("\n");
},
speechText: function (text) {
this.text = text;
var speech = new SpeechSynthesisUtterance(text);
speech.lang = 'en-US';
window.speechSynthesis.speak(speech);
},
speech: function () {
var texts = this.getTextsFromString(this.textsString);
var text = texts[this.i];
this.speechText(text);
},
ok: function () {
var texts = this.getTextsFromString(this.textsString);
texts.splice(this.i, 1);
this.textsString = texts.join("\n");
if (texts.length === 0) {
this.show = true;
this.speechText('Congratulations');
return;
}
if (this.i == texts.length) {
this.i = 0;
}
this.text = texts[this.i];
this.show = false;
this.speechText(this.text);
},
ko: function () {
var texts = this.getTextsFromString(this.textsString);
this.i = this.i + 1;
if (this.i == texts.length) {
this.i = 0;
}
this.text = texts[this.i];
this.show = false;
this.speechText(this.text);
},
loadText: function (id) {
if (id === undefined) {
id = this.library[0].id;
}
var match = this.library.filter(function (item) {
return item.id === id
});
if (match) {
this.textsString = match[0].textsString;
this.currentTextId = id;
}
},
addToLibrary: function (e) {
var id = document.getElementById('libraryItemId').value;
var item = {
id: id,
textsString: this.textsString
};
this.library.push(item);
console.log(this.library);
},
removeFromLibrary: function (id) {
for (var i = 0; i < this.library.length; i++) {
var item = this.library[i];
if (item.id === id) {
this.library.splice(i, 1);
return;
}
}
}
}
});
app.library = [
{
id: 'helloworld',
textsString: "Hello World!\nApple\nBanana\nCandy\nDonuts"
},
{
id: 'tellme',
textsString: "Tell me and I forget,\nteach me and I may remember,\ninvolve me and I learn"
}
];
app.loadText();
app.init();
</script>
</body>
</html>