Spaces:
Runtime error
Runtime error
feat: Use is_api_key_error flag from backend + onclick-based button for reliable change key UX
bc7bdb7 Download video_processor.py from ILRDF-Lowking/Truku-AI-Translator: direct link, hf CLI and curl.
- Browser
- Download file 643 Bytes
-
https://huggingface.co/spaces/ILRDF-Lowking/Truku-AI-Translator/resolve/main/video_processor.py
- Command line
-
hf download hf://spaces/ILRDF-Lowking/Truku-AI-Translator/video_processor.py
-
curl -L -o video_processor.py https://huggingface.co/spaces/ILRDF-Lowking/Truku-AI-Translator/resolve/main/video_processor.py
643 Bytes
| # video_processor.py | |
| from moviepy import VideoFileClip | |
| import os | |
| def extract_audio(video_path, output_audio_path): | |
| """從影片中提取音軌並轉為 wav 格式""" | |
| try: | |
| # 載入影片 | |
| video = VideoFileClip(video_path) | |
| # 提取音軌 | |
| audio = video.audio | |
| # 寫出音檔 (設定為 16000Hz 以利 ASR 辨識) | |
| audio.write_audiofile(output_audio_path, fps=16000, nbytes=2, codec='pcm_s16le') | |
| # 關閉資源釋放記憶體 | |
| video.close() | |
| audio.close() | |
| return True | |
| except Exception as e: | |
| print(f"影片音軌提取失敗: {e}") | |
| return False |