0
2

More than 3 years have passed since last update.

Python: pydub の使い方

Posted at

オーディオファイルを編集する方法です。

入力ファイル
input.png

出力ファイル
out.png

変換プログラム
入力ファイルから 3sec から 7sec までを切り出します。

edit.py
#! /usr/bin/python
#
#   edit.py
#
#                       Oct/06/2020
#
# ------------------------------------------------------------------
import sys
from pydub import AudioSegment

# ------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
#
file_in = sys.argv[1]
file_out = sys.argv[2]

audio_aa = AudioSegment.from_mp3(file_in)
start = 3 * 1000
end = 7 * 1000
audio_bb = audio_aa[start:end]
audio_bb.export(file_out, format="wav")
#
sys.stderr.write("*** 終了 ***\n")
# ------------------------------------------------------------------

実行方法

./edit.py input.wav out.wav

次のバージョンで確認しました。

$ python --version
Python 3.8.2
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2