示例#1
0
def task_predict(input_file, input_model):

    # FS = 8000
    m = ModelInterface.load(input_model)
    fs_noise, noise = read_wav("noise.wav")
    m.init_noise(fs_noise, noise)
    
            
    #for f in [input_files]:
    try:
        fs, signal = read_wav(input_file)
        
        print("freq " + str(fs))
        
        signal = m.filter(fs, signal)
        print("len " + str(len(signal)))
        if len(signal) < 50:
            return None
        
        print("AA")
        label = m.predict(fs, signal)
        print input_file, '->', label
        return label
    except:
        print "Unexpected error:", sys.exc_info()[0]            
def task_enroll(input_directory, output_model):
    m = ModelInterface()
    for k in input_directory.strip().split():
        input_dirs = [os.path.expanduser(k)]
    for d in input_directory:
        dirs = itertools.chain(*(glob.glob(d)))
    for d in dirs:
        if os.path.isdir(d):
            dirs = [d]
    files = []
    if len(dirs) == 0:
        print "No valid directory found!"
        sys.exit(1)
    for d in dirs:
        label = os.path.basename(d.rstrip('/'))

        wavs = glob.glob(d + '/*.wav')
        if len(wavs) == 0:
            print "No wav file found in {0}".format(d)
            continue
        print "Label {0} has files {1}".format(label, ','.join(wavs))
        for wav in wavs:
            fs, signal = read_wav(wav)
            m.enroll(label, fs, signal)

    m.train()
    m.dump(output_model)
def task_enroll(input_dirs, output_model):
    m = ModelInterface()
    input_dirs = [os.path.expanduser(k) for k in input_dirs.strip().split()]
    dirs = itertools.chain(*(glob.glob(d) for d in input_dirs))
    dirs = [d for d in dirs if os.path.isdir(d)]
    files = []
    if len(dirs) == 0:
        print ("No valid directory found!")
        sys.exit(1)
    for d in dirs:
        label = os.path.basename(d.rstrip('/'))
        #label =d
        wavs = glob.glob(d + '/*.wav')
        #print(wavs)
        if len(wavs) == 0:
            print ("No wav file found in {0}".format(d))
            continue
        print ("Label {0} has files {1}".format(label, ','.join(wavs)))
        for wav in wavs:
            fs, signal = read_wav(wav)
            label=wav.split('/')[-1].split('_')[0]
            #print(label)
            m.enroll(label, fs, signal)

    m.train()
    m.dump(output_model)
示例#4
0
def task_enroll(input_dirs, output_model):
    m = ModelInterface()
    input_dirs = [os.path.expanduser(k) for k in input_dirs.strip().split()]
    dirs = itertools.chain(*(glob.glob(d) for d in input_dirs))
    dirs = [d for d in dirs if os.path.isdir(d)]
    files = []
    if len(dirs) == 0:
        print "No valid directory found!"
        sys.exit(1)
    training_stats = []
    for d in dirs:
        label = os.path.basename(d.rstrip('/'))

        wavs = glob.glob(d + '/*.wav')
        if len(wavs) == 0:
            print "No wav file found in {0}".format(d)
            continue
        print "Label '{0}' has files: {1}".format(label, ', '.join(wavs))
        total_len = 0
        for wav in wavs:
            fs, signal = read_wav(wav)
            print "   File '{}' has frequency={} and length={}".format(
                wav, fs, len(signal))
            total_len += len(signal)
            m.enroll(label, fs, signal)
        training_stats.append((label, total_len))
    print "--------------------------------------------"
    for label, total_len in training_stats:
        print "Total length of training data for '{}' is {}".format(
            label, total_len)
    print "For best accuracy, please make sure all labels have similar amount of training data!"

    m.train()
    m.dump(output_model)
