From 357553f1eaf1da04556c287c9428c685dac0a0d2 Mon Sep 17 00:00:00 2001 From: Logan Date: Sun, 12 Apr 2026 22:04:11 -0400 Subject: [PATCH] =?UTF-8?q?Issue=09Fix=20Upload=20404=20warning=09doc=5Fse?= =?UTF-8?q?t(merge=3DTrue)=20in=20upload.py=20=E2=80=94=20creates=20doc=20?= =?UTF-8?q?if=20missing=20MQTT=20call=5Fend=20404=20error=09doc=5Fset(merg?= =?UTF-8?q?e=3DTrue)=20in=20mqtt=5Fhandler.py=20=E2=80=94=20same=20root=20?= =?UTF-8?q?cause=20Transcription=20404=20(saving=20transcript=20to=20nonex?= =?UTF-8?q?istent=20doc)=09doc=5Fset(merge=3DTrue)=20in=20transcription.py?= =?UTF-8?q?=20Transcription=20ADC=20credentials=20error=09Explicit=20servi?= =?UTF-8?q?ce=5Faccount.Credentials=20from=20gcp-key.json=20in=20=5Fsync?= =?UTF-8?q?=5Ftranscribe=20=E2=80=94=20same=20pattern=20as=20storage.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- drb-c2-core/app/internal/mqtt_handler.py | 2 +- drb-c2-core/app/internal/transcription.py | 13 +++++++++++-- drb-c2-core/app/routers/upload.py | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/drb-c2-core/app/internal/mqtt_handler.py b/drb-c2-core/app/internal/mqtt_handler.py index 229df34..601ee55 100644 --- a/drb-c2-core/app/internal/mqtt_handler.py +++ b/drb-c2-core/app/internal/mqtt_handler.py @@ -193,7 +193,7 @@ class MQTTHandler: if payload.get("audio_url"): updates["audio_url"] = payload["audio_url"] - await fstore.doc_update("calls", call_id, updates) + await fstore.doc_set("calls", call_id, updates) logger.info(f"Call end: {call_id}") # ------------------------------------------------------------------ diff --git a/drb-c2-core/app/internal/transcription.py b/drb-c2-core/app/internal/transcription.py index 7a898a5..c05600c 100644 --- a/drb-c2-core/app/internal/transcription.py +++ b/drb-c2-core/app/internal/transcription.py @@ -35,7 +35,7 @@ async def transcribe_call(call_id: str, gcs_uri: str) -> Optional[str]: if transcript: try: - await fstore.doc_update("calls", call_id, {"transcript": transcript}) + await fstore.doc_set("calls", call_id, {"transcript": transcript}) logger.info(f"Transcript saved for call {call_id} ({len(transcript)} chars)") except Exception as e: logger.warning(f"Could not save transcript for {call_id}: {e}") @@ -46,8 +46,17 @@ async def transcribe_call(call_id: str, gcs_uri: str) -> Optional[str]: def _sync_transcribe(gcs_uri: str) -> Optional[str]: """Synchronous STT call — run in a thread via asyncio.to_thread.""" from google.cloud import speech + from app.config import settings - client = speech.SpeechClient() + if settings.gcp_credentials_path: + from google.oauth2 import service_account + creds = service_account.Credentials.from_service_account_file( + settings.gcp_credentials_path, + scopes=["https://www.googleapis.com/auth/cloud-platform"], + ) + client = speech.SpeechClient(credentials=creds) + else: + client = speech.SpeechClient() audio = speech.RecognitionAudio(uri=gcs_uri) config = speech.RecognitionConfig( diff --git a/drb-c2-core/app/routers/upload.py b/drb-c2-core/app/routers/upload.py index 7f3905b..008912e 100644 --- a/drb-c2-core/app/routers/upload.py +++ b/drb-c2-core/app/routers/upload.py @@ -49,7 +49,7 @@ async def upload_call_audio( if audio_url: try: - await fstore.doc_update("calls", call_id, {"audio_url": audio_url}) + await fstore.doc_set("calls", call_id, {"audio_url": audio_url}) except Exception as e: logger.warning(f"Could not update call {call_id} with audio_url: {e}")