Created function for generating sound files and code refactoring.