mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-06-16 08:25:18 +02:00
feat: allow recording audio in workflow builder
This commit is contained in:
parent
ac0731a374
commit
2fa4191d9b
22 changed files with 700 additions and 246 deletions
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
from typing import Annotated, Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from fastapi import APIRouter, Depends, File, Form, HTTPException, Query, UploadFile
|
||||
from loguru import logger
|
||||
|
||||
from api.constants import DEPLOYMENT_MODE
|
||||
from api.db import db_client
|
||||
from api.db.workflow_recording_client import generate_short_id
|
||||
from api.enums import StorageBackend
|
||||
|
|
@ -16,6 +17,7 @@ from api.schemas.workflow_recording import (
|
|||
RecordingUploadResponseSchema,
|
||||
)
|
||||
from api.services.auth.depends import get_user
|
||||
from api.services.mps_service_key_client import mps_service_key_client
|
||||
from api.services.storage import storage_fs
|
||||
|
||||
router = APIRouter(prefix="/workflow-recordings", tags=["workflow-recordings"])
|
||||
|
|
@ -216,3 +218,42 @@ async def delete_recording(
|
|||
raise HTTPException(
|
||||
status_code=500, detail="Failed to delete recording"
|
||||
) from exc
|
||||
|
||||
|
||||
@router.post(
|
||||
"/transcribe",
|
||||
summary="Transcribe an audio file",
|
||||
)
|
||||
async def transcribe_audio(
|
||||
file: UploadFile = File(...),
|
||||
language: str = Form("en"),
|
||||
user=Depends(get_user),
|
||||
):
|
||||
"""Transcribe an uploaded audio file using MPS STT."""
|
||||
try:
|
||||
audio_data = await file.read()
|
||||
|
||||
if DEPLOYMENT_MODE == "oss":
|
||||
result = await mps_service_key_client.transcribe_audio(
|
||||
audio_data=audio_data,
|
||||
filename=file.filename or "audio.wav",
|
||||
content_type=file.content_type or "audio/wav",
|
||||
language=language,
|
||||
created_by=str(user.provider_id),
|
||||
)
|
||||
else:
|
||||
result = await mps_service_key_client.transcribe_audio(
|
||||
audio_data=audio_data,
|
||||
filename=file.filename or "audio.wav",
|
||||
content_type=file.content_type or "audio/wav",
|
||||
language=language,
|
||||
organization_id=user.selected_organization_id,
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
except Exception as exc:
|
||||
logger.error(f"Error transcribing audio: {exc}")
|
||||
raise HTTPException(
|
||||
status_code=500, detail="Failed to transcribe audio"
|
||||
) from exc
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue