stt updates and intelligence updates
This commit is contained in:
@@ -11,17 +11,34 @@ from typing import Optional
|
||||
from app.internal.logger import logger
|
||||
from app.internal import firestore as fstore
|
||||
|
||||
# Whisper treats `prompt` as preceding transcript text, not instructions.
|
||||
# Writing it as actual radio speech primes the vocabulary toward P25 codes
|
||||
# and phrasing before the model hears the audio.
|
||||
_WHISPER_PROMPT = (
|
||||
"10-4. 10-23. 10-20. 10-97. 10-8. 10-7. 10-34. 10-50. 10-52. "
|
||||
"Post 4, I'm out. Post 3. En route. On scene. In route. "
|
||||
"Copy. Negative. Stand by. Be advised. Go ahead. "
|
||||
"Units responding. Dispatch. Talkgroup. "
|
||||
"Engine. Ladder. Medic. Rescue. Car. Unit. "
|
||||
"MVA. MVC. Structure fire. Working fire."
|
||||
)
|
||||
|
||||
async def transcribe_call(call_id: str, gcs_uri: str) -> Optional[str]:
|
||||
|
||||
async def transcribe_call(
|
||||
call_id: str,
|
||||
gcs_uri: str,
|
||||
talkgroup_name: Optional[str] = None,
|
||||
) -> Optional[str]:
|
||||
"""
|
||||
Transcribe audio at the given GCS URI and store the result in Firestore.
|
||||
|
||||
Args:
|
||||
call_id: Firestore document ID in the 'calls' collection.
|
||||
gcs_uri: GCS URI of the audio file, e.g. gs://bucket/calls/xyz.mp3
|
||||
call_id: Firestore document ID in the 'calls' collection.
|
||||
gcs_uri: GCS URI of the audio file, e.g. gs://bucket/calls/xyz.mp3
|
||||
talkgroup_name: Passed through to the intelligence layer; unused here.
|
||||
|
||||
Returns:
|
||||
The transcript string, or None if transcription failed / was skipped.
|
||||
The raw Whisper transcript string, or None if transcription failed.
|
||||
"""
|
||||
if not gcs_uri or not gcs_uri.startswith("gs://"):
|
||||
return None
|
||||
@@ -53,11 +70,9 @@ def _sync_transcribe(gcs_uri: str) -> Optional[str]:
|
||||
logger.warning("OPENAI_API_KEY not set — transcription disabled.")
|
||||
return None
|
||||
|
||||
# Parse gs://bucket/path/to/file.mp3
|
||||
without_scheme = gcs_uri[len("gs://"):]
|
||||
bucket_name, blob_path = without_scheme.split("/", 1)
|
||||
|
||||
# Download to a temp file
|
||||
if settings.gcp_credentials_path:
|
||||
creds = service_account.Credentials.from_service_account_file(
|
||||
settings.gcp_credentials_path,
|
||||
@@ -83,7 +98,7 @@ def _sync_transcribe(gcs_uri: str) -> Optional[str]:
|
||||
model="whisper-1",
|
||||
file=f,
|
||||
language="en",
|
||||
prompt="Public safety radio communication. May include police codes, fire, EMS, talkgroup IDs, unit numbers, addresses.",
|
||||
prompt=_WHISPER_PROMPT,
|
||||
)
|
||||
return response.text.strip() or None
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user