def getDist(args): sample = args['s_path'] word = args['w_path'] model = args['model'] trans = args['trans'] sample_wav, fs = walkman.load(sample) sample_feat = logfbank(sample_wav, samplerate=fs, lowfreq=64, highfreq=8000, nfilt=40, nfft=2048) sample_feat_trans = featureTransform(sample_feat, trans) word_wav, fs = walkman.load(word) word_feat = logfbank(word_wav, samplerate=fs, lowfreq=64, highfreq=8000, nfilt=40, nfft=2048) word_feat_trans = featureTransform(word_feat, trans) y_sample = model.predict(sample_feat_trans) y_word = model.predict(word_feat_trans) dist, _, _, _ = dtw(makeList(y_word), makeList(y_sample), euclidean) args['dist'] = dist return args
def makeFeature(args): sample = args['path'] trans = args['trans'] sample_wav, fs = walkman.load(sample) sample_feat = logfbank(sample_wav, samplerate=fs, lowfreq=64, highfreq=8000, nfilt=40, nfft=2048) sample_feat_trans = featureTransform(sample_feat, trans) args['feat'] = sample_feat_trans return args
def playFile(truth, sample, model, trans, nnet_dict): t = list() # Starting trial t.append(time.time()) imChange('blank') data, fs = walkman.load(truth['path']) print('Starting trial {0:s}...'.format(truth['path'])) while time.time() - t[0] < 1.5: None # File will play after 1.5 seconds t.append(time.time()) imChange('listen') while time.time() - t[0] < 2: None # Playing file print('Playing') walkman.play(data, fs) while time.time() - t[0] < 3.5: None # Rest time begins t.append(time.time()) print('Rest') imChange('rest') while time.time() - t[0] < 5: None # Speak time print('Speak') imChange('speak') t.append(time.time()) rec, fs = walkman.record_nowait(2.5, 16000, 1) while (time.time() - t[3] < 2.5): None # Recording ends here. Scoring can now begin t.append(time.time()) imChange('triangle') print('Saving') walkman.save(sample['path'], rec, 16000) # Doing VAD first = time.time() # sample['path'] = 'recordings/data2.wav' vad.makeVad(sample['path'], 'temp.wav') sample['path'] = 'temp.wav' # Scoring print('Scoring') sc = score(sample, truth, model, trans, nnet_dict) print(sc) print('Scored in {0:.2f} seconds\n'.format(time.time() - first)) imChange('blank') return t
def score(sample, truth, model, trans): sample_wav, fs = walkman.load(sample) sample_feat = logfbank(sample_wav, samplerate=fs, lowfreq=64, highfreq=8000, nfilt=40) sample_feat_trans = featureTransform(sample_feat, trans) print(np.shape(sample_feat_trans)) x = sample_feat_trans y_sample = model.predict(x, batch_size=512) y_truth = load_truth(truth) dist, _, _, _ = dtw(makeList(y_truth), makeList(y_sample), klDist) return dist
def phase2b(truth, sample): #, model, trans, nnet_dict): dict = config.getPhase2b() t = list() # Starting trial t.append(time.time()) imChange('blank') data, fs = walkman.load(truth['endpath']) print('Starting trial {0:s}...'.format(truth['path'])) while time.time() - t[0] < dict['rest1']: None t.append(time.time()) imChange(truth['image'], path=truth['impath']) print('Image') while time.time() - t[0] < dict['rest1'] + dict['image']: None imChange('blank') time.sleep(dict['rest2']) # Speak time print('Speak') imChange('speak') t.append(time.time()) rec, fs = walkman.record_nowait(2.5, 16000, 1) while (time.time() - t[2] < dict['record']): None # Recording ends here. Scoring can now begin t.append(time.time()) imChange('triangle') print('Saving') walkman.save(sample['path'], rec, 16000) # Playing file imChange('listen') print('Playing') walkman.play(data, fs) while time.time() - t[3] < dict['listen']: None # # Doing VAD # first = time.time() # # sample['path'] = 'recordings/data2.wav' # vad.makeVad(sample['path'], 'temp.wav') # sample['path'] = 'temp.wav' # # Scoring # print('Scoring') # sc = score(sample, truth, model, trans, nnet_dict) # print(sc) # print('Scored in {0:.2f} seconds\n'.format(time.time() - first)) # # Show score image # imScore(sc) # time.sleep(dict['score']) return t
def playFile(truth, subject, sender=None): dictn = {'rest1': 0.5, 'delay': 1.5, 'listen': 1.5} t = list() t.append(time.time()) # Load file data, fs = walkman.load(truth['path']) print('Starting trial {0:s}...'.format(truth['path'])) # Playing file t.append(time.time()) # append time when starts playing print('Playing') walkman.play(data, fs) # Keypress time t.append(time.time()) # append time when stops playing imChange('keypress') print('Keypress...') keypress = 3 # getch() t.append(time.time()) # append time when key is pressed while keypress > 2: keypress = ord(getch()) - ord(str(1)) + 1 print(keypress) # while int(float(keypress)) > 2: # keypress = getch() # print(int(float(keypress))) with open('recordings/{0:s}/keys.csv'.format(subject), 'a+') as file: file.write( '{0:d},{1:s},{2:d},{3:s},{4:s},{5:5.2f},{6:5.3f},{7:5.3f}\n'. format(truth['prompt'], truth['path'], truth['npkr'], str(keypress), truth['trial'], t[1] - t[0], t[2] - t[0], t[3] - t[0])) if keypress == truth['npkr']: imChange('correct') score = 1 else: imChange('wrong') score = 0 time.sleep(1) imChange('blank') # trial ends return score
def phase2a(truth, sample): dict = config.getPhase2a() t = list() # Starting trial t.append(time.time()) imChange('blank') data, fs = walkman.load(truth['endpath']) print('Starting trial {0:s}...'.format(truth['path'])) while time.time() - t[0] < dict['rest1']: None t.append(time.time()) imChange(truth['image'], path=truth['impath']) print('Image') while time.time() - t[0] < dict['rest1'] + dict['image']: None imChange('listen') time.sleep(dict['delay']) # Playing file print('Playing') walkman.play(data, fs) while time.time() - t[0] < dict['rest1'] + dict['image'] + dict['listen']: None # Rest time begins t.append(time.time()) print('Rest') imChange('rest') while time.time( ) - t[0] < dict['rest1'] + dict['image'] + dict['listen'] + dict['rest2']: None # Speak time print('Speak') imChange('speak') t.append(time.time()) rec, fs = walkman.record_nowait(2.5, 16000, 1) while (time.time() - t[3] < dict['record']): None # Recording ends here. Scoring can now begin t.append(time.time()) imChange('triangle') print('Saving') walkman.save(sample['path'], rec, 16000) imChange('blank') return t