mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-02 19:55:18 +02:00
fix: add defensive dictionary access and error handling for local STT
- Use .get() for safe dictionary access instead of direct key access - Add explicit try-catch for local STT transcription failures - Validate transcription result is not empty - Provide clear error messages for corrupted audio files - Match error handling pattern with external STT service
This commit is contained in:
parent
504399ad01
commit
15ba2b86f6
1 changed files with 14 additions and 5 deletions
|
|
@ -792,17 +792,26 @@ async def process_file_in_background(
|
||||||
# Use local Faster-Whisper for transcription
|
# Use local Faster-Whisper for transcription
|
||||||
from app.services.stt_service import stt_service
|
from app.services.stt_service import stt_service
|
||||||
|
|
||||||
|
try:
|
||||||
result = stt_service.transcribe_file(file_path)
|
result = stt_service.transcribe_file(file_path)
|
||||||
transcribed_text = result["text"]
|
transcribed_text = result.get("text", "")
|
||||||
|
|
||||||
|
if not transcribed_text:
|
||||||
|
raise ValueError("Transcription returned empty text")
|
||||||
|
except Exception as e:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=422,
|
||||||
|
detail=f"Failed to transcribe audio file {filename}: {str(e)}"
|
||||||
|
) from e
|
||||||
|
|
||||||
await task_logger.log_task_progress(
|
await task_logger.log_task_progress(
|
||||||
log_entry,
|
log_entry,
|
||||||
f"Local STT transcription completed: {filename}",
|
f"Local STT transcription completed: {filename}",
|
||||||
{
|
{
|
||||||
"processing_stage": "local_transcription_complete",
|
"processing_stage": "local_transcription_complete",
|
||||||
"language": result["language"],
|
"language": result.get("language"),
|
||||||
"confidence": result["language_probability"],
|
"confidence": result.get("language_probability"),
|
||||||
"duration": result["duration"],
|
"duration": result.get("duration"),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue