Skip to content

chore: migrate google-cloud-speech to librarian#8635

Closed
jskeet wants to merge 1 commit into
googleapis:mainfrom
jskeet:scripted-migrate-google-cloud-speech
Closed

chore: migrate google-cloud-speech to librarian#8635
jskeet wants to merge 1 commit into
googleapis:mainfrom
jskeet:scripted-migrate-google-cloud-speech

Conversation

@jskeet

@jskeet jskeet commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

This PR migrates the google-cloud-speech package to use Librarian for code generation.

Highlights

  • Enabled Librarian generation for google-cloud-speech by removing skip_generate: true in librarian.yaml.

  • Removed OwlBot configuration (.OwlBot.yaml).

  • Updated .repo-metadata.json (updated description, documentation links).

  • Removed obsolete test/source files:

    • packages/google-cloud-speech/src/helpers.ts: The custom streamingRecognize helper.
    • packages/google-cloud-speech/test/helpers.test.ts: Tests for the custom helper.
    • packages/google-cloud-speech/system-test/*: Legacy system tests.
    Why are these helper and test files obsolete? The custom streamingRecognize helper in helpers.ts was originally added to provide a better user experience for streaming (e.g., accepting raw audio and wrapping it). However, we are moving towards fully auto-generated clients to ensure consistency and reduce maintenance overhead. The associated tests (helpers.test.ts and legacy system tests) are removed as they target the deleted helper.

    Prior to this migration, OwlBot copied files from the Bazel-generated assembly package speech-v1-nodejs which included all dependencies. Librarian is more precise and only copies/keeps the protos defined for the API or transitively imported by them (resolved via *_proto_list.json generated during GAPIC generation), and filters out common protos that are already provided by google-gax. This is handled by copyMissingProtos in Librarian.

User-facing Changes (Questionable)

Warning

Breaking Change
The custom streamingRecognize helper has been removed. This helper was previously exposed to users by being mixed into the SpeechClient prototype. Users must now use the default generated streamingRecognize method.

Detail of breaking changes and migration path

What changed?

Previously, the custom helper was mixed into SpeechClient.prototype.streamingRecognize at runtime. It wrapped the raw gRPC stream to provide a more convenient API:

  1. It accepted streamingConfig as the first argument to streamingRecognize(config).
  2. The returned stream accepted raw audio buffers (via write() or pipe()) and automatically wrapped them into StreamingRecognizeRequest objects ({audioContent: buffer}).

With the removal of the helper, users now interact directly with the raw generated gRPC stream.

Migration Path

Before (with helper):

const stream = client.streamingRecognize(config).on('data', (response) => {
  // Handle response
});
// You could pipe a raw audio stream directly:
fs.createReadStream('audio.raw').pipe(stream);
// Or write buffers directly:
stream.write(audioBuffer);

After (without helper):
You must now write StreamingRecognizeRequest objects. The first write must contain the configuration, and subsequent writes must contain the audio content. You can no longer pipe raw audio streams directly without a transform.

const stream = client.streamingRecognize().on('data', (response) => {
  // Handle response
});

// 1. Write the config first
stream.write({streamingConfig: config});

// 2. Write audio content wrapped in an object
stream.write({audioContent: audioBuffer});

// If you want to pipe a file, you must transform it first:
const {Transform} = require('stream');
const chunker = new Transform({
  objectMode: true,
  transform(chunk, encoding, callback) {
    callback(null, {audioContent: chunk});
  }
});
// Write config first, then pipe the chunked audio
stream.write({streamingConfig: config});
fs.createReadStream('audio.raw').pipe(chunker).pipe(stream);

Fixes needed (for reviewers/author)

  • Delete packages/google-cloud-speech/librarian.js: This file is still present and is trying to post-process the generated files by importing ./helpers (which was deleted). This is causing compilation/test failures.
  • Regenerate code: After deleting librarian.js, the code should be regenerated to remove the appended helper imports from:
    • packages/google-cloud-speech/src/v1/speech_client.ts
    • packages/google-cloud-speech/src/v1p1beta1/speech_client.ts
    • packages/google-cloud-speech/src/v2/speech_client.ts

@jskeet jskeet requested a review from a team as a code owner June 12, 2026 17:52

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request transitions the library to a fully auto-generated client by removing the custom "streamingRecognize" helper, its associated tests, and updating the metadata and entry point. The reviewer notes that manual edits to generated TypeScript client files should be avoided, and any custom helpers should be restored upstream in the generator.

Comment on lines +15 to -45
// ** 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'
)!
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Do not manually edit generated TypeScript client files. Any changes or updates must be made upstream in the generator. If the custom streamingRecognize helper (previously in helpers.ts) needs to be restored, please ensure this is handled upstream in the generator rather than manually editing the files in this repository.

References
  1. Do not manually edit generated TypeScript client files. Any changes or updates must be made upstream in the generator.

@shivanee-p shivanee-p requested review from shivanee-p and removed request for shivanee-p June 12, 2026 21:56
@shivanee-p shivanee-p marked this pull request as draft June 12, 2026 21:57
@shivanee-p shivanee-p self-requested a review June 12, 2026 21:57
@shivanee-p shivanee-p marked this pull request as ready for review June 12, 2026 21:57
@shivanee-p

Copy link
Copy Markdown
Contributor

@pearigee and I were debugging the test failures, and we found that this code is being post-processed in by librarian.js.

Additionally, the imports in the index file need to be updated to account for the deleted files.

@suztomo

suztomo commented Jun 15, 2026

Copy link
Copy Markdown
Member

I enriched the pull request description. Let me see a way to avoid user-facing changes.

@suztomo suztomo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding "Request changes" while I investigate this.

@suztomo

suztomo commented Jun 15, 2026

Copy link
Copy Markdown
Member

With updated keep list: #8648

@suztomo suztomo closed this Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants