Using Sox, LAME, FLAC, and madplay — I put together this “dictionary” of shell commands that can be run to convert audio from one format to other, including dialup-modem-streamable lofi mono MP3 files, and including shorter clips of music.
Above each command-line and the INPUT and OUTPUT audio formats. (represented by $in and $out in the command line.)
For short audio clips, you need $start — what second to start the clip at, and $duration — how long the clip should go. All clips have a 1-second fade-in, and 2-second fade-out.
flac wav
flac -sd $in -o $out
flac wav clip
flac -sdc $in | sox -t wav — -t raw -s -w -c 2 — trim $start $duration | sox -t raw -r 44100 -s -w -c 2 — $out fade h 1 $duration 2
flac wav-lofi
flac -sdc $in | sox -t wav — -s -w -c 1 -r 22050 $out rate
flac mp3-hifi
flac -sdc $in | lame — $out
flac mp3-hifi clip
flac -sdc $in | sox -t wav — -t raw -s -w -c 2 — trim $start $duration | sox -t raw -r 44100 -s -w -c 2 — -t wav — fade h 1 $duration 2 | lame — $out
flac mp3-lofi
flac -sdc $in | sox -t wav — -t wav -s -w -c 1 -r 22050 — rate | lame -b 80 — $out
flac mp3-lofi clip
flac -sdc $in | sox -t wav — -t raw -s -w -c 1 -r 22050 — rate | sox -t raw -r 22050 -s -w -c 1 — -t raw -r 22050 -s -w -c 1 — trim $start $duration | sox -t raw -r 22050 -s -w -c 1 — -t wav — fade h 1 $duration 2 | lame -b 80 — $out
wav flac
flac -s $in -o $out
wav wav clip
sox -t wav $in -t raw -s -w -c 2 — trim $start $duration | sox -t raw -r 44100 -s -w -c 2 — -t wav $out fade h 1 $duration 2
wav wav lofi
sox -t wav $in -s -w -c 1 -r 22050 $out rate
wav mp3-hifi
lame $in $out
wav mp3-hifi clip
sox -t wav $in -t raw -s -w -c 2 — trim $start $duration | sox -t raw -r 44100 -s -w -c 2 — -t wav — fade h 1 $duration 2 | lame — $out
wav mp3-lofi
sox -t wav $in -t wav -s -w -c 1 -r 22050 — rate | lame -b 80 — $out
wav mp3-lofi clip
sox -t wav $in -t raw -s -w -c 1 -r 22050 — rate | sox -t raw -r 22050 -s -w -c 1 — -t raw -r 22050 -s -w -c 1 — trim $start $duration | sox -t raw -r 22050 -s -w -c 1 — -t wav — fade h 1 $duration 2 | lame -b 80 — $out
mp3 flac
madplay -q -o wave:- $in | flac -s — -o $out
mp3 wav clip
madplay -q -o wave:- $in | sox -t wav — -t raw -s -w -c 2 — trim $start $duration | sox -t raw -r 44100 -s -w -c 2 — $out fade h 1 $duration 2
mp3 wav lofi
madplay -q -o wave:$out -m -R 22050 $in
mp3 mp3-hifi
cp $in $out
mp3 mp3-hifi clip
madplay -q -o wave:- $in | sox -t wav — -t raw -s -w -c 2 — trim $start $duration | sox -t raw -r 44100 -s -w -c 2 — -t wav — fade h 1 $duration 2 | lame — $out
mp3 mp3-lofi
madplay -q -o wave:- -m -R 22050 $in | lame -b 80 — $out
mp3 mp3-lofi clip
madplay -q -o wave:- -m -R 22050 $in | sox -t raw -r 22050 -s -w -c 1 — -t raw -r 22050 -s -w -c 1 — trim $start $duration | sox -t raw -r 22050 -s -w -c 1 — -t wav — fade h 1 $duration 2 | lame -b 80 — $out
Got any more single-line open-source audio-converting commands to add?
—————————————————
Try this one 🙂
ls *.flac |while read a; do n=$(basename «$a» .flac); flac -sdc «$a» |lame -V 1 — «${n}.mp3» ; done
————————————————
just save this into a file
such as convert.sh and make it executable
#!/bin/bash
FILES=$(ls *.flac | cut -d ‘.’ -f1)
for i in $FILES; do
echo converting: $i.flac
flac -sdc $i.flac | lame — $i.mp3
done
—————————————-