ai tools finished
This commit is contained in:
@ -60,6 +60,8 @@ async def generate_captions(req: CaptionRequest):
|
||||
|
||||
return PlainTextResponse(content, media_type="text/plain")
|
||||
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
logger.error(f"Caption generation failed: {e}", exc_info=True)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
@ -200,6 +200,8 @@ async def export_video(req: ExportRequest):
|
||||
result["srt_path"] = srt_path
|
||||
return result
|
||||
|
||||
except HTTPException:
|
||||
raise
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
except RuntimeError as e:
|
||||
|
||||
@ -7,23 +7,52 @@ import logging
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
import warnings
|
||||
from pathlib import Path
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
try:
|
||||
from df.enhance import enhance, init_df, load_audio, save_audio
|
||||
DEEPFILTER_AVAILABLE = True
|
||||
except ImportError:
|
||||
DEEPFILTER_AVAILABLE = False
|
||||
DEEPFILTER_AVAILABLE = None
|
||||
enhance = None
|
||||
init_df = None
|
||||
load_audio = None
|
||||
save_audio = None
|
||||
|
||||
|
||||
_df_model = None
|
||||
_df_state = None
|
||||
|
||||
|
||||
def _ensure_deepfilter_loaded() -> bool:
|
||||
global DEEPFILTER_AVAILABLE, enhance, init_df, load_audio, save_audio
|
||||
if DEEPFILTER_AVAILABLE is not None:
|
||||
return DEEPFILTER_AVAILABLE
|
||||
|
||||
try:
|
||||
# DeepFilterNet currently triggers a third-party torchaudio deprecation warning
|
||||
# on import in some environments; suppress only this known warning.
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings(
|
||||
"ignore",
|
||||
message=r".*torchaudio\._backend\.common\.AudioMetaData has been moved.*",
|
||||
category=UserWarning,
|
||||
)
|
||||
from df.enhance import enhance as _enhance, init_df as _init_df, load_audio as _load_audio, save_audio as _save_audio
|
||||
enhance = _enhance
|
||||
init_df = _init_df
|
||||
load_audio = _load_audio
|
||||
save_audio = _save_audio
|
||||
DEEPFILTER_AVAILABLE = True
|
||||
except ImportError:
|
||||
DEEPFILTER_AVAILABLE = False
|
||||
|
||||
return DEEPFILTER_AVAILABLE
|
||||
|
||||
|
||||
def _init_deepfilter():
|
||||
global _df_model, _df_state
|
||||
if not _ensure_deepfilter_loaded():
|
||||
raise RuntimeError("DeepFilterNet is not available")
|
||||
if _df_model is None:
|
||||
logger.info("Initializing DeepFilterNet model")
|
||||
_df_model, _df_state, _ = init_df()
|
||||
@ -46,7 +75,7 @@ def clean_audio(
|
||||
if not output_path:
|
||||
output_path = str(input_path.with_stem(input_path.stem + "_clean"))
|
||||
|
||||
if DEEPFILTER_AVAILABLE:
|
||||
if is_deepfilter_available():
|
||||
return _clean_with_deepfilter(str(input_path), output_path)
|
||||
else:
|
||||
return _clean_with_ffmpeg(str(input_path), output_path)
|
||||
@ -77,7 +106,7 @@ def _clean_with_ffmpeg(input_path: str, output_path: str) -> str:
|
||||
|
||||
|
||||
def is_deepfilter_available() -> bool:
|
||||
return DEEPFILTER_AVAILABLE
|
||||
return _ensure_deepfilter_loaded()
|
||||
|
||||
|
||||
def detect_silence_ranges(input_path: str, min_silence_ms: int, silence_db: float):
|
||||
|
||||
Reference in New Issue
Block a user