@@ -34,6 +34,7 @@ var request = require('request');
3434var streamEvents = require ( 'stream-events' ) ;
3535var through = require ( 'through2' ) ;
3636var util = require ( 'util' ) ;
37+ var v1beta1 = require ( './v1beta1' ) ;
3738
3839/**
3940 * The [Cloud Speech API](https://cloud.google.com/speech/docs) enables easy
@@ -87,6 +88,9 @@ function Speech(options) {
8788 } ;
8889
8990 common . GrpcService . call ( this , config , options ) ;
91+ this . api = {
92+ Speech : v1beta1 ( options ) . speechApi ( options )
93+ } ;
9094}
9195
9296util . inherits ( Speech , common . GrpcService ) ;
@@ -631,11 +635,6 @@ Speech.prototype.operation = function(name) {
631635Speech . prototype . recognize = function ( file , config , callback ) {
632636 var self = this ;
633637
634- var protoOpts = {
635- service : 'Speech' ,
636- method : 'syncRecognize'
637- } ;
638-
639638 config = extend ( { } , config ) ;
640639
641640 if ( ! config . encoding ) {
@@ -651,21 +650,16 @@ Speech.prototype.recognize = function(file, config, callback) {
651650 return ;
652651 }
653652
654- var reqOpts = {
655- audio : foundFile ,
656- config : config
657- } ;
658-
659- self . request ( protoOpts , reqOpts , function ( err , apiResponse ) {
653+ self . api . Speech . syncRecognize ( config , foundFile , function ( err , resp ) {
660654 if ( err ) {
661- callback ( err , null , apiResponse ) ;
655+ callback ( err , null , resp ) ;
662656 return ;
663657 }
664658
665- var response = new self . protos . Speech . SyncRecognizeResponse ( apiResponse ) ;
659+ var response = new self . protos . Speech . SyncRecognizeResponse ( resp ) ;
666660 var results = Speech . formatResults_ ( response . results , verboseMode ) ;
667661
668- callback ( null , results , apiResponse ) ;
662+ callback ( null , results , resp ) ;
669663 } ) ;
670664 } ) ;
671665} ;
@@ -773,11 +767,6 @@ Speech.prototype.recognize = function(file, config, callback) {
773767Speech . prototype . startRecognition = function ( file , config , callback ) {
774768 var self = this ;
775769
776- var protoOpts = {
777- service : 'Speech' ,
778- method : 'asyncRecognize'
779- } ;
780-
781770 config = extend ( { } , config ) ;
782771
783772 if ( ! config . encoding ) {
@@ -793,19 +782,14 @@ Speech.prototype.startRecognition = function(file, config, callback) {
793782 return ;
794783 }
795784
796- var reqOpts = {
797- audio : foundFile ,
798- config : config
799- } ;
800-
801- self . request ( protoOpts , reqOpts , function ( err , apiResponse ) {
785+ self . api . Speech . asyncRecognize ( config , foundFile , function ( err , resp ) {
802786 if ( err ) {
803- callback ( err , null , apiResponse ) ;
787+ callback ( err , null , resp ) ;
804788 return ;
805789 }
806790
807- var operation = self . operation ( apiResponse . name ) ;
808- operation . metadata = apiResponse ;
791+ var operation = self . operation ( resp . name ) ;
792+ operation . metadata = resp ;
809793
810794 // Intercept the "complete" event to decode and format the results of the
811795 // operation for the user.
@@ -821,10 +805,10 @@ Speech.prototype.startRecognition = function(file, config, callback) {
821805 callback ( null , Speech . formatResults_ ( response . results , verboseMode ) ) ;
822806 } ) ;
823807
824- callback ( null , operation , apiResponse ) ;
808+ callback ( null , operation , resp ) ;
825809 } ) ;
826810 } ) ;
827811} ;
828812
829813module . exports = Speech ;
830- module . exports . v1beta1 = require ( './ v1beta1' ) ;
814+ module . exports . v1beta1 = v1beta1 ;
0 commit comments