forked from syzer/speech-recognition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
234 lines (216 loc) · 6.15 KB
/
app.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
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
function recognizeSpeech(phrases, onresult) {
var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition
var SpeechGrammarList = SpeechGrammarList || webkitSpeechGrammarList
const grammar = '#JSGF V1.0; grammar phrase; public <phrase> = ' + phrases.join(' | ') + ';';
let recognition = new SpeechRecognition()
let speechRecognitionList = new SpeechGrammarList()
speechRecognitionList.addFromString(grammar, 1)
recognition.grammars = speechRecognitionList
recognition.lang = 'en-US'
recognition.interimResults = false
recognition.continuous = true
recognition.maxAlternatives = 1
recognition.start()
recognition.onspeechend = () => {
console.log('end', new Date())
}
recognition.onerror = (event) => console.error(event)
recognition.onresult = onresult
}
let bingoBitmap = _.times(5, _.constant(
_.times(5, _.constant(0))
))
const isBingoRows = (arr) => !!arr.find(
row => row.reduce(_.add) === row.length
)
const isBingoCols = (bingoBitmap) => {
for (let i in bingoBitmap) {
let sum = 0
for (let j in bingoBitmap) {
sum += bingoBitmap[j][i]
if (sum === bingoBitmap.length) {
return true
}
}
}
return false
}
const isBingo = (arr) => isBingoCols(arr) || isBingoRows(arr)
const maybeMark = (phrase, bingoBoard, bingoBitmap) =>
bingoBoard.filter((row, i) =>
row.filter((word, j) => {
if (_.toLower(phrase) === _.toLower(word)) {
bingoBitmap[ i ][ j ] = 1
return true
}
return false
})
)
const binBy = (groupSize, arr) => (arr).reduce((acc, curr, i) => {
acc[i % groupSize] = acc[i % groupSize] || []
acc[i % groupSize].push(curr)
return acc
}, [])
angular
.module('game', [])
.controller('BingoCtrl', BingoCtrl)
.filter('capitalize', capitalize)
const phrases = _.shuffle([
'column oriented',
'vertical database',
'sharding',
'ZooKeeper',
'data warehouse',
'Hadoop',
'velocity',
'hive',
'ETL',
'Kafka',
'data volume',
'fast data',
'mapreduce',
'cloud',
'Cassandra',
'real-time',
'analytics',
'unstructured data',
'scoop',
'no sequel',
'big data',
'scrum',
'data warehouse',
'e-commerce',
'performance'
])
const similarSounding = (w) => ({
atm: 'etl',
atl: 'etl',
'atl.com': 'etl',
guitar: 'data',
allen: 'analytics',
btl: 'etl',
bigcommerce: 'e-commerce',
big: 'big data',
buzz: 'fast data',
call: 'cloud',
clown: 'cloud',
cop: 'kafka',
costco: 'kafka',
cough: 'kafka',
'costco.com': 'kafka',
common: 'column oriented',
commerce: 'e-commerce',
charlene: 'sharding',
charting: 'sharding',
chardon: 'sharding',
charging: 'sharding',
club: 'cloud',
columbia: 'column oriented',
construction: 'unstructured data',
chrome: 'scrum',
cream: 'scrum',
crime: 'scrum',
california: 'data volume',
conundrum: 'cassandra',
dictator: 'big data',
ecommerce: 'e-commerce',
athleta: 'fast data',
fox: 'fast data',
farting: 'sharding',
finding: 'sharding',
firstdata: 'fast data',
first: 'fast data',
flowers: 'cloud',
german: 'scrum',
harding: 'sharding',
hi: 'hive',
high: 'hive',
how: 'hadoop',
honda: 'hadoop',
hospital: 'fast data',
'high-end': 'hive',
'high-fiber': 'hive',
higher: 'hive',
hydro: 'hadoop',
home: 'column oriented',
horton: 'data volume',
knife: 'hive',
kobe: 'column oriented',
life: 'hive',
love: 'data volume',
mount: 'mapreduce',
maureen: 'column oritented',
produce: 'mapreduce',
performers: 'performance',
news: 'mapreduce',
reduce: 'mapreduce',
juice: 'mapreduce',
santa: 'fast data',
patagonia: 'data volume',
oriented: 'column oriented',
oriental: 'column oriented',
oregon: 'column oriented',
reviews: 'mapreduce',
roaming: 'data volume',
mattresses: 'mapreduce',
secret: 'no squel',
sleep: 'no sequel',
scrub: 'scrum',
scope: 'scoop',
scuba: 'scoop',
scram: 'scrum',
school: 'scoop',
skyrim: 'scrum',
sharing: 'sharding',
sequins: 'sharding',
spawn: 'scoop',
starting: 'sharding',
strong: 'scrum',
structured: 'unstructured data',
sequel: 'no sequel',
squad: 'scoop',
roadhouse: 'data warehouse',
rhel: 'etl',
real: 'real-time',
house: 'data warehouse',
translator: 'fast data',
translate: 'fast data',
tractor: 'unstructured data',
time: 'real-time',
understanding: 'sharding',
verdict: 'vertical database',
vertica: 'vertical database',
volume: 'data volume',
vertical: 'vertical database',
warehouse: 'data warehouse',
warehousing: 'data warehouse'
}[w] || w)
function BingoCtrl($scope) {
$scope.bingoBitmap = bingoBitmap
$scope.isBingo = isBingo(bingoBitmap)
$scope.picked = []
$scope.bingoBoard = binBy(5, phrases)
$scope.startRecognizing = () =>
recognizeSpeech(phrases, (event) => {
const lastResult = _.last(event.results)[0]
const speechTranscript = _.toLower(lastResult.transcript)
.split(' ')
.map(similarSounding)
.join(' ')
console.log(speechTranscript, ':', lastResult.transcript, lastResult.confidence)
$scope.picked = _.uniq($scope.picked.concat(newMatchedWords(speechTranscript)))
$scope.picked.map(w => maybeMark(w, $scope.bingoBoard, bingoBitmap))
$scope.isBingo = isBingo(bingoBitmap)
$scope.$apply()
})
const newMatchedWords = (transcript) =>
phrases.map(_.toLower)
.filter(p => _.includes(transcript, p))
const isPicked = (word) => _.includes($scope.picked, _.toLower(word))
$scope.isHighlight = (word) => isPicked(word) ? 'picked' : ''
window.scope = $scope
}
// http://stackoverflow.com/questions/30207272/capitalize-the-first-letter-of-string-in-angularjs
function capitalize() {
return str => str.charAt(0).toUpperCase() + str.slice(1)
}