# Audio Conversions

The audio converter Script goes here:

#!/bin/bash
# Modified: Today by E.l.f
#
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
#
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
#
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the Free Software Foundation, Inc., 51
## Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
## http://www.gnu.org/copyleft/gpl.html
#
## Script-name - oga2ogg.sh
#
RED="\033[0;31m"
BLUE="\033[1;34m"
CYAN="\033[1;36m"
YELLOW="\033[1;33m"
NC="\033[0m"
if [ $USER = root ]; then echo -e$RED"Are you Insane!"
echo -e $RED"Error: In order to use this script, one must NOT be$USER"
echo -e $YELLOW"Exiting..."$NC
exit 0
else
echo ""
echo "    $USER may proceed." echo " May peace be with you." fi clear echo "-------------------Audio Conversions List--------------------" echo echo -e$YELLOW"    Please choose one of the following options:    "$NC echo " Or " echo -e$YELLOW"    Hit Ctrl+c (^c) to stop now."$NC echo -e$BLUE"    \"UPPER\", \"lower\" and \"Capitalized\" spelling "$NC echo " are valid forms of input." echo echo " Convert lossless (*.oga/*.flac) audio files in the " echo " [current] working directory?" echo " OR." echo " Convert them in a [recursive] manner." echo " Starting from within this directory?" echo echo "-------------------------------------------------------------" echo echo -e$CYAN"    [[c]current] or [[r]recursive]"$NC echo -n "Please make your choice: " read Choice ## Based on an adjusted k3b setting: # flac -V -o %f --force-raw-format --best --ogg --endian=little --channels=2 --sample-rate=44100 --sign=signed --bps=16 -T ARTIST=%a -T TITLE=%t -T TRACKNUMBER=%n -T DATE=%y -T ALBUM=%m - ## Though this will compress the audio in a much better fashion and changes the extension from *.flac into *.oga, k3b mysteriously hangs after the last track has been encoded??? ## The default gives you: # flac -V -o %f --force-raw-format --endian=little --channels=2 --sample-rate=44100 --sign=signed --bps=16 -T ARTIST=%a -T TITLE=%t -T TRACKNUMBER=%n -T DATE=%y -T ALBUM=%m - ## And no hangover hickups, i.e. the k3b app doesn't hang on you after it finishes. case "$Choice" in
"C" | "c" | "Current" | "CURRENT" | "current")
## Quality at 9\!  Yeah I know I am an audiophile.
## oggenc's default quality is 3, which is perfectly fine in most cases.
## For 'cd quality' one could consider raising the bar to either 5 or 6\!\?
## Please note that flac IS cd quality as it is a lossless format\!
echo -e $BLUE" Are the files in flac or oga format?"$NC
echo -e $BLUE" I.e. they have an extension either ending in"$NC
echo -e $CYAN" [flac] or [oga]"$NC
echo
echo -n "Enter the extension name: "
case "$answer" in "F" | "f" | "FLAC" | "Flac" | "flac") oggenc -q 9$(ls *.flac | sort -n) || exit 0
#        \rm *.flac
exit 0
;;
"O" | "o" | "OGA" | "Oga" | "oga")
oggenc -q 9 $(ls *.oga | sort -n) || exit 0 # \rm *.oga exit 0 ;; *) echo " Wrong answer!!!" echo " Please rerun the script again?" echo " Then: Either enter yes or no." echo " \"UPPER\", \"lower\" and \"Capitalized\" spelling are supported" echo " Usage: Yes|No" echo exit 0 ;; esac ;; "R" | "r" | "Recursive" | "RECURSIVE" | "recursive") echo -e$BLUE"    Are the files in flac or oga format?"$NC echo -e$BLUE"    I.e. they have an extension either ending in"$NC echo -e$CYAN"    [flac] or [oga]"$NC echo echo -n "Enter the extension name: " read answer case "$answer" in
"F" | "f" | "FLAC" | "Flac" | "flac")
find -iname '*.flac' -exec oggenc -q 9 "{}" \; || exit 0
#       find -iname '*.flac' -exec \rm "{}" \;
exit 0
;;
"O" | "o" | "OGA" | "Oga" | "oga")
find -iname '*.oga' -exec oggenc -q 9 "{}" \; || exit 0
#       find -iname '*.oga' -exec \rm "{}" \;
exit 0
;;
*)
echo "   Wrong answer!!!"
echo "   Please rerun the script again?"
echo "   Then: Either enter yes or no."
echo "   \"UPPER\", \"lower\" and \"Capitalized\" spelling are supported"
echo "   Usage: Yes|No"
echo
exit 0
;;
esac
;;
*)
# Default option.
# Empty input (hitting RETURN) fits here, too.
echo
echo -e $YELLOW" Please choose a valid option!"$NC
echo -e $BLUE" \"UPPER\", \"lower\" and \"Capitalized\" spelling are supported"$NC
echo -e $CYAN" Usage: [[c]current] or [[r]recursive]"$NC
echo
;;
esac
exit 0


