import * as common from '@google-cloud/common' ; import * as pumpify from 'pumpify' ; import * as streamEvents from 'stream-events' ; import { PassThrough } from 'stream' ; import * as protosTypes from '../protos/protos' ; import * as gax from 'google-gax' ; export class ImprovedStreamingClient { param { object } config The configuration for the stream. This is
     *     appropriately wrapped and sent as the first argument. It should be an
     *     object conforming to the [StreamingRecognitionConfig] StreamingRecognitionConfig *     structure.
     *  param { object } options Optional parameters. You can override the default
     *     settings for this call, e.g, timeout, retries, paginations, etc. See
     *     [gax.CallOptions] https *     for the details.
     *  returns { stream } An object stream which is both readable and writable. It
     *     accepts raw audio for the `write()` method, and will emit objects
     *     representing [StreamingRecognizeResponse] StreamingRecognizeResponse *     on the 'data' event asynchronously.
     *
     *  example streamingRecognize ( streamingConfig ? , options ? ) { options = options || { } ; streamingConfig = streamingConfig || { } ; const recognizeStream = streamEvents ( new pumpify . obj ( ) ) ; const requestStream = ( this as any ) . _streamingRecognize ( options ) . on ( 'error' , ( err ) => { recognizeStream . destroy ( err ) ; } ) . on ( 'response' , ( response ) => { recognizeStream . emit ( 'response' , response ) ; } ) ; recognizeStream . once ( 'writing' , ( ) => { requestStream . write ( { streamingConfig } ) ; recognizeStream . setPipeline ( [ new PassThrough ( { objectMode : true , transform : ( audioContent , _ , next ) => { if ( audioContent !== undefined ) { next ( undefined , { audioContent } ) ; return ; } next ( ) ; } , } ) , requestStream , new PassThrough ( { objectMode : true , transform : ( response , enc , next ) => { if ( response . error ) { next ( new common . util . ApiError ( response . error ) ) ; return ; } next ( undefined , response ) ; } , } ) , ] ) ; } ) ; return recognizeStream ; } }