feat(google): accept a credentials object on STT and TTS - #6618
Open
biztex wants to merge 2 commits into
Open
Conversation
google.STT and google.TTS only supported authentication via credentials_info (a service-account dict), credentials_file (a path on disk), or Application Default Credentials. Setups using Workload Identity Federation with custom credential providers obtain google.auth.credentials.Credentials objects in memory that never exist as files, and had no way to pass them. Add an optional credentials parameter to both classes and pass it through to the underlying SpeechAsyncClient / TextToSpeechAsyncClient, taking precedence over credentials_info and credentials_file. Mirrors the credentials parameter already accepted by RealtimeModel, LLM, and the aiplatform LLM in this plugin. STT also skips the ADC availability check when a credentials object is given. Fixes livekit#6586
With an in-memory credentials object the ADC startup check is skipped, but _get_recognizer still derived the project id from ambient credentials - so a WIF setup without ADC connected fine and then failed at transcription time with a confusing default-credentials-not-found error. Resolve the project from the credentials object itself (project_id or quota_project_id) when one is supplied, and when the project remains unresolvable raise a clear error saying exactly that instead of leaking the ADC failure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6586
Problem
google.STTandgoogle.TTSonly authenticate viacredentials_info(a service-account dict),credentials_file(a path on disk), or Application Default Credentials. Workload Identity Federation setups with custom credential providers hold agoogle.auth.credentials.Credentialsobject in memory that never exists as a file — and had no way to pass it, despite both classes already constructing their clients withcredentials=<object>internally (they just insisted on deriving that object from a file first).Change
Adds an optional
credentialsparameter to bothgoogle.STTandgoogle.TTS, passed straight through toSpeechAsyncClient/TextToSpeechAsyncClient. It takes precedence overcredentials_info/credentials_file, and STT skips its ADC-availability check when the object is supplied. Signature and type match thecredentialsparameter already accepted byRealtimeModel,LLM, and the aiplatform LLM in this same plugin — this just completes the parity, exactly as requested in the issue. Default isNone, so existing callers are unaffected.Tests
New hermetic
tests/test_google_credentials.py(unit-marked; usesAnonymousCredentials, no network/files/env): constructing STT without ADC now works with a credentials object, both clients receive the exact supplied object, and the object wins over a (nonexistent)credentials_file.