@@ -0,0 +1,1897 @@
+#!/usr/bin/env python%0Aimport wave%0Aimport struct%0Aimport os%0Aimport sys%0A%0A# gets tuple of (%22-f%7C-d%22, %5Bpath%5D) and determines if it's a dir%0Adef is_directory(audio_input):%0A    return audio_input%5B0%5D == %22-d%22%0A%0Adef is_mp3(file):%0A    return True%0A%0A%22%22%22%0Acreate_file_array:%0ACreates an array of all valid files from input%0AIf it's a single file, creates a single-element array%0AIf it's a directory, creates an array with its valid files, %0Afilters out files with unsupported formats%0AAssumes that audio_input is a valid path to something that exists%0A%0AINPUT: Valid paths to a file or directory%0AOUTPUT: Array of all valid files from input%0A%22%22%22%0Adef create_file_array(audio_input):%0A    if (is_directory(audio_input)):%0A        input_dir = os.listdir(audio_input%5B1%5D)%0A        file_array = %5B%5D%0A        for filename in input_dir:%0A            full_filename = audio_input%5B1%5D + '/' + filename%0A            if (validate_file(full_filename)):%0A                file_array.append(full_filename)%0A            else:%0A                print %22Program terminating...%22%0A                sys.exit(2)%0A        return file_array%0A    else:%0A        return %5Baudio_input%5B1%5D%5D%0A%0Adef validate_file(file_input):%0A    try:%0A        wave.open(file_input, 'rb')%0A        return True%0A    except IOError:%0A        print %22ERROR: file %22, file_input,%22 does not exist%22%0A    except wave.Error:%0A        print %22ERROR: file %22, file_input,%22 is not a supported format%22%0A    return False%0A%0A%0Adef validate_input(file_input):%0A    path = file_input%5B1%5D%0A    try:%0A        if (is_directory(file_input)):%0A            os.listdir(path)%0A            return True%0A        else:%0A            return validate_file(path)%0A    except OSError:%0A        print %22ERROR: directory %22, path,%22 does not exist%22%0A    return False%0A%0Adef length(wave_file):%0A    wr = wave.open(wave_file, %22rb%22)%0A    sample_rate = wr.getframerate()%0A    num_frames = wr.getnframes()%0A    wr.close()%0A%0A    return num_frames / float(sample_rate);%0A

add read_audio