#!/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"
    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
