Spaces:
Sleeping
Sleeping
Download tools/audio_tools.py from KeyBow/MediaMaster-v2: direct link, hf CLI and curl.
- Browser
- Download file 834 Bytes
-
https://huggingface.co/spaces/KeyBow/MediaMaster-v2/resolve/main/tools/audio_tools.py
- Command line
-
hf download hf://spaces/KeyBow/MediaMaster-v2/tools/audio_tools.py
-
curl -L -o audio_tools.py https://huggingface.co/spaces/KeyBow/MediaMaster-v2/resolve/main/tools/audio_tools.py
834 Bytes
| """ | |
| audio_tools.py | |
| 音声関連の変換処理 | |
| - m4a-mp3 : M4A → MP3 | |
| - mp4-mp3 : MP4(動画)→ MP3(音声抽出) | |
| """ | |
| import os | |
| from typing import List | |
| from pydub import AudioSegment | |
| from tools.base_tool import tasks | |
| # ---------- M4A / MP4 → MP3 ---------- | |
| def convert_to_mp3(task_id: str, filenames: List[str], input_path: str, output_path: str): | |
| """M4A または MP4 ファイルを MP3 に変換する""" | |
| for i, fname in enumerate(filenames): | |
| in_f = os.path.join(input_path, fname) | |
| tasks[task_id]["last_log"] = f"処理中: {fname}" | |
| tasks[task_id]["progress"] = int(20 + (i / len(filenames)) * 60) | |
| audio = AudioSegment.from_file(in_f) | |
| audio.export( | |
| os.path.join(output_path, f"{os.path.splitext(fname)[0]}.mp3"), | |
| format="mp3" | |
| ) | |