set -e # exit immediately on error
set -u # error if a variable is misspelled

while read -r my_file; do
  my_new="$(dirname "$my_file")/$(basename "$my_file" .wav).flac"

  ffmpeg -i "$my_file" -acodec flac "$my_new"

  # safe because of set -e, but still do a test run
  #rm "$my_file"
done <<< "$(find . -type f -name '*.wav')"

