-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
135 lines (115 loc) · 4.81 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
<!DOCTYPE html>
<html>
<head>
<title>Text to Spetch</title>
<meta charset=utf-8>
<meta name=viewport content="width=device-width, initial-scale=1">
</head>
<body>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/materialize/0.95.1/css/materialize.min.css">
<div class="container">
<div class="row">
<nav>
<div class="nav-wrapper">
<div class="col s12">
<a href="#" class="brand-logo">Text to speech example</a>
</div>
</div>
</nav>
</div>
<form class="col s8 offset-s2">
<div class="row">
<label>Choose voice</label>
<select id="voices"></select>
</div>
<div class="row">
<div class="col s6">
<label>Rate</label>
<p class="range-field">
<input type="range" id="rate" min="1" max="100" value="10" />
</p>
</div>
<div class="col s6">
<label>Pitch</label>
<p class="range-field">
<input type="range" id="pitch" min="0" max="2" value="1" />
</p>
</div>
<div class="col s12">
<p>N.B. Rate and Pitch only work with native voice.</p>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<textarea id="message" class="materialize-textarea"></textarea>
<label>Write message</label>
</div>
</div>
<a href="#" id="speak" class="waves-effect waves-light btn">Speak</a>
</form>
</div>
<div id="modal1" class="modal">
<h4>Speech Synthesis not supported</h4>
<p>Your browser does not support speech synthesis.</p>
<p>We recommend you use Google Chrome.</p>
<div class="action-bar">
<a href="#" class="waves-effect waves-green btn-flat modal-action modal-close">Close</a>
</div>
</div>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/materialize/0.95.1/js/materialize.min.js"></script>
<script>
$(function () {
if ('speechSynthesis' in window) {
speechSynthesis.onvoiceschanged = function () {
var $voicelist = $('#voices');
if ($voicelist.find('option').length == 0) {
speechSynthesis.getVoices().forEach(function (voice, index) {
console.log(voice);
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.');
};
// console.log(speechSynthesis);
speechSynthesis.speak(msg);
})
} else {
$('#modal1').openModal();
}
});
</script>
<!-- <textarea name='text' id='text'>hello asif vora kem cho .? </textarea><br>
<input type='button' value='Speak' onclick="textToSpetch()">
<script>
function textToSpetch() {
let secretKey = '2WqSu01Bp8yTNKawc3KeFs';
let text = document.getElementById('text').value;
let apiUrl = 'https://www.yakitome.com/api/rest/tts?api_key=' + secretKey + '&voice=Audrey&speed=5&text=' + text;
var msg = new SpeechSynthesisUtterance(text)
window.speechSynthesis.speak(msg)
var synth = window.speechSynthesis;
var voices = synth.getVoices();
console.log('voices', voices)
}
// let message = 'hello asif vora kem cho'
// var msg = new SpeechSynthesisUtterance(message)
// console.log('voices', msg)
// window.speechSynthesis.speak(msg)
</script> -->
</body>
</html>