################################
# VoiceOne Vo-tools Methods
#  
# @package voiceone_webservices
# @subpackage Sounds
################################
###
# getSoundsDir: return AST_SOUND_DIR
### 
getSoundsDir () {
  echo "$AST_SOUND_DIR";
}
###
# soundsInit: make a file.txt that list all the files in AST_SOUND_DIR
###
soundsInit () {
  if [ -e $1/sounds/filesList.txt ]; then
    rm -rf $1/sounds/filesList.txt
  fi
  if [ ! -d "$1/sounds/" ]; then
    mkdir $1/sounds
  fi
  if [ -d "$AST_SOUND_DIR" ]; then
    ls -lHR $AST_SOUND_DIR > $1/sounds/filesList.txt
  fi
  #create voiceone folders in any languages
  cd $AST_SOUND_DIR
  for LANG in *; do
    if [ -d "$AST_SOUND_DIR/$LANG" ];then
      if [ ${#LANG} -eq 2 ] || [ ${#LANG} -eq 5 ];then
        if [ ! -e "$AST_SOUND_DIR/$LANG/voiceone" ];then
          mkdir "$AST_SOUND_DIR/$LANG/voiceone"
          chown -R asterisk.asterisk "$AST_SOUND_DIR/$LANG/voiceone"
        fi
        if [ ! -e "$AST_SOUND_DIR/$LANG/voiceone/custom" ];then
          mkdir "$AST_SOUND_DIR/$LANG/voiceone/custom"
          chown -R asterisk.asterisk "$AST_SOUND_DIR/$LANG/voiceone/custom"
        fi
        if [ ! -e "$AST_SOUND_DIR/$LANG/voiceone/IVR" ];then
          mkdir "$AST_SOUND_DIR/$LANG/voiceone/IVR"
          chown -R asterisk.asterisk "$AST_SOUND_DIR/$LANG/voiceone/IVR"
        fi
      fi
    fi
  done
}
###
# soundsCopy: overwrite an audio file
###
soundsCopy () {
  if [ -e $1 ]; then
    if [ -e $2 ]; then
      rm -f $2
      cp -f $1 $2
      chmod 644 $2
    fi
  fi
}
###
# soundsMoveToSandbox: copy audio file from sounds folder to sandbox
###
soundsMoveToSandbox () {
  if [ ! -d $2 ]; then
    mkdir $2
  fi
  if [ -e $1 ]; then
    #sox $1 -r 8000 -c 1 -s -w $3
    sox $1 -r 8000 -c 1 -s $3
  fi
}
###
# soundsMoveToSandbox: move audio file from sandbox to sounds folder
###
soundsMoveToSounds () {
  if [ ! -d "$AST_SOUND_DIR/voiceone/tmp" ]; then
    mkdir $AST_SOUND_DIR/voiceone/tmp
  fi
  if [ -e $1 ]; then
    if [ $(sox -V $1 -n stat 2>&1 | grep -m 1 Rate | sed "s/.*Rate\s*: //") -ne "8000" ]; then
      sox $1 -r 8000 -c1 $AST_SOUND_DIR/voiceone/tmp/$2 resample -ql
    else
      sox $1 -c1 $AST_SOUND_DIR/voiceone/tmp/$2 
    fi 
  fi
}
###
# soundsClear: remove all audio files from sandbox/sounds
###
soundsClear () {
  rm -f $1
}
###
# soundsCreateEmptyFile: make an empty file in /voiceone/custom
###
soundsCreateEmptyFile () {
  if [ ! -d "$1" ]; then
    mkdir $1
  fi
  if [ ! -e "$1/$2.gsm" ]; then
      touch $1/$2.gsm
  fi
}
###
# soundsCreateLinkFile: make a link to a sound file in a not default lenguage
###
soundsCreateLinkFile () {
  if [ -d "$1" ]; then
    cd $1
    if [ -e "$1" ]; then
      ln -s $2 $3
    fi
  fi
}