diff --git a/librarian.yaml b/librarian.yaml index 7c3cb742eb0e..38b52713337e 100644 --- a/librarian.yaml +++ b/librarian.yaml @@ -1423,7 +1423,6 @@ libraries: - path: google/cloud/speech/v1 - path: google/cloud/speech/v1p1beta1 copyright_year: "2026" - skip_generate: true nodejs: default_version: v1 dependencies: diff --git a/packages/google-cloud-speech/.OwlBot.yaml b/packages/google-cloud-speech/.OwlBot.yaml deleted file mode 100644 index 935e8e8659e4..000000000000 --- a/packages/google-cloud-speech/.OwlBot.yaml +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2021 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -deep-remove-regex: - - /owl-bot-staging - -deep-copy-regex: - - source: /google/cloud/speech/google-cloud-speech-nodejs - dest: /owl-bot-staging/google-cloud-speech - -begin-after-commit-hash: f43939eac6a0bb5998c1fa0f79063194e699230e diff --git a/packages/google-cloud-speech/.repo-metadata.json b/packages/google-cloud-speech/.repo-metadata.json index 0f074bc04db8..8f3fffe654de 100644 --- a/packages/google-cloud-speech/.repo-metadata.json +++ b/packages/google-cloud-speech/.repo-metadata.json @@ -1,17 +1,16 @@ { - "name": "speech", - "name_pretty": "Cloud Speech", - "product_documentation": "https://cloud.google.com/speech-to-text/docs/", - "client_documentation": "https://googleapis.dev/nodejs/speech/latest", - "issue_tracker": "https://issuetracker.google.com/savedsearches/559758", - "release_level": "stable", - "language": "nodejs", - "repo": "googleapis/google-cloud-node", - "distribution_name": "@google-cloud/speech", - "api_id": "speech.googleapis.com", - "requires_billing": false, - "codeowner_team": "@googleapis/ml-apis", - "default_version": "v1", - "api_shortname": "speech", - "library_type": "GAPIC_COMBO" -} + "api_description": "Converts audio to text by applying powerful neural network models.", + "api_id": "speech.googleapis.com", + "api_shortname": "speech", + "client_documentation": "https://cloud.google.com/nodejs/docs/reference/speech/latest", + "default_version": "v1", + "distribution_name": "@google-cloud/speech", + "issue_tracker": "https://issuetracker.google.com/savedsearches/559758", + "language": "nodejs", + "library_type": "GAPIC_AUTO", + "name": "speech", + "name_pretty": "Cloud Speech-to-Text", + "product_documentation": "https://cloud.google.com/speech-to-text/docs", + "release_level": "stable", + "repo": "googleapis/google-cloud-node" +} \ No newline at end of file diff --git a/packages/google-cloud-speech/prettier.config.js b/packages/google-cloud-speech/prettier.config.js deleted file mode 100644 index a425d3f76180..000000000000 --- a/packages/google-cloud-speech/prettier.config.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - singleQuote: true, - trailingComma: 'es5', -}; diff --git a/packages/google-cloud-speech/src/helpers.ts b/packages/google-cloud-speech/src/helpers.ts deleted file mode 100644 index 0b24f145143b..000000000000 --- a/packages/google-cloud-speech/src/helpers.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -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 { - /** - * Performs bidirectional streaming speech recognition: receive results while - * sending audio. This method is only available via the gRPC API (not REST). - * - * @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]{@link 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]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} - * 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]{@link StreamingRecognizeResponse} - * on the 'data' event asynchronously. - * - * @example - * const speech = require('@google-cloud/speech'); - * const client = new speech.SpeechClient(); - * - * const stream = client.streamingRecognize({ - * config: { - * encoding: 'LINEAR16', - * languageCode: 'en-us', - * sampleRateHertz: 44100, - * }, - * }).on('data', function(response) { - * // doThingsWith(response); - * }); - * const request = {}; - * // Write request objects. - * stream.write(request); - */ - streamingRecognize( - streamingConfig?: - | protosTypes.google.cloud.speech.v2.IStreamingRecognitionConfig - | protosTypes.google.cloud.speech.v1.IStreamingRecognitionConfig - | protosTypes.google.cloud.speech.v1p1beta1.IStreamingRecognitionConfig, - options?: gax.CallOptions - ) { - options = options || {}; - streamingConfig = streamingConfig || {}; - - // Format the audio content as input request for pipeline - const recognizeStream = streamEvents(new pumpify.obj()); - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const requestStream = (this as any) - ._streamingRecognize(options) - .on('error', (err: Error) => { - recognizeStream.destroy(err); - }) - .on( - 'response', - ( - response: - | protosTypes.google.cloud.speech.v2.StreamingRecognizeResponse - | protosTypes.google.cloud.speech.v1.StreamingRecognizeResponse - | protosTypes.google.cloud.speech.v1p1beta1.StreamingRecognizeResponse - ) => { - recognizeStream.emit('response', response); - } - ); - - // Attach the events to the request stream, but only do so - // when the first write (of data) comes in. - // - // This also means that the sending of the initial request (with the - // config) is delayed until we get the first burst of data. - recognizeStream.once('writing', () => { - // The first message should contain the streaming config. - requestStream.write({streamingConfig}); - - // Set up appropriate piping between the stream returned by - // the underlying API method and the one that we return. - recognizeStream.setPipeline([ - // Format the user's input. - // This entails that the user sends raw audio; it is wrapped in - // the appropriate request structure. - 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; - } -} diff --git a/packages/google-cloud-speech/src/index.ts b/packages/google-cloud-speech/src/index.ts index 09b80275dcb1..c6c71034eeae 100644 --- a/packages/google-cloud-speech/src/index.ts +++ b/packages/google-cloud-speech/src/index.ts @@ -11,46 +11,21 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +// +// ** This file is automatically generated by synthtool. ** +// ** https://github.com/googleapis/synthtool ** +// ** All changes to this file may be overwritten. ** -import {ImprovedStreamingClient} from './helpers'; -import * as v1p1beta1 from './v1p1beta1'; import * as v1 from './v1'; +import * as v1p1beta1 from './v1p1beta1'; import * as v2 from './v2'; -// The following code is adapted from http://www.typescriptlang.org/docs/handbook/mixins.html -// tslint:disable-next-line no-any -Object.defineProperty( - v1.SpeechClient.prototype, - 'streamingRecognize', - Object.getOwnPropertyDescriptor( - ImprovedStreamingClient.prototype, - 'streamingRecognize' - )! -); -Object.defineProperty( - v1p1beta1.SpeechClient.prototype, - 'streamingRecognize', - Object.getOwnPropertyDescriptor( - ImprovedStreamingClient.prototype, - 'streamingRecognize' - )! -); -Object.defineProperty( - v2.SpeechClient.prototype, - 'streamingRecognize', - Object.getOwnPropertyDescriptor( - ImprovedStreamingClient.prototype, - 'streamingRecognize' - )! -); - -const SpeechClient = v1.SpeechClient; -type SpeechClient = v1.SpeechClient; const AdaptationClient = v1.AdaptationClient; type AdaptationClient = v1.AdaptationClient; -export {v1, v1p1beta1, v2, SpeechClient, AdaptationClient}; -// For compatibility with JavaScript libraries we need to provide this default export: -// tslint:disable-next-line no-default-export -export default {v1, v1p1beta1, v2, SpeechClient, AdaptationClient}; +const SpeechClient = v1.SpeechClient; +type SpeechClient = v1.SpeechClient; + +export {v1, v1p1beta1, v2, AdaptationClient, SpeechClient}; +export default {v1, v1p1beta1, v2, AdaptationClient, SpeechClient}; import * as protos from '../protos/protos'; export {protos}; diff --git a/packages/google-cloud-speech/system-test/fixtures/streamingRecognize/input.wav b/packages/google-cloud-speech/system-test/fixtures/streamingRecognize/input.wav deleted file mode 100644 index 27a14fa7e3c5..000000000000 Binary files a/packages/google-cloud-speech/system-test/fixtures/streamingRecognize/input.wav and /dev/null differ diff --git a/packages/google-cloud-speech/system-test/speech_system_test.js b/packages/google-cloud-speech/system-test/speech_system_test.js deleted file mode 100644 index 292de0cbd2ea..000000000000 --- a/packages/google-cloud-speech/system-test/speech_system_test.js +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const assert = require('assert'); -const {describe, it} = require('mocha'); -const path = require('path'); -const speech = require(path.join(process.cwd(), 'build', 'src')); -const fs = require('fs'); - -describe('SpeechClient system test default', () => { - it('calls recognize', async () => { - const client = new speech.SpeechClient(); - - const languageCode = 'en-US'; - const sampleRateHertz = 44100; - const encoding = 'FLAC'; - const config = { - languageCode: languageCode, - sampleRateHertz: sampleRateHertz, - encoding: encoding, - audioChannelCount: 2, - }; - const uri = 'gs://cloud-samples-data/speech/hello.flac'; - const audio = { - uri: uri, - }; - const request = { - config: config, - audio: audio, - }; - const [response] = await client.recognize(request); - assert.strictEqual(response.results[0].alternatives[0].transcript, 'hello'); - }); - - it('calls longRunningRecognize', async () => { - const client = new speech.SpeechClient(); - - const languageCode = 'en-US'; - const sampleRateHertz = 44100; - const encoding = 'FLAC'; - const config = { - languageCode: languageCode, - sampleRateHertz: sampleRateHertz, - encoding: encoding, - audioChannelCount: 2, - }; - const uri = 'gs://cloud-samples-data/speech/hello.flac'; - const audio = { - uri: uri, - }; - const request = { - config: config, - audio: 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 = 'LINEAR16'; - const config = { - languageCode: languageCode, - sampleRateHertz: sampleRateHertz, - encoding: encoding, - }; - const request = { - config, - interimResults: false, - }; - - const client = new speech.SpeechClient(); - const stream = client.streamingRecognize(request); - let gotResponse = false; - stream.on('data', response => { - assert.match( - response.results[0].alternatives[0].transcript, - /test of streaming.*call/ - ); - gotResponse = true; - }); - stream.on('end', () => { - assert(gotResponse); - done(); - }); - stream.on('error', done); - fs.createReadStream(filename).pipe(stream); - }); -}); diff --git a/packages/google-cloud-speech/system-test/speech_system_test_v1.js b/packages/google-cloud-speech/system-test/speech_system_test_v1.js deleted file mode 100644 index 78728558fc7c..000000000000 --- a/packages/google-cloud-speech/system-test/speech_system_test_v1.js +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const assert = require('assert'); -const {describe, it} = require('mocha'); -const path = require('path'); -const speech = require(path.join(process.cwd(), 'build', 'src')); -const fs = require('fs'); - -describe('SpeechClient system test v1', () => { - it('calls recognize', async () => { - const client = new speech.v1.SpeechClient(); - - const languageCode = 'en-US'; - const sampleRateHertz = 44100; - const encoding = 'FLAC'; - const config = { - languageCode: languageCode, - sampleRateHertz: sampleRateHertz, - encoding: encoding, - audioChannelCount: 2, - }; - const uri = 'gs://cloud-samples-data/speech/hello.flac'; - const audio = { - uri: uri, - }; - const request = { - config: config, - audio: 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 = 'FLAC'; - const config = { - languageCode: languageCode, - sampleRateHertz: sampleRateHertz, - encoding: encoding, - audioChannelCount: 2, - }; - const uri = 'gs://cloud-samples-data/speech/hello.flac'; - const audio = { - uri: uri, - }; - const request = { - config: config, - audio: 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 = 'LINEAR16'; - const config = { - languageCode: languageCode, - sampleRateHertz: sampleRateHertz, - encoding: 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.match( - response.results[0].alternatives[0].transcript, - /test of streaming.*call/ - ); - gotResponse = true; - }); - stream.on('end', () => { - assert(gotResponse); - done(); - }); - stream.on('error', done); - fs.createReadStream(filename).pipe(stream); - }); -}); diff --git a/packages/google-cloud-speech/system-test/speech_system_test_v1p1beta1.js b/packages/google-cloud-speech/system-test/speech_system_test_v1p1beta1.js deleted file mode 100644 index 19ca671458f3..000000000000 --- a/packages/google-cloud-speech/system-test/speech_system_test_v1p1beta1.js +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const assert = require('assert'); -const {describe, it} = require('mocha'); -const path = require('path'); -const speech = require(path.join(process.cwd(), 'build', 'src')); -const fs = require('fs'); - -describe('SpeechClient system test v1p1beta1', () => { - it('calls recognize', async () => { - const client = new speech.v1p1beta1.SpeechClient(); - - const languageCode = 'en-US'; - const sampleRateHertz = 44100; - const encoding = 'FLAC'; - const config = { - languageCode: languageCode, - sampleRateHertz: sampleRateHertz, - encoding: encoding, - audioChannelCount: 2, - }; - const uri = 'gs://cloud-samples-data/speech/hello.flac'; - const audio = { - uri: uri, - }; - const request = { - config: config, - audio: audio, - }; - const [response] = await client.recognize(request); - assert.strictEqual(response.results[0].alternatives[0].transcript, 'hello'); - }); - - it('calls longRunningRecognize', async () => { - const client = new speech.v1p1beta1.SpeechClient(); - - const languageCode = 'en-US'; - const sampleRateHertz = 44100; - const encoding = 'FLAC'; - const config = { - languageCode: languageCode, - sampleRateHertz: sampleRateHertz, - encoding: encoding, - audioChannelCount: 2, - }; - const uri = 'gs://cloud-samples-data/speech/hello.flac'; - const audio = { - uri: uri, - }; - const request = { - config: config, - audio: 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 = 'LINEAR16'; - const config = { - languageCode: languageCode, - sampleRateHertz: sampleRateHertz, - encoding: encoding, - }; - const request = { - config, - interimResults: false, - }; - - const client = new speech.v1p1beta1.SpeechClient(); - const stream = client.streamingRecognize(request); - let gotResponse = false; - stream.on('data', response => { - assert.match( - response.results[0].alternatives[0].transcript, - /test of streaming.*call/ - ); - gotResponse = true; - }); - stream.on('end', () => { - assert(gotResponse); - done(); - }); - stream.on('error', done); - fs.createReadStream(filename).pipe(stream); - }); -}); diff --git a/packages/google-cloud-speech/system-test/speech_typescript_system_test.ts b/packages/google-cloud-speech/system-test/speech_typescript_system_test.ts deleted file mode 100644 index e8a265f9c41d..000000000000 --- a/packages/google-cloud-speech/system-test/speech_typescript_system_test.ts +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -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 default', () => { - it('calls recognize', async () => { - const client = new speech.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.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.SpeechClient(); - const stream = client.streamingRecognize(request); - let gotResponse = false; - stream.on( - 'data', - (response: google.cloud.speech.v1.IStreamingRecognizeResponse) => { - assert.match( - response.results![0].alternatives![0].transcript ?? '', - /test of streaming.*call/ - ); - gotResponse = true; - } - ); - stream.on('end', () => { - assert(gotResponse); - done(); - }); - stream.on('error', done); - fs.createReadStream(filename).pipe(stream); - }); -}); diff --git a/packages/google-cloud-speech/system-test/speech_typescript_system_test_v1.ts b/packages/google-cloud-speech/system-test/speech_typescript_system_test_v1.ts deleted file mode 100644 index d502f61cbd07..000000000000 --- a/packages/google-cloud-speech/system-test/speech_typescript_system_test_v1.ts +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -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: google.cloud.speech.v1.IStreamingRecognizeResponse) => { - assert.match( - response.results![0].alternatives![0].transcript ?? '', - /test of streaming.*call/ - ); - gotResponse = true; - } - ); - stream.on('end', () => { - assert(gotResponse); - done(); - }); - stream.on('error', done); - fs.createReadStream(filename).pipe(stream); - }); -}); diff --git a/packages/google-cloud-speech/system-test/speech_typescript_system_test_v1p1beta1.ts b/packages/google-cloud-speech/system-test/speech_typescript_system_test_v1p1beta1.ts deleted file mode 100644 index d710f571ae4a..000000000000 --- a/packages/google-cloud-speech/system-test/speech_typescript_system_test_v1p1beta1.ts +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -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 v1p1beta1', () => { - it('calls recognize', async () => { - const client = new speech.v1p1beta1.SpeechClient(); - - const languageCode = 'en-US'; - const sampleRateHertz = 44100; - const encoding = - google.cloud.speech.v1p1beta1.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.v1p1beta1.SpeechClient(); - - const languageCode = 'en-US'; - const sampleRateHertz = 44100; - const encoding = - google.cloud.speech.v1p1beta1.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.v1p1beta1.SpeechClient(); - const stream = client.streamingRecognize(request); - let gotResponse = false; - stream.on( - 'data', - (response: google.cloud.speech.v1p1beta1.IStreamingRecognizeResponse) => { - assert.match( - response.results![0].alternatives![0].transcript ?? '', - /test of streaming.*call/ - ); - gotResponse = true; - } - ); - stream.on('end', () => { - assert(gotResponse); - done(); - }); - stream.on('error', done); - fs.createReadStream(filename).pipe(stream); - }); -}); diff --git a/packages/google-cloud-speech/test/helpers.test.ts b/packages/google-cloud-speech/test/helpers.test.ts deleted file mode 100644 index 9cb690b272e2..000000000000 --- a/packages/google-cloud-speech/test/helpers.test.ts +++ /dev/null @@ -1,185 +0,0 @@ -/*! - * Copyright 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -import * as assert from 'assert'; -import {afterEach, describe, it} from 'mocha'; -import * as sinon from 'sinon'; -import * as stream from 'stream'; -import * as speech from '../src'; - -describe('Speech helper methods', () => { - const sandbox = sinon.createSandbox(); - - afterEach(() => { - sandbox.restore(); - }); - - describe('streamingRecognize', () => { - const CONFIG: speech.protos.google.cloud.speech.v1.IStreamingRecognitionConfig = - { - config: {encoding: 'LINEAR16', languageCode: 'en-us'}, - }; - const OPTIONS = {timeout: Infinity}; - - it('writes the config to the resulting stream', done => { - const client = new speech.v1.SpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - - // Stub the underlying _streamingRecognize method to just return - // a bogus stream. - const requestStream = new stream.PassThrough({objectMode: true}); - const sr = sandbox - .stub(client.innerApiCalls, 'streamingRecognize') - .returns(requestStream); - - // Call the new helper method and establish that the config was - // forwarded as expected. - const userStream = client.streamingRecognize(CONFIG, OPTIONS); - - // Establish that the underlying streamingRecognize was called with - // the options. - assert(sr.calledOnce); - assert(sr.calledWithExactly(null, OPTIONS)); - - requestStream._write = (data, enc, next) => { - assert.deepStrictEqual(data, { - streamingConfig: CONFIG, - }); - setImmediate(done); - next(null); - }; - - userStream.write(undefined); - }); - - it('does not require options', () => { - const client = new speech.v1.SpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - - // Stub the underlying _streamingRecognize method to just return - // a bogus stream. - const requestStream = new stream.PassThrough({objectMode: true}); - const sr = sandbox - .stub(client.innerApiCalls, 'streamingRecognize') - .returns(requestStream); - - const userStream = client.streamingRecognize(CONFIG); - - userStream.emit('writing'); - - assert(sr.calledOnce); - assert(sr.calledWithExactly(null, {})); - }); - - it('destroys the user stream when the request stream errors', done => { - const client = new speech.v1.SpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - - // Stub the underlying _streamingRecognize method to just return - // a bogus stream. - const requestStream = new stream.PassThrough({objectMode: true}); - sandbox - .stub(client.innerApiCalls, 'streamingRecognize') - .returns(requestStream); - - const userStream = client.streamingRecognize(CONFIG, OPTIONS); - - const error = new Error('Request stream error'); - - userStream.once('error', (err: Error) => { - assert.strictEqual(err, error); - done(); - }); - - requestStream.emit('error', error); - }); - - it('re-emits response from the request stream', done => { - const client = new speech.v1.SpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - - // Stub the underlying _streamingRecognize method to just return - // a bogus stream. - const requestStream = new stream.PassThrough({objectMode: true}); - sandbox - .stub(client.innerApiCalls, 'streamingRecognize') - .returns(requestStream); - - const userStream = client.streamingRecognize(CONFIG, OPTIONS); - - const response = {}; - - userStream.on('response', (_response: {}) => { - assert.strictEqual(_response, response); - done(); - }); - - userStream.emit('writing'); - requestStream.emit('response', response); - }); - - it('wraps incoming audio data', done => { - const client = new speech.v1.SpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - - // Stub the underlying _streamingRecognize method to just return - // a bogus stream. - const requestStream = new stream.PassThrough({objectMode: true}); - - sandbox - .stub(client.innerApiCalls, 'streamingRecognize') - .returns(requestStream); - - const userStream = client.streamingRecognize(CONFIG, OPTIONS); - const audioContent = Buffer.from('audio content'); - - let count = 0; - requestStream._write = (data, enc, next) => { - if (count === 0) { - assert.deepStrictEqual(data, { - streamingConfig: CONFIG, - }); - } else if (count === 1) { - assert.deepStrictEqual(data, { - audioContent, - }); - setImmediate(done); - } - count++; - next(null); - }; - - userStream.end(audioContent); - }); - }); -});