Python: How to use pydub

How to edit an audio file.

Input file input.png

Output file out.png

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

Python: How to use pydub
Python: How to use pydub (playback)
python3: How to use bottle (2)
How to use Python argparse
[Python] How to use checkio
[Python] How to use input ()
How to use Python lambda
[Python] How to use virtualenv
python3: How to use bottle (3)
python3: How to use bottle
How to use Python bytes
[Python] How to use Pandas Series
How to use Requests (Python Library)
How to use SQLite in Python
[Python] How to use list 3 Added
How to use Mysql in python
How to use OpenPose's Python API
How to use ChemSpider in Python
How to use FTP with Python
How to use PubChem in Python
How to use python zip function
[Python] How to use Typetalk API
How to use xml.etree.ElementTree
How to use Python-shell
[Python] Summary of how to use pandas
[Introduction to Python] How to use class in Python?
How to use tf.data
How to use virtualenv
How to use Seaboan
How to use image-match
How to use shogun
How to install Python
How to install and use pandas_datareader [Python]
How to use Virtualenv
How to use numpy.vectorize
How to use pytest_report_header
[python] How to use __command__, function explanation
How to use partial
How to use Bio.Phylo
How to use SymPy
[Python] How to use import sys sys.argv
How to use x-means
How to use WikiExtractor.py
[Python] Organizing how to use for statements
Memorandum on how to use gremlin python
How to use virtualenv
[Python2.7] Summary of how to use unittest
How to use Matplotlib
How to use iptables
python: How to use locals () and globals ()
How to use numpy
How to use __slots__ in Python class
How to use TokyoTechFes2015
How to use venv
How to use dictionary {}
How to use Pyenv
How to use list []
How to use "deque" for Python data
How to use python-kabusapi
How to use Python zip and enumerate
[Python] Understand how to use recursive functions