MediaRouter / app /api /whisper.py
basyx's picture
Upload 142 files
fba6023 verified
Raw
History Blame Contribute Delete
1.14 kB
from __future__ import annotations
from fastapi import APIRouter, Request
from app.api.media import get_processor
from app.core.response import SuccessResponse
router = APIRouter(prefix="/v1/whisper", tags=["whisper"])
async def _transcribe(request: Request, default_format: str | None = None) -> SuccessResponse:
request.state.operation = "whisper.transcribe"
processor = get_processor(request)
resolved = await processor.resolver.resolve(request)
if default_format and "output_format" not in resolved.params:
resolved.params["output_format"] = default_format
return await processor.run_whisper(resolved)
@router.post("/transcribe", response_model=SuccessResponse)
async def transcribe(request: Request) -> SuccessResponse:
return await _transcribe(request)
@router.post("/subtitles", response_model=SuccessResponse)
async def subtitles(request: Request) -> SuccessResponse:
return await _transcribe(request, "srt")
@router.post("/detect-language", response_model=SuccessResponse)
async def detect_language(request: Request) -> SuccessResponse:
return await _transcribe(request, "json")