-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
37 lines (31 loc) · 1014 Bytes
/
test.js
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
$(function(){
if ('speechSynthesis' in window) {
speechSynthesis.onvoiceschanged = function() {
var $voicelist = $('#voices');
if($voicelist.find('option').length == 0) {
speechSynthesis.getVoices().forEach(function(voice, index) {
var $option = $('<option>')
.val(index)
.html(voice.name + (voice.default ? ' (default)' :''));
$voicelist.append($option);
});
$voicelist.material_select();
}
}
$('#speak').click(function(){
var text = $('#message').val();
var msg = new SpeechSynthesisUtterance();
var voices = window.speechSynthesis.getVoices();
msg.voice = voices[$('#voices').val()];
msg.rate = $('#rate').val() / 10;
msg.pitch = $('#pitch').val();
msg.text = text;
msg.onend = function(e) {
console.log('Finished in ' + event.elapsedTime + ' seconds.');
};
speechSynthesis.speak(msg);
})
} else {
$('#modal1').openModal();
}
});