add sentences borders enable in pc player
This commit is contained in:
@@ -2,6 +2,7 @@ import hashlib
|
||||
import hmac
|
||||
import logging
|
||||
import mimetypes
|
||||
import tempfile
|
||||
import uuid
|
||||
import urllib.request
|
||||
import urllib.error
|
||||
@@ -57,7 +58,7 @@ from .models import (
|
||||
VideoUploadResponse,
|
||||
)
|
||||
from .oss import VolcanoOSSUploader
|
||||
from .processing import VideoProcessor, split_sentence_text
|
||||
from .processing import VideoProcessor, generate_audio_boundary_document, split_sentence_text
|
||||
from .repository import VideoRepository
|
||||
from .store import BoundaryStore
|
||||
from .transcription import MossTranscriber, Transcriber
|
||||
@@ -72,6 +73,7 @@ SHA256_PATH = ApiPath(
|
||||
)
|
||||
ALLOWED_VIDEO_EXTENSIONS = {".mp4", ".m4v", ".mov", ".mkv", ".webm"}
|
||||
ALLOWED_AUDIO_EXTENSIONS = {".m4a", ".mp4", ".wav"}
|
||||
MAX_AUDIO_BOUNDARY_BYTES = 512 * 1024 * 1024
|
||||
|
||||
|
||||
class UploadTooLargeError(ValueError):
|
||||
@@ -329,6 +331,47 @@ def create_app(
|
||||
raise HTTPException(status_code=503, detail=str(exc)) from exc
|
||||
return SentenceExplanationResponse(explanation=explanation)
|
||||
|
||||
@application.post(
|
||||
"/api/v1/audio/sentence-boundaries",
|
||||
response_model=SentenceBoundaryDocument,
|
||||
)
|
||||
async def generate_sentence_boundaries(
|
||||
file: UploadFile = File(...),
|
||||
language: Optional[str] = Form(default=None, max_length=32),
|
||||
user: AuthenticatedUser = Depends(current_user),
|
||||
) -> SentenceBoundaryDocument:
|
||||
del user
|
||||
max_bytes = min(MAX_AUDIO_BOUNDARY_BYTES, service_settings.max_upload_bytes)
|
||||
with tempfile.TemporaryDirectory(prefix="audio-boundaries-") as temp_dir:
|
||||
audio_path = Path(temp_dir) / "audio.wav"
|
||||
try:
|
||||
audio_hash, _size = await run_in_threadpool(
|
||||
_persist_upload,
|
||||
file.file,
|
||||
audio_path,
|
||||
max_bytes,
|
||||
)
|
||||
document = await run_in_threadpool(
|
||||
generate_audio_boundary_document,
|
||||
video_hash=audio_hash,
|
||||
audio_path=audio_path,
|
||||
transcriber=moss,
|
||||
language=language,
|
||||
)
|
||||
except UploadTooLargeError as exc:
|
||||
raise HTTPException(status_code=413, detail=str(exc)) from exc
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=422, detail=str(exc)) from exc
|
||||
except Exception as exc:
|
||||
logger.exception("Ad-hoc audio sentence boundary generation failed.")
|
||||
raise HTTPException(
|
||||
status_code=502,
|
||||
detail="Sentence boundary generation failed. Please try again later.",
|
||||
) from exc
|
||||
finally:
|
||||
await file.close()
|
||||
return document
|
||||
|
||||
@application.delete("/api/v1/courses/{video_hash}/enroll", status_code=204)
|
||||
def unenroll_course(
|
||||
video_hash: str = SHA256_PATH,
|
||||
|
||||
Reference in New Issue
Block a user