def main(argv):
    input_directory = UNTESTED_DIR
    training_file = DEFAULT_TRAINING_FILE
    InputMethod = "FFT"

    try:
        opts, args = getopt.getopt(argv, "hmfi:", ["input="])
    except:
        print "Error gettiong options"
        Usage()
        sys.exit(2)

    for opt, arg in opts:
        if opt == '-h':
            Usage()
            sys.exit()
        elif opt in ('-m'):
            InputMethod = "MEL"
        elif opt in ('-f'):
            InputMethod = "FFT"
        elif opt in ('-i', '--input'):
            input_directory = arg

    with open('objs.pickle') as f:
        clf = pickle.load(f)

    if InputMethod == "FFT":
        print "Using FFT Training"
        X, file_names = blind_read_fft(input_directory)
        file_extension = 'fft.npy'
    elif InputMethod == "MEL":
        print "Using MFCC Training"
        X, file_names = MakeMFCC.blind_read_ceps(input_directory)
        file_extension = 'ceps.npy'
    else:
        print "No valid input method"
        sys.exit()

    y_pred = clf.predict(X)

    print y_pred

    pass_dir = "/home/colin/Documents/Octave/CatMeow/TestRun/WithCat/"
    fail_dir = "/home/colin/Documents/Octave/CatMeow/TestRun/NoCat/"
    # TODO: Verify output directories exist
    # TODO: Have these be inputs

    for fn, y in zip(file_names, y_pred):
        wav_file_name = ntpath.basename(fn.replace(file_extension, 'wav'))
        print "wav_file_name = " + wav_file_name
        original_wav_file = os.path.join(UNTESTED_DIR, wav_file_name)
        print "original_wav_file = " + original_wav_file
        if y == 0:
            out_fn = os.path.join(pass_dir, wav_file_name)
        else:
            out_fn = os.path.join(fail_dir, wav_file_name)
        print "Copying file " + original_wav_file + " to " + out_fn
        shutil.copy2(original_wav_file, out_fn)
def main(argv):
    input_directory = UNTESTED_DIR
    training_file = DEFAULT_TRAINING_FILE
    InputMethod = "FFT"

    try:
        opts, args = getopt.getopt(argv, "hmfi:", ["input="])
    except:
        print "Error gettiong options"
        Usage()
        sys.exit(2)

    for opt, arg in opts:
        if opt == '-h':
            Usage()
            sys.exit()
        elif opt in ('-m'):
            InputMethod="MEL"
        elif opt in ('-f'):
            InputMethod="FFT"
        elif opt in ('-i', '--input'):
            input_directory = arg

    with open('objs.pickle') as f:
        clf = pickle.load(f)

    if InputMethod == "FFT":
        print "Using FFT Training"
        X, file_names = blind_read_fft(input_directory)
        file_extension = 'fft.npy'
    elif InputMethod == "MEL":
        print "Using MFCC Training"
        X, file_names = MakeMFCC.blind_read_ceps(input_directory)
        file_extension = 'ceps.npy'
    else:
        print "No valid input method"
        sys.exit()

    y_pred = clf.predict(X)

    print y_pred

    pass_dir = "/home/colin/Documents/Octave/CatMeow/TestRun/WithCat/"
    fail_dir = "/home/colin/Documents/Octave/CatMeow/TestRun/NoCat/"
    # TODO: Verify output directories exist
    # TODO: Have these be inputs

    for fn, y in zip(file_names, y_pred):
        wav_file_name = ntpath.basename(fn.replace(file_extension, 'wav'))
        print "wav_file_name = " + wav_file_name
        original_wav_file = os.path.join(UNTESTED_DIR, wav_file_name)
        print "original_wav_file = " + original_wav_file
        if y == 0:
            out_fn = os.path.join(pass_dir, wav_file_name)
        else:
            out_fn = os.path.join(fail_dir, wav_file_name)
        print "Copying file " +  original_wav_file + " to " + out_fn
        shutil.copy2(original_wav_file, out_fn)
Example #3
0
# from .user import HiddenMarkovModel as hmm

import AlphaBeta
import Posteriors as post
import HiddenMarkovModel as hmm
import EMTraining as emt
import MakeMFCC
import sounddevice as sd
import scipy.io.wavfile as wv

fs = 16000
sd.default.samplerate = fs
sd.default.channels = 1
window = 25
hamming_window = MakeMFCC.make_window(25, fs)
utterances = 20

odessa_hmm = hmm.HiddenMarkovModel("Odessa", 10)
lights_on_hmm = hmm.HiddenMarkovModel("Lights On", 20)
lights_off_hmm = hmm.HiddenMarkovModel("Lights off", 20)
play_music_hmm = hmm.HiddenMarkovModel("Play Music", 15)
stop_music_hmm = hmm.HiddenMarkovModel("Stop Music", 20)
time_hmm = hmm.HiddenMarkovModel("Time", 20)

odessa_mfccs = []
lights_on_mfccs = []
lights_off_mfccs = []
play_music_mfccs = []
stop_music_mfccs = []
time_mfccs = []
for i in range(1, utterances + 1):
Example #4
0
def main(argv):
    output_file = 'objs.pickle'
    InputMethod = "FFT"
    if argv < 3:
        Usage()
        sys.exit(2)

    try:
        opts, args = getopt.getopt(argv, "hmfp:n:o:", ["positive=","negative=","output="])
    except:
        Usage()
        sys.exit(2)

    for opt, arg in opts:
        if opt == '-h':
            Usage()
            sys.exit()
        elif opt in ('-p', '--positive'):
            positive_training_directory=arg
        elif opt in ('-n', '--negative'):
            negative_training_directory=arg
        elif opt in ('-o', '--output'):
            output_file=arg
        elif opt in ('-m'):
            InputMethod="MEL"
        elif opt in ('-f'):
            InputMethod="FFT"

    print "Using positive training directory ", positive_training_directory
    print "Using negative training directory ", negative_training_directory

    # Read the FFT data
    meow_list = [positive_training_directory, negative_training_directory]
    if InputMethod == "FFT":
        print "Using FFT Training"
        X, y = read_training_ffts(8000, meow_list)
    elif InputMethod == "MEL":
        print "Using MFCC Training"
        X, y = MakeMFCC.read_ceps(meow_list)
    else:
        print "No valid input method"
        sys.exit()

    # Split the data into test and train sets
    X_train, X_test, y_train, y_test = cross_validation.train_test_split(X, y, test_size=0.2, random_state=0)

    # Perform the regression
    clf = LogisticRegression()
    clf.fit(X_train, y_train)

    # Test for an actual prediction
    y_pred = clf.predict(X_test)

    cm = confusion_matrix(y_test, y_pred)
    name = "TestName"
    title = "TestTitle"
    #plot_confusion_matrix(cm, meow_list, name, title)
    print "Confusion matrix of the data"
    print cm

    score = clf.score(X_test, y_test)
    print "Score"
    print score

    # If desired, this can be used to test alternate cross validation sets
    scores = cross_validation.cross_val_score(clf, X, y, cv=5)
    print scores

    print "Writing output to ", output_file
    with open(output_file, 'w') as f:
        pickle.dump(clf, f)