-
Notifications
You must be signed in to change notification settings - Fork 127
/
Copy pathvoice.js
137 lines (116 loc) · 4.09 KB
/
voice.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
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
/*
Notes:
-----
Provides speech input processing. See https://github.com/TalAter/annyang and https://www.talater.com/annyang/.
Depends on <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/annyang/1.1.0/annyang.min.js"></script>.
Requires an HTML5 browser that supports voice input, currently only Google Chrome but IE12 will also have this feature.
*/
var CZ;
(function (CZ) {
(function (Voice) {
// wrapper functions for each speech input command
function Find(item)
{
if (typeof item !== 'string') return;
CZ.Service.getSearch(item).done(function (results)
{
if (results === null || results.d.length === 0)
{
// tell user could not find
alert('Could not find "' + item + '".');
}
else
{
// close other panes and display timelines
CZ.HomePageViewModel.closeAllForms();
CZ.StartPage.hide();
// navigate to first item found
var result = results.d[0];
var resultIdPrefixes =
{
0: 'e',
1: 't',
2: ''
};
var resultTypes =
{
0: 'exhibit',
1: 'timeline',
2: 'contentItem'
};
CZ.Search.goToSearchResult
(
resultIdPrefixes[result.objectType] + result.id,
resultTypes[ result.objectType]
);
}
});
}
function MoveTo(item)
{
if (typeof item !== 'string') return;
alert('show me ' + item);
}
function ShowHomePage()
{
alert('show home page');
}
function ShowTimelines()
{
alert('show timelines');
}
function SwitchCollection(item)
{
if (typeof item !== 'string') return;
alert('explore ' + item);
}
function TourLast()
{
alert('next item');
}
function TourNext()
{
alert('previous item');
}
function TourPause()
{
alert('pause tour');
}
function TourResume()
{
alert('resume tour');
}
// make each wrapper public so can be called later by speech engine
Voice.Find = Find;
Voice.MoveTo = MoveTo;
Voice.ShowHomePage = ShowHomePage;
Voice.ShowTimelines = ShowTimelines;
Voice.SwitchCollection = SwitchCollection;
Voice.TourLast = TourLast;
Voice.TourNext = TourNext;
Voice.TourPause = TourPause;
Voice.TourResume = TourResume;
// if speech is enabled in both web config and browser
if (constants.speechInputEnabled && annyang)
{
// map speech commands to wrappers
var commands =
{
'explore *item': CZ.Voice.SwitchCollection,
'pause tour': CZ.Voice.TourPause,
'resume tour': CZ.Voice.TourResume,
'previous item': CZ.Voice.TourLast,
'next item': CZ.Voice.TourNext,
'show timelines': CZ.Voice.ShowTimelines,
'show home page': CZ.Voice.ShowHomePage,
'show me *item': CZ.Voice.MoveTo,
'find *item': CZ.Voice.Find // <-- currently this is the only item testing with
};
// initiate speech engine
annyang.setLanguage('en');
annyang.addCommands(commands);
annyang.start();
}
})(CZ.Voice || (CZ.Voice = {}));
var Voice = CZ.Voice;
})(CZ || (CZ = {}));