@@ -39,7 +39,7 @@ describe('speech_to_text', function() {
39
39
session_id : 'foo' ,
40
40
new_session_uri : '#' ,
41
41
recognize : '#' ,
42
- observe_result : '#' ,
42
+ observe_result : '#'
43
43
} ,
44
44
new_session_with_cookie = extend ( { } , new_session , { cookie_session : 'foobar' } ) ;
45
45
@@ -226,6 +226,75 @@ describe('speech_to_text', function() {
226
226
} ) ;
227
227
} ) ;
228
228
229
+ describe ( 'recognizeStream()' , function ( ) {
230
+ var path = '/v1/sessions/foo/recognize' ,
231
+ payload = {
232
+ session_id : 'foo' ,
233
+ cookie_session : 'foobar' ,
234
+ content_type : 'audio/l16; rate=41100'
235
+ } ,
236
+ service_response = {
237
+ result : [ {
238
+ alternative : [ {
239
+ transcript : 'one two three'
240
+ } ] ,
241
+ 'final' : true
242
+ } ] ,
243
+ result_index : 0
244
+ } ;
245
+
246
+ var options = {
247
+ content_type : 'audio/l16;rate=41100' ,
248
+ "continuous" : true ,
249
+ "timestamps" :true ,
250
+ "inactivity_timeout" : - 1 ,
251
+ "max_alternatives" : 1 ,
252
+ "interim_results" : false ,
253
+ "keywords" : [ 'one' , 'Three' ] ,
254
+ "keywords_threshold" : 0.9 ,
255
+ "word_alternatives_threshold" : 0.25
256
+ } ;
257
+ var recognizeStream = speech_to_text . createRecognizeStream ( options ) ;
258
+ var DEBUG = fs . createReadStream ( __dirname + '/resources/audio.wav' ) . pipe ( recognizeStream ) ;
259
+ recognizeStream . setEncoding ( 'utf8' ) ;
260
+
261
+ it ( 'should have expected _events' , function ( done ) {
262
+ assert . equal ( true , recognizeStream . hasOwnProperty ( '_events' ) ) ;
263
+ assert . equal ( true , recognizeStream . _events . hasOwnProperty ( 'connect' ) ) ;
264
+ assert . equal ( true , recognizeStream . _events . hasOwnProperty ( 'connection-close' ) ) ;
265
+ assert . equal ( true , recognizeStream . _events . hasOwnProperty ( 'results' ) ) ;
266
+ assert . equal ( true , recognizeStream . _events . hasOwnProperty ( 'error' ) ) ;
267
+ assert . equal ( true , recognizeStream . _events . hasOwnProperty ( 'finish' ) ) ;
268
+ } ) ;
269
+
270
+ recognizeStream . on ( 'connect' , function ( socket ) {
271
+ it ( 'should have a socket connection with a correct config' , function ( done ) {
272
+ assert . notStrictEqual ( socket , socket . config , socket . config . fragmentOutgoingMessages ) ;
273
+ assert . notStrictEqual ( socket , socket . config , socket . config . fragmentOutgoingMessages ) ;
274
+ } ) ;
275
+ } ) ;
276
+
277
+ recognizeStream . on ( 'error' , function ( err ) {
278
+ it ( 'should throw ECONNRESET with bad credentials' , function ( done ) {
279
+ assert . equal ( err . code , 'ECONNRESET' ) ;
280
+ assert . equal ( err . errno , 'ECONNRESET' ) ;
281
+ } )
282
+ } ) ;
283
+
284
+ recognizeStream . on ( 'connection-close' , function ( reasonCode , description ) {
285
+ console . log ( 139 , reasonCode ) ;
286
+ console . log ( 140 , description ) ;
287
+ } ) ;
288
+
289
+ recognizeStream . on ( 'results' , function ( obj ) {
290
+ console . log ( JSON . stringify ( obj ) ) ;
291
+ it ( 'should generate a valid response' , function ( done ) {
292
+ assert . equal ( obj , service_response ) ;
293
+ } ) ;
294
+ } ) ;
295
+ } ) ;
296
+
297
+
229
298
describe ( 'recognizeLive()' , function ( ) {
230
299
var path = '/v1/sessions/foo/recognize' ,
231
300
payload = {
0 commit comments