-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwavToMp3.sh
More file actions
executable file
·51 lines (42 loc) · 1.5 KB
/
wavToMp3.sh
File metadata and controls
executable file
·51 lines (42 loc) · 1.5 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
44
45
46
47
48
49
50
51
#!/bin/bash
# docs: http://lame.cvs.sourceforge.net/viewvc/lame/lame/USAGE
source @includes.sh
echo '###################################################'
echo '# Description: Convert a wav/aif file to mp3'
echo '# Usage: $ ./wavToMp3.sh /path/to/file.wav [256] [1]'
echo '# Param 1: Wav or Aif file'
echo '# Param 2 [Optional]: Bitrate'
echo '# Param 3 [Optional]: Channels'
echo '# Requires: Lame'
echo '###################################################'
echoNewline
################################################################################
################################################################################
# check parameters
if [[ $1 == "" ]] ; then
echoError '1st arg must be a wav or aif file'
exit 1
fi
bitrate=320
if [[ $2 -eq 0 ]] ; then
echoInfo '[Optional]: Using default bitrate of 320'
else
bitrate=$2
fi
mono=""
if [[ $3 -eq 1 ]] ; then
mono="-a"
echoInfo '[Optional]: Converting to mono'
fi
################################################################################
################################################################################
# get filename
filename=$1
extension=$(extension $filename)
outputFile="$1.$bitrate.mp3"
# do conversion
lame --abr $bitrate --resample 44.1 --bitwidth 16 $mono -q0 "$filename" $outputFile
################################################################################
################################################################################
# complete
echoSuccess "Converted to 16/44.1 mp3 \n# $outputFile"