AI에게 동영상에서 오디오를 추출해서 Text로 변환하라고 했는데, 로컬에 일부 파일 설치가 안되어 Text로 변환하지 못했다.
로컬에서 실행하는 오디오 추출 프로그램을 다운받아 인식했다. 원래는 cactus-needle 모듈을 이용하려고 했는데, 한국어를 지원하지 못한다. 그래서 이모듈로 전환했는데, 분량이 적어서인지 속도도 늦지 않고 인식도 잘 된다.
pip install mlx-whisper pip install --upgrade --force-reinstall scipy
파이썬 코드는 아래와 같다. 변환하려는 오디오 파일은 “suncoach-1015-063352.wav” 이다.
import sys
from pathlib import Path
import mlx_whisper
MODEL = "mlx-community/whisper-large-v3-turbo"
EXTS = {".wav", ".mp3", ".m4a", ".flac", ".ogg", ".aac"}
# 인자가 있으면 해당 파일만, 없으면 현재 폴더의 모든 오디오 파일
args = sys.argv[1:]
if args:
files = [Path(a) for a in args]
else:
files = sorted(p for p in Path(".").iterdir()
if p.is_file() and p.suffix.lower() in EXTS)
if not files:
print("변환할 오디오 파일이 없습니다.")
sys.exit(0)
for i, f in enumerate(files, 1):
out = f.with_suffix(".txt")
if out.exists():
print(f"[{i}/{len(files)}] 건너뜀 (이미 있음): {out.name}")
continue
print(f"[{i}/{len(files)}] 변환 중: {f.name}")
result = mlx_whisper.transcribe(
str(f),
path_or_hf_repo=MODEL,
language="ko",
condition_on_previous_text=False, # 같은 문장 반복 방지
)
text = result["text"].strip()
out.write_text(text + "\n", encoding="utf-8")
print(f" 저장됨: {out.name}\n")
print("완료")