Big updates

This commit is contained in:
Logan
2026-04-21 01:51:23 -04:00
parent 788afca339
commit 6612e4b683
13 changed files with 168 additions and 49 deletions
+5 -3
View File
@@ -40,7 +40,7 @@ async def transcribe_call(
return None, []
try:
transcript, segments = await asyncio.to_thread(_sync_transcribe, gcs_uri)
transcript, segments = await asyncio.to_thread(_sync_transcribe, gcs_uri, talkgroup_name)
except Exception as e:
logger.warning(f"Transcription failed for call {call_id}: {e}")
return None, []
@@ -61,7 +61,7 @@ async def transcribe_call(
return transcript, segments
def _sync_transcribe(gcs_uri: str) -> tuple[Optional[str], list[dict]]:
def _sync_transcribe(gcs_uri: str, talkgroup_name: Optional[str] = None) -> tuple[Optional[str], list[dict]]:
"""Download audio from GCS and transcribe with OpenAI Whisper."""
from google.cloud import storage as gcs
from google.oauth2 import service_account
@@ -94,13 +94,15 @@ def _sync_transcribe(gcs_uri: str) -> tuple[Optional[str], list[dict]]:
try:
blob.download_to_filename(tmp_path)
prompt = (f"Talkgroup: {talkgroup_name}. " + _WHISPER_PROMPT) if talkgroup_name else _WHISPER_PROMPT
openai_client = OpenAI(api_key=settings.openai_api_key)
with open(tmp_path, "rb") as f:
response = openai_client.audio.transcriptions.create(
model="whisper-1",
file=f,
language="en",
prompt=_WHISPER_PROMPT,
prompt=prompt,
response_format="verbose_json",
)
text = response.text.strip() or None