-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
146 lines (127 loc) · 5.85 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<script type="text/javascript" src="https://yastatic.net/jquery/2.2.0/jquery.min.js"></script>
<script type="text/javascript" src="https://download.yandex.ru/webspeechkit/webspeechkit-1.0.0.js"></script>
<script type="text/javascript" src="https://download.yandex.ru/webspeechkit/webspeechkit-settings.js"></script>
<script>
window.onload = function() {
var timer = null;
window.doAnalyze = function(text, data) {
var result = null;
if(!data || !data.Morph) {
result = 'Ошибка при анализе :(';
} else {
var words = $(data.Morph).map(function(idx, el) {
if(!el || !el.Lemmas || !el.Lemmas[0].Grammems) {
return [[null, ""]]
}
return [[el.Lemmas[0].Text, el.Lemmas[0].Grammems[0].split(' ')]]
});
result = 'Запрос проанализирован<br/>';
$(words).map(function(idx, el) {
var word = el[0];
var params = el[1];
console.log(word, params);
if(params.indexOf('S') >= 0) {
result += 'Субьект: ' + word + '<br/>';
}
if(params.indexOf('V') >= 0) {
result += 'Действие: ' + word + '<br/>';
if(word=='открывать')
$.get( "http://192.168.1.125/WIN=OPEN" );
if(word=='закрыть')
$.get( "http://192.168.1.125/WIN=CLOSE" );
}
});
}
$(".lead").html('Вы сказали: ' + text + '<br/>' + result);
}
var doRecognize = function(text) {
if(text) {
$(".lead").text('!Вы сказали: ' + text + '\nАнализируем…');
$.getJSON("https://vins-markup.voicetech.yandex.net/markup/0.x/?text="+ text +"&key=").done(function(data) {
doAnalyze(text, data);
$("#button").attr({disabled: false}).removeClass('disabled').html('Нажмите и скажите ещё')
}).fail(function(){
doAnalyze(text, null)
$("#button").attr({disabled: false}).removeClass('disabled').html('Нажмите и скажите ещё')
});
} else {
$("#button").attr({disabled: false}).removeClass('disabled').html('Нажмите и скажите ещё')
}
clearInterval(timer);
timer = null;
}
var spotter = function() {
window.spotter = new ya.speechkit.Spotter({
doneCallback: function (text) {
console.log("Spotter You've said: " + text);
recognize();
},
initCallback: function () {
console.log("Spotter You may speak now");
},
errorCallback: function (err) {
console.log("Spotter Something gone wrong: " + err);
doRecognize();
},
model: 'freeform', // Model name for recognition process
lang: 'ru-RU', //Language for recognition process
apiKey: '',
phrase: 'Записывай, Завершить запись'
})
window.spotter.start();
}
var recognize = function() {
ya.speechkit.recognize({
doneCallback: function (text) {
console.log("You've said: " + text);
doRecognize(text);
},
initCallback: function () {
console.log("You may speak now");
},
errorCallback: function (err) {
console.log("Something gone wrong: " + err);
doRecognize();
},
model: 'freeform', // Model name for recognition process
lang: 'ru-RU', //Language for recognition process
apiKey: '' // ваш ключ API
});
$("#button").attr({disabled: true}).addClass('disabled').html('Слушаем!')
timer = setTimeout(function() {
$(".lead").text('Говорите смелее!')
}, 10000);
}
$("#button").click(recognize);
new ya.speechkit.Equalizer('equalizer');
spotter();
};
</script>
<title>Narrow Jumbotron Template for Bootstrap</title>
<!-- Bootstrap core CSS -->
<link href="https://v4-alpha.getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="https://v4-alpha.getbootstrap.com/examples/narrow-jumbotron/narrow-jumbotron.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="header clearfix">
<h3 class="text-muted">Открывашка</h3>
</div>
<div class="jumbotron">
<p id="lead" class="lead">Вы пока ничего ещё не сказали</p>
<p><a class="btn btn-lg btn-success" id="button" href="#" role="button">Нажмите и говорите</a></p>
</div>
<p id="equalizer" ></p>
<p id="textline" ></p>
<footer class="footer">
</footer>
</div> <!-- /container -->
</body>
</html>