Exemplo n.º 1
0
def loop():
    global last_click
    global values
    print 'loop'
    chunk = stream.read(CHUNK)
    chunk = segment.decode(chunk, 1)[:,0]/32678.
    smoothed = segment.smooth(chunk, 4)
    clicks, last_click = segment.get_clicks(smoothed, threshold, 10000, last_click=last_click)
    if last_click is not None:
        last_click -= CHUNK
    taps = segment.chop(chunk, clicks, afterlength=1300, prelength=50)
    if taps.shape[0]==0:
        print ' ... '
    for tap in taps:
        ft = transform.sndFeature(tap)            
        letter = tap_recog.transform(ft)
        proba = tap_recog.predict_proba(ft)[0]
        i = np.argmax(proba)
        dvalues = np.zeros(3)
        dvalues[i]=1
        values += power * dvalues
        print '{} --> {}'.format(proba, letter)
    values *= shrinkage
    
    canvas.delete("all")
    nvalues = (base_size*values).astype(np.int32)
    canvas.create_text(base*1, 500, text='Gab', font=("Arial",nvalues[0]), fill='blue')
    canvas.create_text(base*2, 200, text='San', font=("Arial",nvalues[1]), fill='green')
    canvas.create_text(base*3, 500, text='Suc', font=("Arial",nvalues[2]), fill='red')
    master.after(10, loop)  
Exemplo n.º 2
0
def loop():
    global last_click
    global values
    print 'loop'
    chunk = stream.read(CHUNK)
    chunk = segment.decode(chunk, 1)[:, 0] / 32678.
    smoothed = segment.smooth(chunk, 4)
    clicks, last_click = segment.get_clicks(smoothed,
                                            threshold,
                                            10000,
                                            last_click=last_click)
    if last_click is not None:
        last_click -= CHUNK
    taps = segment.chop(chunk, clicks, afterlength=1300, prelength=50)
    if taps.shape[0] == 0:
        print ' ... '
    for tap in taps:
        ft = transform.sndFeature(tap)
        letter = tap_recog.transform(ft)
        proba = tap_recog.predict_proba(ft)[0]
        i = np.argmax(proba)
        dvalues = np.zeros(3)
        dvalues[i] = 1
        values += power * dvalues
        print '{} --> {}'.format(proba, letter)
    values *= shrinkage

    canvas.delete("all")
    nvalues = (base_size * values).astype(np.int32)
    canvas.create_text(base * 1,
                       500,
                       text='Gab',
                       font=("Arial", nvalues[0]),
                       fill='blue')
    canvas.create_text(base * 2,
                       200,
                       text='San',
                       font=("Arial", nvalues[1]),
                       fill='green')
    canvas.create_text(base * 3,
                       500,
                       text='Suc',
                       font=("Arial", nvalues[2]),
                       fill='red')
    master.after(10, loop)
Exemplo n.º 3
0
threshold = 0.4
text=[]
try: 
    last_click = None
    while True:
        print 'loop'
        if realtime:
            chunk = stream.read(CHUNK)
            chunk = segment.decode(chunk, 1)[:,0]/32678.
        elif over:
            break
        smoothed = segment.smooth(chunk, 4)
        clicks, last_click = segment.get_clicks(smoothed, threshold, 10000, last_click=last_click)
        if last_click is not None:
            last_click -= CHUNK
        taps = segment.chop(chunk, clicks, afterlength=1300, prelength=50)
        #print len(taps)
        if taps.shape[0]==0:
            print ' ... '
        for tap in taps:
            ft = transform.sndFeature(tap)            
            letter = tap_recog.transform(ft)
            proba = tap_recog.predict_proba(ft)
            text.append(letter)
            print '{} --> {}'.format(proba, letter)
        over = True
except KeyboardInterrupt:
    print "finished recording"
finally: 
    stream.stop_stream()
    stream.close()