-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewModel.js
More file actions
executable file
·114 lines (94 loc) · 3.19 KB
/
Copy pathviewModel.js
File metadata and controls
executable file
·114 lines (94 loc) · 3.19 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
(function(global){
global.robotDictee.createViewModel=createViewModel;
function createViewModel(textToSpeechEngine){
var _predefinedDictations = ko.observable(global.robotDictee.predefinedDictations)
var _groupedDictations = ko.computed(function() {
var groups = {};
var order = [];
(_predefinedDictations() || []).forEach(function(d) {
var match = d.title.match(/^(Thème \d+)/);
var theme = match ? match[1] : 'Autres';
if (!groups[theme]) {
groups[theme] = { theme: theme, dictations: [] };
order.push(theme);
}
groups[theme].dictations.push(d);
});
return order.map(function(t) { return groups[t]; });
})
var _newDictationText = ko.observable("");
var _dictation = ko.observable();
var _currentWordText = ko.observable("");
var _segmentSaidSubscription=null;
var _currentPage = ko.observable('newDictation');
_currentWordText.subscribe(onCurrentWordTextChanged);
return {
dictation:_dictation,
currentWordText:_currentWordText,
predefinedDictations: _predefinedDictations,
groupedDictations: _groupedDictations,
usePredefinedDictation,
newDictationText:_newDictationText,
createDictation,
sayCurrentSegment,
showAboutPage,
showMobileHowToPage,
currentPage:_currentPage
}
function onCurrentWordTextChanged(newValue){
if(getLastChar(_currentWordText())==' '){
commitWord();
}
}
function getLastChar(value){
return value.substr(value.length - 1);
}
function commitWord(){
var valueToCommit = _currentWordText().rtrim();
_currentWordText("");
_dictation().commitCurrentWord(valueToCommit);
}
function sayCurrentSegment(event){
_dictation().sayCurrentSegment();
document.getElementById("currentWordText").focus();
}
function onSegmentSaid(value){
textToSpeechEngine.textToSpeech(value);
}
//read-only
var _dictation = ko.computed(function() {
return _dictation();
});
function usePredefinedDictation(predefinedDictation){
if(predefinedDictation.audioMap){
textToSpeechEngine = global.robotDictee.createStaticAudioTextToSpeechEngine(predefinedDictation.audioMap);
} else {
textToSpeechEngine = global.robotDictee.createSpeechSynthesisTextToSpeechEngine();
}
startDictation(predefinedDictation.text);
}
function createDictation(){
textToSpeechEngine = global.robotDictee.createSpeechSynthesisTextToSpeechEngine();
startDictation(_newDictationText());
}
function startDictation(text){
var newDictation = global.robotDictee.createDictation(text);
_dictation(newDictation);
_currentPage("dictation");
subscribeToSegmentSaid();
sayCurrentSegment();
}
function subscribeToSegmentSaid(){
if(_segmentSaidSubscription){
_segmentSaidSubscription.dispose();
}
_segmentSaidSubscription=_dictation().segmentSaid.subscribe(onSegmentSaid);
}
function showAboutPage(){
_currentPage("about");
}
function showMobileHowToPage(){
_currentPage("mobileHowTo");
}
}
})(this)