This repository has been archived by the owner on Nov 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
72 lines (63 loc) · 1.84 KB
/
main.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
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
/*-----------------------------
Global variables
------------------------------*/
var commands = ["carica", "scarica", "informazioni", "crea", "elimina"];
var Commands = {
CARICA: 0,
SCARICA: 1,
INFORMAZIONI: 2,
CREA: 3,
ELIMINA: 4,
NONE: -1
};
var noteTextarea = $('#note-textarea');
var instructions = $('#recording-instructions');
var noteContent = '';
try {
var SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
var recognition = new SpeechRecognition();
}
catch(e) {
console.error(e);
$('.no-browser-support').show();
$('.app').hide();
}
/*-----------------------------
App buttons and input
------------------------------*/
$('#start-record-btn').on('click', function(e) {
if (noteContent.length) {
noteContent += ' ';
}
recognition.start();
instructions.text('Voice recognition turned on.');
});
$('#pause-record-btn').on('click', function(e) {
recognition.stop();
instructions.text('Voice recognition turned off.');
});
$('#reset-btn').on('click', function(e) {
recognition.stop();
instructions.text('Presse the START RECOGNITION button to allow access');
noteTextarea.val('');
//azzera il contenuto registrato
noteContent='';
if (document.contains(document.getElementById("stud-img")))
document.getElementById("stud-img").remove();
if (document.contains(document.getElementById("demo")))
document.getElementById("demo").remove();
});
$('#speak-btn').on('click', function(e) {
var tempV=0;
recognition.stop();
sTalking();
for(var i=0;i<noteContent.length;i++){
tempV+=75;
}
readOutLoud(noteContent);
setTimeout(fTalking, tempV);
});
// Sync the text inside the text area with the noteContent variable.
noteTextarea.on('input', function() {
noteContent = $(this).val();
});