def task_enroll(input_dirs, output_model):
    m = ModelInterface()
    input_dirs = [os.path.expanduser(k) for k in input_dirs.strip().split()]
    dirs = itertools.chain(*(glob.glob(d) for d in input_dirs))
    dirs = [d for d in dirs if os.path.isdir(d)]
    files = []
    if len(dirs) == 0:
        print "No valid directory found!"
        sys.exit(1)
    training_stats = []
    for d in dirs:
        label = os.path.basename(d.rstrip('/'))

        wavs = glob.glob(d + '/*.wav')
        if len(wavs) == 0:
            print "No wav file found in {0}".format(d)
            continue
        print "Label '{0}' has files: {1}".format(label, ', '.join(wavs))
        total_len = 0
        for wav in wavs:
            fs, signal = read_wav(wav)
            print "   File '{}' has frequency={} and length={}".format(wav, fs, len(signal))
            total_len += len(signal)
            m.enroll(label, fs, signal)
        training_stats.append((label, total_len))
    print "--------------------------------------------"
    for label, total_len in training_stats:
        print "Total length of training data for '{}' is {}".format(label, total_len)
    print "For best accuracy, please make sure all labels have similar amount of training data!"

    m.train()
    m.dump(output_model)
def task_predict(input_files, input_model):
    m = ModelInterface.load(input_model)
    for f in glob.glob(os.path.expanduser(input_files)):
        fs, signal = read_wav(f)
        label = m.predict(fs, signal)
	f = os.path.basename(f)
        print f, '->', label
def task_predict(input_files, input_model):
    m = ModelInterface.load(input_model)
    for f in glob.glob(os.path.expanduser(input_files)):
        wavs = glob.glob(f + '/*.wav')
        for wav in wavs:
            fs, signal = read_wav(wav)
            label = m.predict(fs, signal)
            print (wav.split('/')[-1].split('_')[0]+'|->|'+label)
示例#8
0
def task_predict(input_model):
    m = ModelInterface.load(input_model)
    test_data = range(1, 4)
    for f in test_data:
        wav = "./data/test/" + str(f) + ".wav"
        print wav
        fs, signal = read_wav(wav)
        label = m.predict(fs, signal)
        print f, '->', label
示例#9
0
def task_predict(input_model):
    m = ModelInterface.load(input_model)
    test_data  = range(1,4)
    for f in test_data:
	wav = "./data/test/"+str(f)+".wav"
	print wav 
        fs, signal = read_wav(wav)
        label = m.predict(fs, signal)
        print f, '->', label
示例#10
0
 def reco_files(self):
     fnames = QFileDialog.getOpenFileNames(self, "Select Wav Files", "",
                                           "Files (*.wav)")
     print('reco_files')
     for f in fnames:
         fs, sig = read_wav(f)
         newsig = self.backend.filter(fs, sig)
         label = self.backend.predict(fs, newsig)
         print(f, label)
def task_predict(input_files, input_model, index):
    m = ModelInterface.load(input_model)
    for f in glob.glob(os.path.expanduser(input_files)):
        fs, signal = read_wav(f)
        label = m.predict(fs, signal)
        print f, '->', label
        if label == index:
            sys.exit(1)
        else:
            sys.exit(2)
示例#12
0
 def enroll_file(self):
     fname = QFileDialog.getOpenFileName(self, "Open Wav File", "",
                                         "Files (*.wav)")
     if not fname:
         return
     self.status(fname)
     self.enrollFileName.setText(fname)
     fs, signal = read_wav(fname)
     signal = monophonic(signal)
     self.enrollWav = (fs, signal)
示例#13
0
    def reco_file(self):
        fname = QFileDialog.getOpenFileName(self, "Open Wav File", "",
                                            "Files (*.wav)")
        print('reco_file')
        if not fname:
            return
        self.status(fname)

        fs, signal = read_wav(fname)
        self.reco_do_predict(fs, signal)
def task_predict(input_files, input_model):
    m = ModelInterface.load(input_model)
    for f in glob.glob(os.path.expanduser(input_files)):
        fs, signal = read_wav(f)
        #label = m.predict(fs, signal)
        (label, score) = m.predict_with_score(fs, signal)
        if math.fabs(score) < 0.13:
            print f, '->', label, ' score:', score
        else:
            print f, 'NO SPEAKER RECOGNIZED   (', label, ' score:', score, ')'
示例#15
0
def task_enroll(output_model):
    m = ModelInterface()
    train_data  = range(1,4)
    for i in train_data:
	wav = "./data/train/"+str(i)+".wav"
	print wav
	label = str(i)
        fs, signal = read_wav(wav)
        m.enroll(label, fs, signal)
    m.train()
    m.dump(output_model)
