-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
320 lines (293 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width" />
<title>Iara SDK Syncfusion Adapter</title>
<link
href="https://cdn.syncfusion.com/ej2/22.1.34/ej2-base/styles/material.css"
rel="stylesheet"
type="text/css"
rel="nofollow"
/>
<link
href="https://cdn.syncfusion.com/ej2/22.1.34/ej2-buttons/styles/material.css"
rel="stylesheet"
type="text/css"
rel="nofollow"
/>
<link
href="https://cdn.syncfusion.com/ej2/22.1.34/ej2-inputs/styles/material.css"
rel="stylesheet"
type="text/css"
rel="nofollow"
/>
<link
href="https://cdn.syncfusion.com/ej2/22.1.34/ej2-popups/styles/material.css"
rel="stylesheet"
type="text/css"
rel="nofollow"
/>
<link
href="https://cdn.syncfusion.com/ej2/22.1.34/ej2-lists/styles/material.css"
rel="stylesheet"
type="text/css"
rel="nofollow"
/>
<link
href="https://cdn.syncfusion.com/ej2/22.1.34/ej2-navigations/styles/material.css"
rel="stylesheet"
type="text/css"
rel="nofollow"
/>
<link
href="https://cdn.syncfusion.com/ej2/22.1.34/ej2-splitbuttons/styles/material.css"
rel="stylesheet"
type="text/css"
rel="nofollow"
/>
<link
href="https://cdn.syncfusion.com/ej2/22.1.34/ej2-dropdowns/styles/material.css"
rel="stylesheet"
type="text/css"
rel="nofollow"
/>
<!-- EJ2 Document Editor theme -->
<link
href="https://cdn.syncfusion.com/ej2/22.1.34/ej2-documenteditor/styles/material.css"
rel="stylesheet"
type="text/css"
rel="nofollow"
/>
<link
href="https://cdn.syncfusion.com/ej2/24.1.41/ej2-ribbon/styles/material.css"
rel="stylesheet"
type="text/css"
rel="nofollow"
/>
<!-- EJ2 Document Editor dependent scripts -->
<script
src="https://cdn.syncfusion.com/ej2/22.1.34/ej2-base/dist/global/ej2-base.min.js"
type="text/javascript"
></script>
<script
src="https://cdn.syncfusion.com/ej2/22.1.34/ej2-data/dist/global/ej2-data.min.js"
type="text/javascript"
></script>
<script
src="https://cdn.syncfusion.com/ej2/22.1.34/ej2-svg-base/dist/global/ej2-svg-base.min.js"
type="text/javascript"
></script>
<script
src="https://cdn.syncfusion.com/ej2/22.1.34/ej2-file-utils/dist/global/ej2-file-utils.min.js"
type="text/javascript"
></script>
<script
src="https://cdn.syncfusion.com/ej2/22.1.34/ej2-compression/dist/global/ej2-compression.min.js"
type="text/javascript"
></script>
<script
src="https://cdn.syncfusion.com/ej2/22.1.34/ej2-pdf-export/dist/global/ej2-pdf-export.min.js"
type="text/javascript"
></script>
<script
src="https://cdn.syncfusion.com/ej2/22.1.34/ej2-buttons/dist/global/ej2-buttons.min.js"
type="text/javascript"
></script>
<script
src="https://cdn.syncfusion.com/ej2/22.1.34/ej2-popups/dist/global/ej2-popups.min.js"
type="text/javascript"
></script>
<script
src="https://cdn.syncfusion.com/ej2/22.1.34/ej2-splitbuttons/dist/global/ej2-splitbuttons.min.js"
type="text/javascript"
></script>
<script
src="https://cdn.syncfusion.com/ej2/22.1.34/ej2-inputs/dist/global/ej2-inputs.min.js"
type="text/javascript"
></script>
<script
src="https://cdn.syncfusion.com/ej2/22.1.34/ej2-lists/dist/global/ej2-lists.min.js"
type="text/javascript"
></script>
<script
src="https://cdn.syncfusion.com/ej2/22.1.34/ej2-navigations/dist/global/ej2-navigations.min.js"
type="text/javascript"
></script>
<script
src="https://cdn.syncfusion.com/ej2/22.1.34/ej2-dropdowns/dist/global/ej2-dropdowns.min.js"
type="text/javascript"
></script>
<script
src="https://cdn.syncfusion.com/ej2/22.1.34/ej2-calendars/dist/global/ej2-calendars.min.js"
type="text/javascript"
></script>
<script
src="https://cdn.syncfusion.com/ej2/22.1.34/ej2-charts/dist/global/ej2-charts.min.js"
type="text/javascript"
></script>
<script
src="https://cdn.syncfusion.com/ej2/22.1.34/ej2-office-chart/dist/global/ej2-office-chart.min.js"
type="text/javascript"
></script>
<!-- EJ2 Document Editor script -->
<script
src="https://cdn.syncfusion.com/ej2/22.1.34/ej2-documenteditor/dist/global/ej2-documenteditor.min.js"
type="text/javascript"
></script>
<script
src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js"
type="text/javascript"
></script>
<!-- Iara Speech SDK -->
<script src="https://cdn.iarahealth.com/sdk/javascript/latest/iara-speech.min.js"></script>
</head>
<body>
<div
style="
background: #ffb6b6;
border: 2px solid black;
padding: 0 5px 5px 15px;
width: 250px;
"
>
<h3>Dados de acesso:</h3>
<p>
userId:
<input type="text" id="userId" value="" />
</p>
<p>
apiToken:
<input type="text" id="apiToken" value="" />
</p>
<button id="btnSalvar">Salvar</button>
</div>
<div id="editor-container"></div>
<div>
<p>Status:</p>
<pre
id="saidaStatus"
style="background: #addeff; border: 1px solid black; padding: 10px"
></pre>
<pre
id="console"
style="background: #f1f1f1; border: 1px solid black; padding: 20px"
>
Status: ?</pre
>
</div>
<button id="btnStart">Iniciar</button>
<button id="btnStop">Parar</button>
<script type="module">
import { IaraSyncfusionAdapter } from "/dist/adapters.mjs";
window.onload = () => {
window.ej.documenteditor.DocumentEditorContainer.Inject(
window.ej.documenteditor.Toolbar
);
const editorContainer =
new window.ej.documenteditor.DocumentEditorContainer({
enableToolbar: true,
height: "800px",
serviceUrl:
"https://api.iarahealth.com/speech/syncfusion/api/documenteditor/",
});
editorContainer.appendTo("#editor-container");
// Elementos na página usados para graconst audio.
const botaoStart = document.getElementById("btnStart");
const botaoStop = document.getElementById("btnStop");
const elementoConsole = document.getElementById("console");
const elementoSaidaStatus = document.getElementById("saidaStatus");
// Informações de conexão aos serviços da Iara
const myUserId = document.getElementById("userId").value;
const myApiToken = document.getElementById("apiToken").value;
// Instancia o reconhecedor da Iara e informa que resultados intermediários
// de inferência devem ser emitidos.
const recognition = new IaraSpeechRecognition();
recognition.interimResults = true;
const syncfusionAdapter = new IaraSyncfusionAdapter(
editorContainer.documentEditor,
recognition
);
// Botão de Stop só é ativado quando o usuário clica no botão "Iniciar".
botaoStop.disabled = true;
// Define o botão que salva as credenciais e sua função
const botaoSalvar = document.getElementById("btnSalvar");
botaoSalvar.addEventListener("click", function () {
elementoSaidaStatus.innerHTML =
"Inicializando com base nas credenciais informadas...";
salvaCredenciaisDepoisInicializa();
});
function salvaCredenciaisDepoisInicializa() {
// Informações de conexão aos serviços da Iara
const myUserId = document.getElementById("userId").value;
const myApiToken = document.getElementById("apiToken").value;
// Inicializa o SDK, i.e. autenticação, checa o ALS, baixa modelo de voz, etc.
recognition
.init({
userId: myUserId,
apiToken: myApiToken,
forceConnection: true,
engine: "Iara Desktop",
useVAD: true,
})
.done(function (e) {
elementoConsole.innerHTML =
'Pronto para gravar. Pressione o botão "Iniciar".';
// O evento principal do reconhecimento de voz é o "onresult", chamado quando
// algum audio na entrada é reconhecido.
recognition.onresult = function (event) {
// O parâmetro "event" contem uma propriedade chamada "detail", que é um
// objeto IaraSpeechRecognitionResult. A propriedade "transcript" desse
// resultado contém o texto que a Iara reconheceu baseados no audio de entrada.
// Além disso, a propriedade "isFinal" do objeto "detail" informa se essa
// inferência é intermediária (isFinal=false) ou final (isFinal=true).
const text = event.detail.transcript.toLowerCase();
const intermediate = event.detail.isFinal == false;
elementoSaidaStatus.innerText = JSON.stringify(
event.detail,
null,
4
);
if (intermediate == false) {
console.log("Texto reconhecido:" + text);
} else {
console.log("Texto INTERMEDIÁRIO reconhecido:" + text);
}
};
botaoStart.addEventListener("click", function () {
botaoStart.disabled = true;
botaoStop.disabled = false;
elementoConsole.innerHTML = "Preparando gravação...";
recognition.start(function () {
elementoConsole.innerHTML =
'Gravação em andamento (pressione "Parar" para finalizar).';
});
});
botaoStop.addEventListener("click", function () {
elementoConsole.innerHTML = "Gravação finalizada.";
botaoStart.disabled = false;
botaoStop.disabled = true;
recognition.stop();
});
})
.fail(function (e) {
// Algum problema aconteceu. O parâmetro "e" contem várias informações sobre o erro.
elementoConsole.innerHTML =
"Algum problema na inicialização da Iara: " +
e.detail.developerMessage;
console.error("Problema: " + e.detail.developerMessage);
})
.progress(function (e) {
// Esse método é invocado várias vezes pelo SDK ao longo de sua inicialização.
// Você pode usar ele para acompanhar os passos da inicialização, para informar
// ao seu usuário que seu modelo de voz está sendo baixado, por exemplo.
elementoConsole.innerHTML =
"A Iara está inicializando: " + e.detail.type;
console.log("Inicializando: " + e.detail.type);
});
}
};
</script>
</body>
</html>