I changed the debugging output (echos file name, duration, and freq) to stderr. I moved these lines into a void function that is called.