示例#1
0
def main():
    filename = sys.argv[1]
    wave_reader = wave.open(filename)
    voice_classifier,keyboard_classifier = pickle.load(open("classifier.pickle"))
    try:
        wave_reader.setpos(int(current_end_of_file(filename)*48000)+1)
    except:
        print "file done"
        return
    print "bees"
    print current_time(wave_reader)
    start_time, end_time = find_endpoints(wave_reader)
    print "bees2"
    while start_time < current_end_of_file(filename):
        assert False
        start_time, end_time = find_endpoints(wave_reader)
    print start_time
    for i in range(0,50):
        print start_time, end_time
        if numpy.sum(vadutils.read_region(filename, start_time, end_time-start_time)) == 0:
            print "silence detected!"
            voice = False
            keyboard = False
        else:
            play_region(filename, start_time, end_time)
            vectors = []
            vadutils.load_vectors(filename, vectors,start_time, end_time)
            print numpy.average(voice_classifier.predict_proba(vectors), axis=0)
            voice = raw_input("was that voice? [y/n] ") == "y"
            keyboard = raw_input("was that keyboard? [y/n] ") == "y"

        insert_sample(filename, start_time, end_time, voice, keyboard)
        start_time, end_time = find_endpoints(wave_reader)
        if abs(current_time(wave_reader)-sample_end_time(wave_reader)) <= 0.5:
            break
示例#2
0
def main():
    filename = sys.argv[1]
    wave_reader = wave.open(filename)
    voice_classifier, keyboard_classifier = pickle.load(
        open("classifier.pickle"))
    try:
        wave_reader.setpos(int(current_end_of_file(filename) * 48000) + 1)
    except:
        print "file done"
        return
    print "bees"
    print current_time(wave_reader)
    start_time, end_time = find_endpoints(wave_reader)
    print "bees2"
    while start_time < current_end_of_file(filename):
        assert False
        start_time, end_time = find_endpoints(wave_reader)
    print start_time
    for i in range(0, 50):
        print start_time, end_time
        if numpy.sum(
                vadutils.read_region(filename, start_time,
                                     end_time - start_time)) == 0:
            print "silence detected!"
            voice = False
            keyboard = False
        else:
            play_region(filename, start_time, end_time)
            vectors = []
            vadutils.load_vectors(filename, vectors, start_time, end_time)
            print numpy.average(voice_classifier.predict_proba(vectors),
                                axis=0)
            voice = raw_input("was that voice? [y/n] ") == "y"
            keyboard = raw_input("was that keyboard? [y/n] ") == "y"

        insert_sample(filename, start_time, end_time, voice, keyboard)
        start_time, end_time = find_endpoints(wave_reader)
        if abs(current_time(wave_reader) -
               sample_end_time(wave_reader)) <= 0.5:
            break
import vadutils
from sklearn.ensemble import RandomForestClassifier
import numpy
import cPickle as pickle
import wave

if __name__ == "__main__":
    s = vadutils.load_vectors("sample.wav", 0, 8)
    c = pickle.loads(open("final_classifier").read())
    c.verbose = 3

    headings = sorted(s[0].headings())
    vectors = numpy.array([x.to_vector(headings) for x in s])
    predictions = c.predict(vectors)

    f = wave.open("sample.wav")

    writer = wave.open("sample-filtered.wav", "w")

    writer.setnchannels(1)
    writer.setsampwidth(f.getsampwidth())
    writer.setframerate(f.getframerate())

    for pred in predictions:
        x = f.readframes(768)
        if pred == 1:
            writer.writeframes(x)
        else:
            writer.writeframes("".join(["\x00" for value in x]))

    writer.close()
import vadutils
from sklearn.ensemble import RandomForestClassifier
import numpy
import cPickle as pickle
import wave

if __name__ == "__main__":
    s = vadutils.load_vectors("sample.wav",0,8)
    c = pickle.loads(open("final_classifier").read())
    c.verbose = 3

    headings = sorted(s[0].headings())
    vectors = numpy.array([x.to_vector(headings) for x in s])
    predictions = c.predict(vectors)



    f = wave.open("sample.wav")

    writer = wave.open("sample-filtered.wav", "w")

    writer.setnchannels(1)
    writer.setsampwidth(f.getsampwidth())
    writer.setframerate(f.getframerate())


    for pred in predictions:
        x = f.readframes(768)
        if pred == 1:
            writer.writeframes(x)
        else: