chore: updated docs & refactored sst_service.py

This commit is contained in:
DESKTOP-RTLN3BA\$punk 2025-10-15 14:31:38 -07:00
parent 5ed9aa2b0b
commit 70b547c9c9
5 changed files with 53 additions and 41 deletions

View file

@ -785,20 +785,25 @@ async def process_file_in_background(
)
# Determine STT service type
stt_service_type = "local" if app_config.STT_SERVICE and app_config.STT_SERVICE.startswith("local/") else "external"
stt_service_type = (
"local"
if app_config.STT_SERVICE
and app_config.STT_SERVICE.startswith("local/")
else "external"
)
# Check if using local STT service
if stt_service_type == "local":
# Use local Faster-Whisper for transcription
from app.services.stt_service import stt_service
try:
result = stt_service.transcribe_file(file_path)
transcribed_text = result.get("text", "")
if not transcribed_text:
raise ValueError("Transcription returned empty text")
# Add metadata about the transcription
transcribed_text = (
f"# Transcription of {filename}\n\n{transcribed_text}"
@ -806,9 +811,9 @@ async def process_file_in_background(
except Exception as e:
raise HTTPException(
status_code=422,
detail=f"Failed to transcribe audio file {filename}: {str(e)}"
detail=f"Failed to transcribe audio file {filename}: {e!s}",
) from e
await task_logger.log_task_progress(
log_entry,
f"Local STT transcription completed: {filename}",
@ -828,13 +833,17 @@ async def process_file_in_background(
"api_key": app_config.STT_SERVICE_API_KEY,
}
if app_config.STT_SERVICE_API_BASE:
transcription_kwargs["api_base"] = app_config.STT_SERVICE_API_BASE
transcription_response = await atranscription(**transcription_kwargs)
transcription_kwargs["api_base"] = (
app_config.STT_SERVICE_API_BASE
)
transcription_response = await atranscription(
**transcription_kwargs
)
# Extract the transcribed text
transcribed_text = transcription_response.get("text", "")
if not transcribed_text:
raise ValueError("Transcription returned empty text")