forked from TalAter/annyang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·243 lines (223 loc) · 11 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
<!DOCTYPE html>
<html>
<head>
<title>annyang! Easily add speech recognition to your site</title>
<meta name="description" content="annyang is a JavaScript SpeechRecognition library that makes adding voice commands to your site super-easy. Let your users control your site with their voice." />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta property="og:image" content="https://www.talater.com/annyang/images/icon_speech.png"/>
<meta property="og:title" content="annyang! Easily add speech recognition to your site"/>
<meta property="og:url" content="https://www.talater.com/annyang/"/>
<meta property="og:site_name" content="annyang"/>
<meta property="fb:admins" content="568390229" />
<script>
var annyangScript = document.createElement('script');
if (/localhost/.exec(window.location)) {
annyangScript.src = "//localhost:8443/annyang.js"
} else {
annyangScript.src = "//cdnjs.cloudflare.com/ajax/libs/annyang/1.4.0/annyang.min.js"
}
document.write(annyangScript.outerHTML)
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
"use strict";
// first we make sure annyang started succesfully
if (annyang) {
// define the functions our commands will run.
var hello = function() {
$("#hello").slideDown("slow");
scrollTo("#section_hello");
};
var showFlickr = function(tag) {
$('#flickrGallery').show();
$('#flickrLoader p').text('Searching for '+tag).fadeIn('fast');
var url = '//api.flickr.com/services/rest/?method=flickr.photos.search&api_key=a828a6571bb4f0ff8890f7a386d61975&sort=interestingness-desc&per_page=9&format=json&callback=jsonFlickrApi&tags='+tag;
$.ajax({
type: 'GET',
url: url,
async: false,
jsonpCallback: 'jsonFlickrApi',
contentType: "application/json",
dataType: 'jsonp'
});
scrollTo("#section_image_search");
};
var jsonFlickrApi = function(results) {
$('#flickrLoader p').fadeOut('slow');
var photos = results.photos.photo;
$.each(photos, function(index, photo) {
$(document.createElement("img"))
.attr({ src: '//farm'+photo.farm+'.staticflickr.com/'+photo.server+'/'+photo.id+'_'+photo.secret+'_s.jpg' })
.addClass("flickrGallery")
.appendTo(flickrGallery);
});
};
var showTPS = function(type) {
$('#tpsreport').show().animate({
bottom: '-100px'
}).delay('2000').animate({
bottom: '-500px'
});
};
var getStarted = function() {
window.location.href = 'https://github.com/TalAter/annyang';
}
// define our commands.
// * The key is what you want your users to say say.
// * The value is the action to do.
// You can pass a function, a function name (as a string), or write your function as part of the commands object.
var commands = {
'hello (there)': hello,
'show me *search': showFlickr,
'show :type report': showTPS,
'let\'s get started': getStarted,
};
// OPTIONAL: activate debug mode for detailed logging in the console
annyang.debug();
// Add voice commands to respond to
annyang.addCommands(commands);
// OPTIONAL: Set a language for speech recognition (defaults to English)
annyang.setLanguage('en');
// Start listening. You can call this here, or attach this call to an event, button, etc.
annyang.start();
} else {
$(document).ready(function() {
$('#unsupported').fadeIn('fast');
});
}
var scrollTo = function(identifier, speed) {
$('html, body').animate({
scrollTop: $(identifier).offset().top
}, speed || 1000);
}
</script>
<link rel="stylesheet" href="css/main.min.css" />
</head>
<body>
<section id="section_header">
<h1><em>annyang!</em> SpeechRecognition that just works</h1>
<h2>annyang is a tiny javascript library that lets your visitors control your site with voice commands.</h2>
<h2>annyang supports multiple languages, has no dependencies, weighs just 2kb and is free to use.</h2>
<img src="images/icon_user.png">
<img src="images/icon_speech.png">
<img src="images/icon_js.png">
</section>
<section id="section_hello">
<p><em>Go ahead, try it…</em></p>
<p class="voice_instructions">Say "Hello!"</p>
<p id="hello" class="hidden">Annyang!</p>
</section>
<section id="section_image_search">
<p><em>Let's try something more interesting…</em></p>
<p class="voice_instructions">Say "Show me cute kittens!"</p>
<p class="voice_instructions">Say "Show me Arches National Park!"</p>
<p class="voice_instructions">Now go wild. Say "Show me…" and make your demands!</p>
<div id="flickrLoader"><p></p></div>
<div id="flickrGallery" class="hidden"></div>
</section>
<section id="section_biz_use">
<p><em>That's cool, but in the real world it's not all kittens and hello world.</em></p>
<p class="voice_instructions">No problem, say "Show TPS report"</p>
<img src="images/tpscover.jpg" id="tpsreport" class="hidden">
</section>
<section id="section_code_sample_1">
<p><em>How did you do that?</em></p>
<p>Simple. Here is all the code needed to achieve that:</p>
<pre><code><script src="<a href="//cdnjs.cloudflare.com/ajax/libs/annyang/1.4.0/annyang.min.js">//cdnjs.cloudflare.com/ajax/libs/annyang/1.4.0/annyang.min.js</a>"></script>
<script>
if (annyang) {
// Let's define our first command. First the text we expect, and then the function it should call
var commands = {
'show tps report': function() {
$('#tpsreport').animate({bottom: '-100px'});
}
};
// Add our commands to annyang
annyang.addCommands(commands);
// Start listening. You can call this here, or attach this call to an event, button, etc.
annyang.start();
}
</script></code></pre>
</section>
<section id="section_named_and_splats">
<p><em>What about more complicated commands?</em></p>
<p>annyang understands commands with <strong>named variables</strong>, <strong>splats</strong>, and <strong>optional words</strong>.</p>
<p>Use <strong>named variables</strong> for one word arguments in your command.</p>
<p>Use <strong>splats</strong> to capture multi-word text at the end of your command (greedy).</p>
<p>Use <strong>optional words or phrases</strong> to define a part of the command as optional.</p>
<pre><code><script>
var commands = {
// annyang will capture anything after a splat (*) and pass it to the function.
// e.g. saying "Show me Batman and Robin" is the same as calling showFlickr('Batman and Robin');
'show me *term': showFlickr,
// A named variable is a one word variable, that can fit anywhere in your command.
// e.g. saying "calculate October stats" will call calculateStats('October');
'calculate :month stats': calculateStats,
// By defining a part of the following command as optional, annyang will respond to both:
// "say hello to my little friend" as well as "say hello friend"
'say hello (to my little) friend': greeting
};
var showFlickr = function(term) {
var url = 'http://api.flickr.com/services/rest/?tags='+tag;
$.getJSON(url);
}
var calculateStats = function(month) {
$('#stats').text('Statistics for '+month);
}
var greeting = function() {
$('#greeting').text('Hello!');
}
</script></code></pre>
</section>
<section id="section_docs">
<p><em>What about browser support?</em></p>
<p>annyang plays nicely with all browsers, progressively enhancing browsers that support SpeechRecognition, while leaving users with older browsers unaffected.</p>
</section>
<section id="section_footer">
<h2>Ready to get started?</h2>
<p>Grab the latest version of <a href="https://github.com/TalAter/annyang">annyang.min.js</a>, drop it in your html, and start adding commands.</p>
<p>…or just say "let's get started!" to visit annyang on <a href="https://github.com/TalAter/annyang">GitHub</a>.</p>
<div class="social">
<iframe src="vendor/html/github-btn.html?user=TalAter&repo=annyang&type=watch&count=true&size=large" allowtransparency="true" frameborder="0" scrolling="0" width="152px" height="30px"></iframe>
<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.annyangjs.com" data-counturl="https://www.talater.com/annyang" data-via="TalAter" data-size="large" data-lang="en" data-count="horizontal" data-text="annyang! A javascript library that lets your users talk to your site, giving it voice commands">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
<div style="display: inline;" class="fb-like" data-href="https://www.talater.com/annyang/" data-width="200" data-layout="button_count" data-show-faces="true" data-send="true"></div>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=263514670331109";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
</div>
<div class="comments">
<h2>Questions? Comments?</h2>
<div class="fb-comments" data-href="https://www.talater.com/annyang/" data-colorscheme="dark" data-width="750"></div>
</div>
<div class="copyright">
<p>© 2013 Tal Ater. All rights reserved. The annyang source code is free to use under the <a href="https://raw.github.com/TalAter/annyang/master/LICENSE">MIT license</a>.</p>
<p>Tal Ater retains creative control, spin-off rights and theme park approval for Mr. Banana Grabber, Baby Banana Grabber, and any other Banana Grabber family character that might emanate there from.</p>
</div>
</section>
<div id="unsupported" class="hidden">
<h4>It looks like your browser doesn't support speech recognition.</h4>
<p>annyang plays nicely with all browsers, progressively enhancing modern browsers that support the SpeechRecognition standard, while leaving users with older browsers unaffected.</p>
<p>Please visit <a href="http://www.annyangjs.com/">http://www.annyangjs.com/</a> in a desktop browser like Chrome.</p>
</div>
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-24775009-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script src="./vendor/js/highlight.pack.js"></script>
<script>
hljs.initHighlightingOnLoad();
</script>
</body>
</html>