-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathdemo.js
More file actions
119 lines (104 loc) · 2.85 KB
/
Copy pathdemo.js
File metadata and controls
119 lines (104 loc) · 2.85 KB
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
// Global UI elements:
// - log: event log
// - trans: transcription window
// Global objects:
// - tt: simple structure for managing the list of hypotheses
// - dictate: dictate object with control methods 'init', 'startListening', ...
// and event callbacks onResults, onError, ...
var tt = new Transcription();
var dictate = new Dictate({
server : "wss://bark.phon.ioc.ee:8443/dev/duplex-speech-api/ws/speech",
serverStatus : "wss://bark.phon.ioc.ee:8443/dev/duplex-speech-api/ws/status",
recorderWorkerPath : '../lib/recorderWorker.js',
onReadyForSpeech : function() {
__message("READY FOR SPEECH");
__status("Kuulan ja transkribeerin...");
},
onEndOfSpeech : function() {
__message("END OF SPEECH");
__status("Transkribeerin...");
},
onEndOfSession : function() {
__message("END OF SESSION");
__status("");
},
onServerStatus : function(json) {
__serverStatus(json.num_workers_available + ':' + json.num_requests_processed);
if (json.num_workers_available == 0) {
$("#buttonStart").prop("disabled", true);
$("#serverStatusBar").addClass("highlight");
} else {
$("#buttonStart").prop("disabled", false);
$("#serverStatusBar").removeClass("highlight");
}
},
onPartialResults : function(hypos) {
// TODO: demo the case where there are more hypos
tt.add(hypos[0].transcript, false);
__updateTranscript(tt.toString());
},
onResults : function(hypos) {
// TODO: demo the case where there are more results
tt.add(hypos[0].transcript, true);
__updateTranscript(tt.toString());
// diff() is defined only in diff.html
if (typeof(diff) == "function") {
diff();
}
},
onError : function(code, data) {
__error(code, data);
__status("Viga: " + code);
dictate.cancel();
},
onEvent : function(code, data) {
__message(code, data);
}
});
// Private methods (called from the callbacks)
function __message(code, data) {
log.innerHTML = "msg: " + code + ": " + (data || '') + "\n" + log.innerHTML;
}
function __error(code, data) {
log.innerHTML = "ERR: " + code + ": " + (data || '') + "\n" + log.innerHTML;
}
function __status(msg) {
statusBar.innerHTML = msg;
}
function __serverStatus(msg) {
serverStatusBar.innerHTML = msg;
}
function __updateTranscript(text) {
$("#trans").val(text);
}
// Public methods (called from the GUI)
function toggleLog() {
$(log).toggle();
}
function clearLog() {
log.innerHTML = "";
}
function clearTranscription() {
tt = new Transcription();
$("#trans").val("");
}
function startListening() {
dictate.startListening();
}
function stopListening() {
dictate.stopListening();
}
function cancel() {
dictate.cancel();
}
function init() {
dictate.init();
}
function showConfig() {
var pp = JSON.stringify(dictate.getConfig(), undefined, 2);
log.innerHTML = pp + "\n" + log.innerHTML;
$(log).show();
}
window.onload = function() {
init();
};