-
Notifications
You must be signed in to change notification settings - Fork 75
/
index.html
141 lines (102 loc) · 4.17 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
<!DOCTYPE html>
<html class="mdc-typography">
<head>
<meta charset="utf-8">
<link rel='manifest' href='./manifest.json'>
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Text to Speech App</title>
<!-- material components styles -->
<link
rel="stylesheet"
href="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.css">
<!-- material icons -->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet">
<!-- styles -->
<style>
body {background-color: white;}
</style>
</head>
<body>
<header class="mdc-toolbar">
<div class="mdc-toolbar__row">
<section class="mdc-toolbar__section mdc-toolbar__section--align-start">
<span class="mdc-toolbar__title">Text to Speech</span>
</section>
<section class="mdc-toolbar__section mdc-toolbar__section--align-end" role="toolbar">
<a href="#" id="clearCache" class="material-icons mdc-toolbar__icon" aria-label="Clear cache" alt="Clear Cache"><i class="material-icons">refresh</i></a> </section>
</div>
</header>
<!-- UI Items to Modify -->
<h1 class="mdc-typography--display1">Hello, World!</h1>
<input type="text" name="phrase" id="phrase">
<button type="button" class="special mdc-button mdc-button--raised">
Say Phrase
</button>
<br><br>
<button type="button" class="standard mdc-button mdc-button--raised">
Stop playing LightBot!
</button>
<br>
<button type="button" class="standard mdc-button mdc-button--raised">
Wake up!
</button> <br>
<button type="button" class="standard mdc-button mdc-button--raised">
I don't like haters.
</button> <br>
<button type="button" class="standard mdc-button mdc-button--raised">
Put that cookie down.
</button>
<div class="mdc-snackbar"
aria-live="assertive"
aria-atomic="true"
aria-hidden="true"
data-mdc-auto-init="MDCSnackbar">
<div class="mdc-snackbar__text"></div>
<div class="mdc-snackbar__action-wrapper">
<button type="button" class="mdc-snackbar__action-button"></button>
</div>
</div>
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Material Components -->
<script src="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.js"></script>
<script>window.mdc.autoInit();</script>
<script>
// register the service worker for offline use
if('serviceWorker' in navigator) {
navigator.serviceWorker
.register('./sw.js')
.then(function() { console.log("Service Worker Registered"); });
}
// reusable function to use the speech API
function sayIt (setOfWords) {
var msg = new SpeechSynthesisUtterance(setOfWords);
window.speechSynthesis.speak(msg);
}
// hook up event handler on the buttons
$("button.standard").on("click", function() {
sayIt($(this).text());
});
$("button.special").on("click", function() {
sayIt($("#phrase").val());
});
// need to be able to clear the cache to load new versions
$("#clearCache").on("click", function() {
caches.open('textToSpeech').then(function(cache) {
cache.delete('./');
cache.delete('./index.html').then(function(response) {
var snackbar = new MDCSnackbar(document.querySelector('.mdc-snackbar'));
var dataObj = {
message: 'Cache cleared'
};
snackbar.show(dataObj);
});
});
});
// Material Components Snackbar stuff
const MDCSnackbar = mdc.snackbar.MDCSnackbar;
const MDCSnackbarFoundation = mdc.snackbar.MDCSnackbarFoundation;
</script>
</body>
</html>