356108e792
- Video pipeline: video file OCR via VLM plus audio track ASR, integrated into job_handlers with progress emit per phase. New media_utils.py for audio extraction from video files. - Document export: richExport.js replaces inline docx builder; DOCX and PDF export buttons are now enabled in MilkdownEditor. File size limit raised to 100 MB. - Input block: new InputBlockCrepe.vue component with inputBlockPlugin.ts and inputBlock.js for custom user-input nodes in the editor. - Risk config: added Vite dev server ports (5173) to CORS allowlist and increased OCR max input from 10 MB to 100 MB. - TTS/ASR refactor: simplified tts_asr.py model loading and warmup logic. - Test coverage: updated tests for llm, main endpoints, pro completions and web search modules. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
import subprocess
|
|
import tempfile
|
|
|
|
|
|
VIDEO_EXTENSIONS = {".mp4", ".webm", ".mov", ".avi", ".mkv", ".m4v", ".ogv"}
|
|
|
|
|
|
def is_video_filename(filename: str = "", mime_type: str = "") -> bool:
|
|
ext = os.path.splitext(filename or "")[1].lower()
|
|
mime = (mime_type or "").strip().lower()
|
|
return ext in VIDEO_EXTENSIONS or mime.startswith("video/")
|
|
|
|
|
|
def extract_audio_wav_bytes(input_path: str) -> bytes:
|
|
if not input_path or not os.path.exists(input_path):
|
|
raise FileNotFoundError("输入媒体文件不存在")
|
|
|
|
fd, output_path = tempfile.mkstemp(suffix=".wav")
|
|
os.close(fd)
|
|
try:
|
|
subprocess.run(
|
|
[
|
|
"ffmpeg",
|
|
"-y",
|
|
"-i",
|
|
input_path,
|
|
"-vn",
|
|
"-acodec",
|
|
"pcm_s16le",
|
|
"-ar",
|
|
"16000",
|
|
"-ac",
|
|
"1",
|
|
output_path,
|
|
],
|
|
check=True,
|
|
stdout=subprocess.PIPE,
|
|
stderr=subprocess.PIPE,
|
|
)
|
|
with open(output_path, "rb") as handle:
|
|
return handle.read()
|
|
finally:
|
|
if os.path.exists(output_path):
|
|
os.unlink(output_path)
|