28 lines
1.0 KiB
Python
28 lines
1.0 KiB
Python
import os
|
|
from jobs.job_base import JobBase
|
|
|
|
class JobStandardizeFormat(JobBase):
|
|
"""音声ファイルのフォーマットを標準化するジョブ"""
|
|
def __init__(self):
|
|
super().__init__(name=self.__class__.__name__)
|
|
self.description = "Standardize Audio Format Job"
|
|
|
|
def _convert_ffmpeg(self, src, dst):
|
|
import subprocess, pathlib
|
|
pathlib.Path(dst).parent.mkdir(parents=True, exist_ok=True)
|
|
cmd = ["ffmpeg","-y","-i",src,"-ac","1","-ar","16000","-c:a","pcm_s16le",dst]
|
|
subprocess.run(cmd, check=True)
|
|
|
|
def execute(self):
|
|
self.logger.info(f"{self.name} execute started")
|
|
|
|
if os.path.exists(self.status.unified_file):
|
|
# すでに変換済み
|
|
self.logger.info(f"Audio already standardized: {self.status.unified_file}")
|
|
return
|
|
|
|
src = self.status.source_file
|
|
dst = self.status.unified_file
|
|
# フォーマット変換処理(WAV mono / 16kHz / PCM16)
|
|
self._convert_ffmpeg(src, dst)
|
|
return |