@@ -9,6 +9,8 @@ const ERROR = {
9
9
INVALID_INDEX : "INVALID_INDEX"
10
10
}
11
11
12
+ const ARECORD_FILE_LIMIT = 1500000000 // 1.5 GB
13
+
12
14
const CloudSpeechRecognizer = { }
13
15
CloudSpeechRecognizer . init = recognizer => {
14
16
const csr = new stream . Writable ( )
@@ -147,15 +149,50 @@ Sonus.init = (options, recognizer) => {
147
149
}
148
150
149
151
Sonus . start = sonus => {
150
- sonus . mic = record . start ( {
152
+ sonus . mic = Recorder ( sonus )
153
+
154
+ if ( sonus . recordProgram === "arecord" ) {
155
+ ArecordHelper . init ( sonus )
156
+ }
157
+
158
+ sonus . mic . pipe ( sonus . detector )
159
+ sonus . started = true
160
+ }
161
+
162
+ const Recorder = ( sonus ) => {
163
+ return record . start ( {
151
164
threshold : 0 ,
152
165
device : sonus . device || null ,
153
166
recordProgram : sonus . recordProgram || "rec" ,
154
167
verbose : false
155
168
} )
169
+ }
170
+
171
+ const ArecordHelper = { byteCount : 0 }
172
+ ArecordHelper . init = ( sonus ) => {
173
+ ArecordHelper . track ( sonus )
174
+ }
175
+
176
+ ArecordHelper . track = ( sonus ) => {
177
+ sonus . mic . on ( 'data' , data => {
178
+ ArecordHelper . byteCount += data . length
179
+
180
+ // When we get to arecord wav file limit, reset
181
+ if ( ArecordHelper . byteCount > ARECORD_FILE_LIMIT ) {
182
+ ArecordHelper . restart ( sonus )
183
+ }
184
+ } )
185
+ }
156
186
187
+ ArecordHelper . restart = ( sonus ) => {
188
+ sonus . mic . unpipe ( sonus . detector )
189
+ record . stop ( )
190
+
191
+ // Restart the audio recording
192
+ sonus . mic = Recorder ( sonus )
193
+ ArecordHelper . byteCount = 0
194
+ ArecordHelper . track ( sonus )
157
195
sonus . mic . pipe ( sonus . detector )
158
- sonus . started = true
159
196
}
160
197
161
198
Sonus . trigger = ( sonus , index , hotword ) => sonus . trigger ( index , hotword )
0 commit comments