Q: So why use flac instead of ripping your cd directly into ogg/mp3/aac et al?
A: Flac is awesome for use as an archiver plus the sound is a 1 on 1 experience for you to listen to (while converting for example.) Anyway I backup all my cds in flac/oga format and at will or convenience I will ‘copy’ them to ogg/vorbis (preferably), mp3 or aac for use with any device which will play any of the specified formats. My preference obviously goes to players who support ogg/vorbis out of the box but a cheap mp3 player will do just fine as well. Imho mp3 suits itself best for use with music that emphasizes low tones, like house/techno/drum&bass et al but that could just be the way I experience it, I am far from having an ‘absolute hearing’ though. 😉

See the galleries for more:
This gallery shows the differences in file size before and after the conversion.

This gallery shows the script in action.

And this one shows what I use to rip the original cd.

Though I use different specs in the script I included in this post! It is however perfectly fine for you to use k3b’s defaults while ripping (as it says in the apps tooltip that the defaults are fine for everyday use.) Because k3b mysteriously hangs when it is finished ripping, while using the other options, and therefore needs to be killed the hard way by me: e.g. kill -s 9 <procid of k3b> (has no side effects though 😆 but a nuisance to do, yes!? My next step would be to figure out how to for example obtain cd text (album-artist-title tag) info without the use of a gui, i.e. direct encoding of my cd into flac from the cli.

From the ‘man flac‘:

–ogg When encoding, generate Ogg FLAC output instead of native FLAC. Ogg FLAC streams are FLAC streams wrapped in an Ogg transport layer. The resulting
file should have an ‘.oga’ extension and will still be decodable by flac.

When decoding, force the input to be treated as Ogg FLAC. This is useful when piping input from stdin or when the filename does not end in ‘.oga’
or ‘.ogg’.

-8, –compression-level-8
Synonymous with -l 12 -b 4096 -m -e -r 6

–best Highest compression. Currently synonymous with -8.

These are the Artist-Album (foldername) and Artist-Title (subfolder) options I use in k3b:
Ugly filenames with spaces be gone… 😆

• # %A-%T/%n !a=’%A'{%a-}%t
• # %{albumartist}-%{albumtitle}
• # Replace all blanks with: .

PS: Oh, before I forget! Please note the time it takes to encode to ogg (approx ~ 15 sec) *Very Fast* Also I’ve tried several gui’s, to achieve the goal I achieved with this script, e.g. OggConvert, soundKonverter and vlc (does encode to mp3 though!) all of which had issues with the used oga extension!?

## 2 thoughts on “Audio Conversions”

1. Something I stumled upon while fiddling around. 😆
Oh, ‘Great Init’ how I love the (tool)chain of command!

## A quick and dirty way to create 'm3u' lists\!\?
echo "#EXTM3U" > output.m3u
find -iname '*.ogg' -exec ls "{}" \; | sort -n >> output.m3u
find -iname '*.mp3' -exec ls "{}" \; | sort -n >> output.m3u
find -iname '*.someExtension' -exec ls "{}" \; | sort -n >> output.m3u
## Now one can open output.m3u with vlc and save the playlist as e.g. output.xspf


Why? Because I don’t like to click more than once to play my media. 😉

That it may it be of use!

Like

• A sample script follows:

#!/bin/bash
# Modified: Today by E.l.f
#
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
#
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
#
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the Free Software Foundation, Inc., 51
## Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
## http://www.gnu.org/copyleft/gpl.html
#
## Script-name - create.m3u.sh
#
RED="\033[0;31m"
BLUE="\033[1;34m"
CYAN="\033[1;36m"
YELLOW="\033[1;33m"
NC="\033[0m"
if [ $USER = root ]; then echo -e$RED"   Are you Insane!"
echo -e $CYAN" Error: In order to use this script, one must NOT be$USER"
echo -e $YELLOW" Exiting..."$NC
exit 0
else
echo ""
echo -e $BLUE"$USER may proceed."
echo -e $CYAN" May peace be with you."$NC
fi
clear
echo -n "Enter filename: "
OUTPUT=$OUTPUT OUTPUT+=".m3u" echo "#EXTM3U" > "$OUTPUT"
find -iname '*.ogg' -exec ls "{}" \; | sort -n >> "$OUTPUT" find -iname '*.mp3' -exec ls "{}" \; | sort -n >> "$OUTPUT"