-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvertm4a.py
More file actions
43 lines (34 loc) · 1.16 KB
/
convertm4a.py
File metadata and controls
43 lines (34 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/python
from pydub import AudioSegment
import sys
import re
appname = "convertwav.py"
gaindB = 30
usage = """ This script reads an input M4A file and converts it to
MP3 with a """ + str(gaindB) + """ dB gain.
Usage:
> python """ + appname + """ FILENAME.WAV
Output: FILENAME_converted.mp3
"""
myargs = sys.argv # read command line args
if len(myargs) < 2: # if there are not enough args, print usage and exit
print("ERROR: not enough parameters.\n")
sys.exit(usage)
infile = myargs[1]
if not re.search("\.m4a$", infile, re.IGNORECASE):
print("ERROR: Input", infile, "is not an M4A file.\n")
sys.exit(usage)
outfile = infile.split('.')[0] + "_converted.mp3"
print("Input =", infile)
print("Output =", outfile)
# files
src = infile
dst = outfile
print("Preparing to convert M4A file to MP3")
input("Press Enter to continue...")
#sys.exit("Goodbye")
print("Converting from M4A to MP3...")
# convert m4a to mp3
sound = AudioSegment.from_file(src, format="m4a")
sound = sound + gaindB
sound.export(dst, format="mp3")