Example #1
0
def files_to_data(files, file_labels, threshold):
    uniqueLabels = np.unique(file_labels)
    labelString2Int = {s:i for i,s in enumerate(uniqueLabels)}
    labels=[]
    data=[]
    for file,file_label in zip(files,file_labels):
        wav = segment.wav_to_np(file)[:,0]/32768. # left CH
        chunks = segment.chop_all(wav, threshold, afterlength=700, prelength=0)
        chunks = map(transform.sndFeature, chunks)
        data += list(chunks)
        labels += [labelString2Int[file_label],]*len(chunks)
        print 'Chunked {} examples for {}'.format(len(chunks),file)
    X = np.array(data)
    y = np.array(labels)
    return X,y,uniqueLabels
Example #2
0
from sklearn.externals import joblib
import sys

tap_recog = joblib.load('forest_recog.bin')

p = pyaudio.PyAudio()
realtime = True
over=False

if realtime:
    stream = p.open(format=p.get_format_from_width(2),
                    channels=1,
                    rate=44100,
                    input=True)
else:
    chunk = segment.wav_to_np('snaps/gss.wav')[:,0]/32768.   
   # segment.play_wav(chunk)

frames = []
CHUNK = 10000
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