#!/bin/sh
##### -*- mode:shell-script; indent-tabs-mode:nil; sh-basic-offset:2 -*-
##### Author: Travis Cross <tc@traviscross.com>

set -e

spath=/usr/share/freeswitch/sounds/en/us/allison
bpath=en/us/allison

case "$1" in
  configure)
    for r in 8000 16000 32000 48000; do
      echo "Generating sounds at $r Hz..." >&2
      for d in $spath/*; do
        [ -d $d ] || continue
        if [ x"$bpath" = x"music" ]
        then
          mkdir -p $d/../$r
        else
          mkdir -p $d/$r
        fi
        for f in $d/flac/*.flac; do
          [ -f $f ] || continue
          w=${f%.flac}.wav
          if [ x"$bpath" = x"music" ]
          then
            flac -s -d -c $f | sox -t wav - -c1 -r$r -b16 -e signed-integer $d/../$r/${w##*/}
          else
            flac -s -d -c $f | sox -t wav - -c1 -r$r -b16 -e signed-integer $d/$r/${w##*/}
          fi
        done
      done
    done
    # for d in $spath/*; do rm -rf $d/flac; done
    ;;
  abort-upgrade|abort-remove|abort-deconfigure)
    ;;
  *)
    echo "postinst called with unknown argument \`$1'" >&2
    exit 1
    ;;
esac

#DEBHELPER#
exit 0
