@@ -35,7 +35,7 @@ var request = require('request');
35
35
var streamEvents = require ( 'stream-events' ) ;
36
36
var through = require ( 'through2' ) ;
37
37
var util = require ( 'util' ) ;
38
- var v1beta1 = require ( './v1beta1 ' ) ;
38
+ var v1 = require ( './v1 ' ) ;
39
39
40
40
/**
41
41
* The [Cloud Speech API](https://cloud.google.com/speech/docs) enables easy
@@ -67,19 +67,14 @@ function Speech(options) {
67
67
} ) ;
68
68
69
69
this . api = {
70
- Speech : v1beta1 ( options ) . speechClient ( options )
70
+ Speech : v1 ( options ) . speechClient ( options )
71
71
} ;
72
72
73
73
var config = {
74
74
baseUrl : 'speech.googleapis.com' ,
75
75
projectIdRequired : false ,
76
76
service : 'speech' ,
77
77
protoServices : {
78
- Speech : {
79
- path : googleProtoFiles . speech . v1beta1 ,
80
- service : 'cloud.speech' ,
81
- apiVersion : 'v1beta1'
82
- } ,
83
78
Operations : {
84
79
path : googleProtoFiles ( 'longrunning' , 'operations.proto' ) ,
85
80
service : 'longrunning'
@@ -97,20 +92,13 @@ function Speech(options) {
97
92
util . inherits ( Speech , commonGrpc . Service ) ;
98
93
99
94
/**
100
- * The endpointer types that the Speech API will return while processing a
95
+ * The event types that the Speech API will return while processing a
101
96
* {module:speech#createRecognizeStream} request. You can track the progress of
102
- * audio recognition by comparing the `data.endpointerType ` property with these
97
+ * audio recognition by comparing the `data.eventType ` property with these
103
98
* values.
104
99
*
105
- * - `Speech.endpointerTypes.ENDPOINTER_EVENT_UNSPECIFIED`: No endpointer
106
- * event specified.
107
- * - `Speech.endpointerTypes.START_OF_SPEECH`: Speech has been detected in the
108
- * audio stream.
109
- * - `Speech.endpointerTypes.END_OF_SPEECH`: Speech has ceased to be detected
110
- * in the audio stream.
111
- * - `Speech.endpointerTypes.END_OF_AUDIO`: The end of the audio stream has
112
- * been reached and it is being processed.
113
- * - `Speech.endpointerTypes.END_OF_UTTERANCE`: This event is only sent when
100
+ * - `Speech.eventTypes.ENDPOINTER_EVENT_UNSPECIFIED`: No event specified.
101
+ * - `Speech.eventTypes.END_OF_SINGLE_UTTERANCE`: This event is only sent when
114
102
* `config.singleUtterance` passed to {module:speech#createRecognizeStream}
115
103
* is `true`. It indicates that the server has detected the end of the
116
104
* user's speech utterance and expects no additional speech. Therefore, the
@@ -119,13 +107,10 @@ util.inherits(Speech, commonGrpc.Service);
119
107
*
120
108
* @type {object }
121
109
*/
122
- Speech . endpointerTypes =
123
- Speech . prototype . endpointerTypes = {
124
- END_OF_AUDIO : 'END_OF_AUDIO' ,
125
- END_OF_SPEECH : 'END_OF_SPEECH' ,
126
- END_OF_UTTERANCE : 'END_OF_UTTERANCE' ,
127
- ENDPOINTER_EVENT_UNSPECIFIED : 'ENDPOINTER_EVENT_UNSPECIFIED' ,
128
- START_OF_SPEECH : 'START_OF_SPEECH'
110
+ Speech . eventTypes =
111
+ Speech . prototype . eventTypes = {
112
+ END_OF_SINGLE_UTTERANCE : 'END_OF_SINGLE_UTTERANCE' ,
113
+ ENDPOINTER_EVENT_UNSPECIFIED : 'ENDPOINTER_EVENT_UNSPECIFIED'
129
114
} ;
130
115
131
116
/**
@@ -371,7 +356,7 @@ Speech.formatResults_ = function(resultSets, verboseMode) {
371
356
* [`StreamingRecognizeResponse`](https://cloud.google.com/speech/reference/rpc/google.cloud.speech.v1beta1#streamingrecognizeresponse)
372
357
* object, containing these properties:
373
358
*
374
- * - **`endpointerType `** See {module:speech#endpointerTypes }.
359
+ * - **`eventType `** See {module:speech#eventTypes }.
375
360
* - **`results`** By default, a combined string of transcripts. When
376
361
* `config.verbose` is enabled, this is an object including a `transcript`
377
362
* property, a `confidence` score from `0` - `100`, and an `alternatives`
@@ -405,7 +390,7 @@ Speech.formatResults_ = function(resultSets, verboseMode) {
405
390
* var request = {
406
391
* config: {
407
392
* encoding: 'LINEAR16',
408
- * sampleRate : 16000
393
+ * sampleRateHertz : 16000
409
394
* },
410
395
* singleUtterance: false,
411
396
* interimResults: false
@@ -416,27 +401,7 @@ Speech.formatResults_ = function(resultSets, verboseMode) {
416
401
* .pipe(speech.createRecognizeStream(request))
417
402
* .on('error', console.error)
418
403
* .on('data', function(data) {
419
- * // The first "data" event emitted might look like:
420
- * // data = {
421
- * // endpointerType: Speech.endpointerTypes.START_OF_SPEECH,
422
- * // results: "",
423
- * // ...
424
- * // }
425
- *
426
- * // A later "data" event emitted might look like:
427
- * // data = {
428
- * // endpointerType: Speech.endpointerTypes.END_OF_AUDIO,
429
- * // results: "",
430
- * // ...
431
- * // }
432
- *
433
- * // A final "data" event emitted might look like:
434
- * // data = {
435
- * // endpointerType:
436
- * // Speech.endpointerTypes.ENDPOINTER_EVENT_UNSPECIFIED,
437
- * // results: "how old is the Brooklyn Bridge",
438
- * // ...
439
- * // }
404
+ * // data.results = "how old is the Brooklyn Bridge"
440
405
* });
441
406
*
442
407
* //-
@@ -445,7 +410,7 @@ Speech.formatResults_ = function(resultSets, verboseMode) {
445
410
* var request = {
446
411
* config: {
447
412
* encoding: 'LINEAR16',
448
- * sampleRate : 16000
413
+ * sampleRateHertz : 16000
449
414
* },
450
415
* singleUtterance: false,
451
416
* interimResults: false,
@@ -457,32 +422,7 @@ Speech.formatResults_ = function(resultSets, verboseMode) {
457
422
* .pipe(speech.createRecognizeStream(request))
458
423
* .on('error', console.error)
459
424
* .on('data', function(data) {
460
- * // The first "data" event emitted might look like:
461
- * // data = {
462
- * // endpointerType: Speech.endpointerTypes.START_OF_SPEECH,
463
- * // results: [],
464
- * // ...
465
- * // }
466
- *
467
- * // A later "data" event emitted might look like:
468
- * // data = {
469
- * // endpointerType: Speech.endpointerTypes.END_OF_AUDIO,
470
- * // results: [],
471
- * // ...
472
- * // }
473
- *
474
- * // A final "data" event emitted might look like:
475
- * // data = {
476
- * // endpointerType:
477
- * // Speech.endpointerTypes.ENDPOINTER_EVENT_UNSPECIFIED,
478
- * // results: [
479
- * // {
480
- * // transcript: "how old is the Brooklyn Bridge",
481
- * // confidence: 88.15
482
- * // }
483
- * // ],
484
- * // ...
485
- * // }
425
+ * // data.results = "how old is the Brooklyn Bridge"
486
426
* });
487
427
*/
488
428
Speech . prototype . createRecognizeStream = function ( config ) {
@@ -492,6 +432,12 @@ Speech.prototype.createRecognizeStream = function(config) {
492
432
throw new Error ( 'A recognize request requires a configuration object.' ) ;
493
433
}
494
434
435
+ config = extend ( true , {
436
+ config : {
437
+ languageCode : 'en-US'
438
+ }
439
+ } , config ) ;
440
+
495
441
var verboseMode = config . verbose === true ;
496
442
delete config . verbose ;
497
443
@@ -507,6 +453,10 @@ Speech.prototype.createRecognizeStream = function(config) {
507
453
recognizeStream . once ( 'writing' , function ( ) {
508
454
var requestStream = self . api . Speech . streamingRecognize ( gaxOptions ) ;
509
455
456
+ requestStream . on ( 'error' , function ( err ) {
457
+ recognizeStream . destroy ( err ) ;
458
+ } ) ;
459
+
510
460
requestStream . on ( 'response' , function ( response ) {
511
461
recognizeStream . emit ( 'response' , response ) ;
512
462
} ) ;
@@ -564,8 +514,8 @@ Speech.prototype.operation = function(name) {
564
514
* larger files, you will need to use {module:speech#startRecognition} or
565
515
* {module:speech#createRecognizeStream}.
566
516
*
567
- * @resource [SyncRecognize API Reference]{@link https://cloud.google.com/speech/reference/rpc/google.cloud.speech.v1beta1#google.cloud.speech.v1beta1.Speech.SyncRecognize }
568
- * @resource [SyncRecognizeRequest API Reference]{@link https://cloud.google.com/speech/reference/rpc/google.cloud.speech.v1beta1#google.cloud.speech.v1beta1.SyncRecognizeRequest }
517
+ * @resource [Recognize API Reference]{@link https://cloud.google.com/speech/reference/rpc/google.cloud.speech.v1beta1#google.cloud.speech.v1beta1.Speech.Recognize }
518
+ * @resource [RecognizeRequest API Reference]{@link https://cloud.google.com/speech/reference/rpc/google.cloud.speech.v1beta1#google.cloud.speech.v1beta1.RecognizeRequest }
569
519
*
570
520
* @param {string|object|module:storage/file } file - The source file to run the
571
521
* detection on. It can be either a local file path, a remote file URL, a
@@ -585,12 +535,12 @@ Speech.prototype.operation = function(name) {
585
535
* array consisting of other transcription possibilities. See the examples
586
536
* below for more.
587
537
* @param {object } callback.apiResponse - Raw API response. See
588
- * [`SyncRecognizeResponse `](https://cloud.google.com/speech/reference/rpc/google.cloud.speech.v1beta1#syncrecognizeresponse ).
538
+ * [`RecognizeResponse `](https://cloud.google.com/speech/reference/rpc/google.cloud.speech.v1beta1#recognizeresponse ).
589
539
*
590
540
* @example
591
541
* var config = {
592
542
* encoding: 'LINEAR16',
593
- * sampleRate : 16000
543
+ * sampleRateHertz : 16000
594
544
* };
595
545
*
596
546
* function callback(err, transcript, apiResponse) {
@@ -632,7 +582,7 @@ Speech.prototype.operation = function(name) {
632
582
* //-
633
583
* var config = {
634
584
* encoding: 'LINEAR16',
635
- * sampleRate : 16000,
585
+ * sampleRateHertz : 16000,
636
586
* verbose: true
637
587
* };
638
588
*
@@ -670,7 +620,9 @@ Speech.prototype.recognize = function(file, config, callback) {
670
620
throw new Error ( 'A recognize request requires a configuration object.' ) ;
671
621
}
672
622
673
- config = extend ( { } , config ) ;
623
+ config = extend ( {
624
+ languageCode : 'en-US'
625
+ } , config ) ;
674
626
675
627
if ( ! config . encoding ) {
676
628
config . encoding = Speech . detectEncoding_ ( file ) ;
@@ -685,7 +637,7 @@ Speech.prototype.recognize = function(file, config, callback) {
685
637
return ;
686
638
}
687
639
688
- self . api . Speech . syncRecognize ( {
640
+ self . api . Speech . recognize ( {
689
641
config : config ,
690
642
audio : foundFile
691
643
} , function ( err , resp ) {
@@ -694,8 +646,7 @@ Speech.prototype.recognize = function(file, config, callback) {
694
646
return ;
695
647
}
696
648
697
- var response = new self . protos . Speech . SyncRecognizeResponse ( resp ) ;
698
- var results = Speech . formatResults_ ( response . results , verboseMode ) ;
649
+ var results = Speech . formatResults_ ( resp . results , verboseMode ) ;
699
650
700
651
callback ( null , results , resp ) ;
701
652
} ) ;
@@ -710,9 +661,9 @@ Speech.prototype.recognize = function(file, config, callback) {
710
661
* events to see how the operation finishes. Follow along with the examples
711
662
* below.
712
663
*
713
- * @resource [AsyncRecognize API Reference]{@link https://cloud.google.com/speech/reference/rpc/google.cloud.speech.v1beta1#google.cloud.speech.v1beta1 .Speech.AsyncRecognize }
714
- * @resource [AsyncRecognizeRequest API Reference]{@link https://cloud.google.com/speech/reference/rpc/google.cloud.speech.v1beta1#google.cloud.speech.v1beta1.AsyncRecognizeRequest }
715
- * @resource [AsyncRecognizeResponse API Reference]{@link https://cloud.google.com/speech/reference/rpc/google.cloud.speech.v1beta1#google.cloud.speech.v1beta1.AsyncRecognizeResponse }
664
+ * @resource [LongRunningRecognize API Reference]{@link https://cloud.google.com/speech/reference/rpc/google.cloud.speech.v1beta1#google.cloud.speech.v1 .Speech.LongRunningRecognize }
665
+ * @resource [LongRunningRecognize API Reference]{@link https://cloud.google.com/speech/reference/rpc/google.cloud.speech.v1beta1#google.cloud.speech.v1.LongRunningRecognizeRequest }
666
+ * @resource [LongRunningRecognize API Reference]{@link https://cloud.google.com/speech/reference/rpc/google.cloud.speech.v1beta1#google.cloud.speech.v1.LongRunningRecognizeResponse }
716
667
*
717
668
* @param {string|object|module:storage/file } file - The source file to run the
718
669
* detection on. It can be either a local file path, a remote file URL, a
@@ -732,7 +683,7 @@ Speech.prototype.recognize = function(file, config, callback) {
732
683
* @example
733
684
* var config = {
734
685
* encoding: 'LINEAR16',
735
- * sampleRate : 16000
686
+ * sampleRateHertz : 16000
736
687
* };
737
688
*
738
689
* function callback(err, operation, apiResponse) {
@@ -781,7 +732,7 @@ Speech.prototype.recognize = function(file, config, callback) {
781
732
* //-
782
733
* var config = {
783
734
* encoding: 'LINEAR16',
784
- * sampleRate : 16000,
735
+ * sampleRateHertz : 16000,
785
736
* verbose: true
786
737
* };
787
738
*
@@ -813,7 +764,9 @@ Speech.prototype.recognize = function(file, config, callback) {
813
764
Speech . prototype . startRecognition = function ( file , config , callback ) {
814
765
var self = this ;
815
766
816
- config = extend ( { } , config ) ;
767
+ config = extend ( {
768
+ languageCode : 'en-US'
769
+ } , config ) ;
817
770
818
771
if ( ! config . encoding ) {
819
772
config . encoding = Speech . detectEncoding_ ( file ) ;
@@ -828,7 +781,7 @@ Speech.prototype.startRecognition = function(file, config, callback) {
828
781
return ;
829
782
}
830
783
831
- self . api . Speech . asyncRecognize ( {
784
+ self . api . Speech . longRunningRecognize ( {
832
785
config : config ,
833
786
audio : foundFile
834
787
} , function ( err , operation , resp ) {
@@ -857,4 +810,4 @@ common.util.promisifyAll(Speech, {
857
810
} ) ;
858
811
859
812
module . exports = Speech ;
860
- module . exports . v1beta1 = v1beta1 ;
813
+ module . exports . v1 = v1 ;
0 commit comments