示例#16
0
def task_enroll(output_model):
    m = ModelInterface()
    train_data = range(1, 4)
    for i in train_data:
        wav = "./data/train/" + str(i) + ".wav"
        print wav
        label = str(i)
        fs, signal = read_wav(wav)
        m.enroll(label, fs, signal)
    m.train()
    m.dump(output_model)
示例#17
0
 def handle_speaker_rec_greeting_intent(self, message):
     directory = "/tmp/mycroft_wake_words"
     self.newest = max(glob.iglob(os.path.join(directory, '*.wav')),
                       key=os.path.getctime)
     CWD_PATH = os.path.dirname(__file__)
     input_model = os.path.join(CWD_PATH, "model.out")
     m = ModelInterface.load(input_model)
     input_files = self.newest
     fs, signal = read_wav(input_files)
     label = m.predict(fs, signal)
     self.speak("Yes, I do recognize your voice, %s" % (label))
     print(self.newest)
示例#18
0
def task_predict(input_files, input_model):
    m = ModelInterface.load(input_model)
    ev = []
    for f in glob.glob(os.path.expanduser(input_files)):
        fs, signal = read_wav(f)
        label = m.predict(fs, signal)
        ev.append(label)
        print f, '->', label
    size = len(ev)
    cnt = Counter(ev)
    mostCommon = cnt.most_common(1)[0][1]
    print(mostCommon)

    print(mostCommon * 100 / size)
示例#19
0
def task_predict(input_files, input_current, input_model):
    m = ModelInterface.load(input_model)
    with open('/host{0}/predictions.csv'.format(input_current), 'w') as pred:
        ss = csv.writer(pred, delimiter=',')
        ss.writerow(['score', 'label', 'file'])
        for f in glob.glob(os.path.expanduser(input_files)):
            fs, signal = read_wav(f)
            scores = m.predict_scores(fs, signal)
            y_scores = dict(zip(m.gmmset.y, scores))
            i = 0
            for label, score in sorted(y_scores.items(),
                                       key=lambda o: o[1],
                                       reverse=True):
                if i == 0 and label in [
                        'Albert', 'Casado', 'Pedro', 'Iglesias'
                ]:
                    ss.writerow([score, label, f])
                i += 1
示例#20
0
    def do_enroll(self):
        name = self.Username.text()
        if not name:
            self.warn("Please Input Your Name")
            return


#        self.addUserInfo()
# new_signal = self.backend.filter(*self.enrollWav)
# print ("After removed: {0} -> {1}".format(len(self.enrollWav[1]), len(new_signal)))
# print ("Enroll: {:.4f} seconds".format(float(len(new_signal)) / Main.FS))
# if len(new_signal) == 0:
#     print( "Error! Input is silent! Please enroll again")
#     return

        path = 'suara/' + str(name) + '/'
        wavs = glob.glob(path + '*.wav')
        for wav in wavs:
            fs, signal = read_wav(wav)
            new_signal = self.backend.filter(fs, signal)
            self.backend.enroll(name, fs, new_signal)
def task_enroll(input_dirs, output_model):
    m = ModelInterface()
    input_dirs = [os.path.expanduser(k) for k in input_dirs.strip().split()]
    dirs = itertools.chain(*(glob.glob(d) for d in input_dirs))
    dirs = [d for d in dirs if os.path.isdir(d)]
    files = []
    if len(dirs) == 0:
        print "No valid directory found!"
        sys.exit(1)
    for d in dirs:
        label = os.path.basename(d.rstrip('/'))
        wavs = glob.glob(d + '/*.wav')
        if len(wavs) == 0:
            print "No wav file found in {0}".format(d)
            continue
        print "Label {0} has files {1}".format(label, ','.join(wavs))
        for wav in wavs:
            fs, signal = read_wav(wav)
            m.enroll(label, fs, signal)

    m.train()
    m.dump(output_model)
示例#22
0
        fs, signal = read_wav(input_file)
        
        print("freq " + str(fs))
        
        signal = m.filter(fs, signal)
        print("len " + str(len(signal)))
        if len(signal) < 50:
            return None
        
        print("AA")
        label = m.predict(fs, signal)
        print input_file, '->', label
        return label
    except:
        print "Unexpected error:", sys.exc_info()[0]            
    
