Merge pull request #1525 from shaiyon/google-default-creds

Enable usage of Application Default Credentials in Google services
This commit is contained in:
Mark Backman
2025-04-18 11:31:08 -04:00
committed by GitHub
3 changed files with 34 additions and 1 deletions

View File

@@ -27,6 +27,8 @@ from pipecat.services.tts_service import TTSService
from pipecat.transcriptions.language import Language
try:
from google.auth import default
from google.auth.exceptions import GoogleAuthError
from google.cloud import texttospeech_v1
from google.oauth2 import service_account
@@ -251,6 +253,16 @@ class GoogleTTSService(TTSService):
elif credentials_path:
# Use service account JSON file if provided
creds = service_account.Credentials.from_service_account_file(credentials_path)
else:
try:
creds, project_id = default(
scopes=["https://www.googleapis.com/auth/cloud-platform"]
)
except GoogleAuthError:
pass
if not creds:
raise ValueError("No valid credentials provided.")
return texttospeech_v1.TextToSpeechAsyncClient(credentials=creds)