示例#1
0
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
示例#2
0
def takeBreak(sec):
    t = time.time()
    prev = t
    index = 1
    while index <= 5:
        imChange('break/{0:d}'.format(6 - index))
        while time.time() - t < index * sec / 5:
            if time.time() - prev > 1:
                print(sec2clk((int)(t + 300 - time.time())), end='\r')
                prev = time.time()
            None
        index = index + 1
    imChange('break/0')
    walkman.play('playback/beep.wav')
示例#3
0
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
示例#4
0
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
示例#5
0
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
示例#6
0
def takeBreak(sec, progress):
    game = Game()
    t = time.time()
    prev = t
    index = 1
    isBreak = True
    while time.time() - t < sec and isBreak:
        timeNow = sec2clk((int)(t + sec - time.time()))
        game.display(timeNow)
        isBreak = game.listen()
        imBreak(t + sec - time.time(), sec, progress)
        time.sleep(1)
    game.close()
    imBreak(0, 1, progress)
    walkman.play('playback/beep.wav')


# def takeBreak(sec):
#     game = Game()
#     t = time.time()
#     prev = t
#     index = 1
#     isBreak = True
#     while index <=5:
#         imChange('break/{0:d}'.format(6 - index))
#         while time.time() - t < index * sec / 5 and isBreak:
#             if time.time() - prev > 1:
#                 # print(sec2clk((int)(t + sec - time.time())), end='\r')
#                 timeNow = sec2clk((int)(t + sec - time.time()))
#                 game.display(timeNow)
#                 prev = time.time()
#             isBreak = game.listen()
#         index = index + 1
#     game.close()
#     imChange('break/0')
#     walkman.play('playback/beep.wav')