raspberrypi/acatcher/convert_audio.sh
2015-02-20 23:19:24 -08:00

28 lines
909 B
Bash
Executable file
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Signed 16 bit Little Endian, Rate 22050 Hz, Mono
#
# use "play" command to play back audio
if [ -z "$1" ]; then
for INFILE in *.raw; do
FIX="`echo $INFILE | sed -e 's/^\[.*\] //g'`"
OUTFILE="`basename \"$FIX\" .raw`.wav"
if [ -f "$OUTFILE" ] ; then
FUDGE="$RANDOM"
OUTFILE="`basename \"$OUTFILE\" .wav`-$FUDGE.wav"
FIX="`basename \"$FIX\" .raw`-$FUDGE.raw"
fi
echo "converting $INFILE to $OUTFILE"
#sox -r 44100 -e unsigned -b 8 -c 1 <RAW_FILE> <TARGET_FILE>
sox -r 22050 -e signed -b 16 -L -c 1 "$INFILE" "$OUTFILE"
mv "$INFILE" "$FIX"
done
else
INFILE="$1"
FIX="`echo $INFILE | sed -e 's/^\[.*\] //g'`"
OUTFILE="`basename \"$FIX\" .raw`.wav"
echo "converting $INFILE to $OUTFILE"
#sox -r 44100 -e unsigned -b 8 -c 1 <RAW_FILE> <TARGET_FILE>
sox -r 22050 -e signed -b 16 -L -c 1 "$INFILE" "$OUTFILE"
mv "$INFILE" "$FIX"
fi