Spaces:
Sleeping
Sleeping
File size: 834 Bytes
264fa46 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | """
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"
)
|