forked from heymrhayes/text-to-speech
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
112 lines (82 loc) · 3.47 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
<!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">
</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>
<h1 class="mdc-typography--display1">Hello, World!</h1>
<button type="button" class="mdc-button mdc-button--raised">
Welcome to Lane Tech.
</button>
<button type="button" class="mdc-button mdc-button--raised">
Hello World
</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").on("click", function() {
sayIt($(this).text());
});
// 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>