Improved script for generating sounds from wav