import * as assert from 'assert' ; import { describe , it } from 'mocha' ; import * as speech from '../src' ; import * as fs from 'fs' ; import * as path from 'path' ; import { google } from '../protos/protos' ; describe ( 'SpeechClient TypeScript system test v1' , ( ) => { it ( 'calls recognize' , async ( ) => { const client = new speech . v1 . SpeechClient ( ) ; const languageCode = 'en-US' ; const sampleRateHertz = 44100 ; const encoding = google . cloud . speech . v1 . RecognitionConfig . AudioEncoding . FLAC ; const audioChannelCount = 2 ; const config = { languageCode , sampleRateHertz , encoding , audioChannelCount , } ; const uri = 'gs://cloud-samples-data/speech/hello.flac' ; const audio = { uri , } ; const request = { config , audio , } ; const [ response ] = await client . recognize ( request ) ; assert . strictEqual ( response . results ! [ 0 ] ! . alternatives ! [ 0 ] . transcript , 'hello' ) ; } ) ; it ( 'calls longRunningRecognize' , async ( ) => { const client = new speech . v1 . SpeechClient ( ) ; const languageCode = 'en-US' ; const sampleRateHertz = 44100 ; const encoding = google . cloud . speech . v1 . RecognitionConfig . AudioEncoding . FLAC ; const audioChannelCount = 2 ; const config = { languageCode , sampleRateHertz , encoding , audioChannelCount , } ; const uri = 'gs://cloud-samples-data/speech/hello.flac' ; const audio = { uri , } ; const request = { config , audio , } ; const [ operation ] = await client . longRunningRecognize ( request ) ; const [ response ] = await operation . promise ( ) ; assert . strictEqual ( response . results ! [ 0 ] . alternatives ! [ 0 ] . transcript , 'hello' ) ; } ) ; it ( 'calls streamingRecognize' , done => { const filename = path . join ( 'system-test' , 'fixtures' , 'streamingRecognize' , 'input.wav' ) ; const languageCode = 'en-US' ; const sampleRateHertz = 24000 ; const encoding = google . cloud . speech . v1 . RecognitionConfig . AudioEncoding . LINEAR16 ; const config = { languageCode , sampleRateHertz , encoding , } ; const request = { config , interimResults : false , } ; const client = new speech . v1 . SpeechClient ( ) ; const stream = client . streamingRecognize ( request ) ; let gotResponse = false ; stream . on ( 'data' , ( response ) => { assert . strictEqual ( response . results ! [ 0 ] . alternatives ! [ 0 ] . transcript , 'test of streaming recognize call' ) ; gotResponse = true ; } ) ; stream . on ( 'end' , ( ) => { assert ( gotResponse ) ; done ( ) ; } ) ; stream . on ( 'error' , done ) ; fs . createReadStream ( filename ) . pipe ( stream ) ; } ) ; } ) ;