How to edit an audio file.
Input file
Output file
Conversion program Cut out 3 to 7 seconds from the input file.
edit.py
#! /usr/bin/python
#
# edit.py
#
# Oct/06/2020
#
# ------------------------------------------------------------------
import sys
from pydub import AudioSegment
# ------------------------------------------------------------------
sys.stderr.write("***start***\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("***End***\n")
# ------------------------------------------------------------------
Execution method
./edit.py input.wav out.wav
I confirmed it in the next version.
$ python --version
Python 3.8.2
Recommended Posts