m = None

if __name__ == '__main__':
    global args
    args = get_args()

    fs_noise, noise = read_wav("noise.wav")
    m_enroll.init_noise(fs_noise, noise)

    task = args.task
    if task == 'enroll':
        task_enroll(args.input, args.model)
    elif task == 'predict':
        task_predict(args.input, args.model)
示例#23
0
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        uic.loadUi("gui/edytor.ui", self)

        self.last_none_start = 0
        self.last_switch_user = 0
        self.last_enter_none_handler = False
        self.last_user_detected = 'None'

        self.statusBar()

        self.check_result = False

        self.timer = QTimer(self)
        self.timer.timeout.connect(self.timer_callback)

        self.noiseButton.clicked.connect(self.noise_clicked)
        self.recording_noise = False
        self.loadNoise.clicked.connect(self.load_noise)

        self.AddUser.clicked.connect(self.add_user)

        self.enrollRecord.clicked.connect(self.start_enroll_record)
        self.stopEnrollRecord.clicked.connect(self.stop_enroll_record)
        self.enrollFile.clicked.connect(self.enroll_file)
        self.enroll.clicked.connect(self.do_enroll)
        self.startTrain.clicked.connect(self.start_train)
        self.dumpBtn.clicked.connect(self.dump)
        self.loadBtn.clicked.connect(self.load)

        self.recoRecord.clicked.connect(self.start_reco_record)
        self.stopRecoRecord.clicked.connect(self.stop_reco_record)
        #        self.newReco.clicked.connect(self.new_reco)
        self.recoFile.clicked.connect(self.reco_file)
        self.recoInputFiles.clicked.connect(self.reco_files)

        #UI.init
        self.userdata = []
        self.loadUsers()
        self.Userchooser.currentIndexChanged.connect(self.showUserInfo)
        self.ClearInfo.clicked.connect(self.clearUserInfo)
        self.UpdateInfo.clicked.connect(self.updateUserInfo)
        self.UploadImage.clicked.connect(self.upload_avatar)
        #movie test
        self.movie = QMovie(u"gui/image/recording.gif")
        self.movie.start()
        self.movie.stop()
        self.Animation.setMovie(self.movie)
        self.Animation_2.setMovie(self.movie)
        self.Animation_3.setMovie(self.movie)

        self.aladingpic = QPixmap(u"gui/image/a_hello.png")
        self.Alading.setPixmap(self.aladingpic)
        self.Alading_conv.setPixmap(self.aladingpic)

        #default user image setting
        self.avatarname = "gui/image/nouser.jpg"
        self.defaultimage = QPixmap(self.avatarname)
        self.Userimage.setPixmap(self.defaultimage)
        self.recoUserImage.setPixmap(self.defaultimage)
        self.convUserImage.setPixmap(self.defaultimage)
        self.load_avatar('gui/avatar/')

        #quick enroll
        self.show_checkbox()
        self.checkbox.setWidget(self.available_to_enroll)
        self.LoadAll.clicked.connect(self.enroll_checklist)

        #Conversation Mode Variables
        self.conv_record = np.array([], dtype=NPDtype)
        self.time_init = QTimer(self)
        self.current_label = None

        # Graph Window init
        self.graphwindow = GraphWindow()
        self.newname = ""
        self.lastname = ""
        self.Graph_button.clicked.connect(self.graphwindow.show)
        self.convRecord.clicked.connect(self.start_conv_record)
        self.convStop.clicked.connect(self.stop_conv)
        self.generateTranscript.clicked.connect(self.generate_transcript)

        self.backend = ModelInterface()

        # debug
        QShortcut(QKeySequence("Ctrl+P"), self, self.printDebug)

        #init
        try:
            fs, signal = read_wav("bg.wav")
            self.backend.init_noise(fs, signal)
        except:
            pass
示例#24
0
 def load_noise(self):
     fname = QFileDialog.getOpenFileName(self, "Open Data File:", "",
                                         "Wav File  (*.wav)")
     if fname:
         fs, signal = read_wav(fname)
         self.backend.init_noise(fs, signal)