Ejemplo n.º 1
0
def test(filename=None):
    import random, os
    import matplotlib.pyplot as plt
    from sys import argv
    #signal, params = read_signal(sound,WINSIZE)
    scenario = None
    if filename != None:
        scene = os.path.basename(filename)[0]
    else:
        filename = random.choice([
            x for x in os.listdir("tmp/") if os.path.splitext(x)[1] == ".flac"
        ])
        scene = filename[0]
        filename = "tmp/" + filename
    print(filename)
    truths = vad.load_truths()
    signal, rate = speech.read_soundfile(filename)
    seconds = float(len(signal)) / rate
    winsize = librosa.time_to_samples(float(WINMS) / 1000, rate)[0]
    window = sp.hanning(winsize)
    ltsd = LTSD(winsize, window, 5)
    res, threshold, nstart, nend = ltsd.compute(signal)
    segments = ltsd.segments(res, threshold)
    #print(float(len(signal))/rate, librosa.core.frames_to_time(len(res), 8000, winsize/2))
    segments = librosa.core.frames_to_time(segments, rate, winsize / 2)
    fig = plt.figure()
    ax = fig.add_subplot(111)
    #ax.plot((signal/np.max(signal))*np.mean(res)+np.mean(res))
    ax.plot(np.linspace(0, seconds, len(res)), res)
    ax.plot([0, seconds], [threshold, threshold])
    vad.plot_segments(truths[scene]['combined'], segments, ax)
    n1 = float(nstart) / rate
    n2 = float(nend) / rate
    ax.vlines([n1, n2], -20, 20)
    plt.show()
Ejemplo n.º 2
0
Archivo: ltsd.py Proyecto: jlep/vad
def test(filename=None):
    import random, os
    import matplotlib.pyplot as plt
    from sys import argv
    #signal, params = read_signal(sound,WINSIZE)
    scenario=None
    if filename != None:
        scene = os.path.basename(filename)[0]
    else:
        filename = random.choice([x for x in os.listdir("tmp/") if os.path.splitext(x)[1] == ".flac"])
        scene = filename[0]
        filename = "tmp/"+filename
    print(filename)
    truths = vad.load_truths()
    signal,rate = speech.read_soundfile(filename)
    seconds = float(len(signal))/rate
    winsize = librosa.time_to_samples(float(WINMS)/1000, rate)[0]
    window = sp.hanning(winsize)
    ltsd = LTSD(winsize,window,5)
    res, threshold,nstart,nend =  ltsd.compute(signal)
    segments = ltsd.segments(res, threshold)
    #print(float(len(signal))/rate, librosa.core.frames_to_time(len(res), 8000, winsize/2))
    segments = librosa.core.frames_to_time(segments, rate, winsize/2)
    fig = plt.figure()
    ax = fig.add_subplot(111)
    #ax.plot((signal/np.max(signal))*np.mean(res)+np.mean(res))
    ax.plot(np.linspace(0,seconds, len(res)), res)
    ax.plot([0, seconds], [threshold, threshold])
    vad.plot_segments(truths[scene]['combined'], segments, ax)
    n1 = float(nstart)/rate
    n2 = float(nend)/rate
    ax.vlines([n1,n2], -20,20)
    plt.show()
Ejemplo n.º 3
0
     print(filename)
 if argv[1] != 'batch':
     sig, rate, frames, fsize, naccs, acvars, ltacs, more = pipeline(
         filename)
     predictions = []
     seconds = float(len(sig)) / rate
 if argv[1] == 'sig':
     plt.plot(
         sigutil.deframesig(frames.T, len(sig), fsize, fsize / 2,
                            signal.hanning))
     plt.show()
 elif argv[1] == 'ac-spec':
     librosa.display.specshow(naccs)
     plt.show()
 elif argv[1] == 'var':
     vad.plot_segments(truths[scene]['combined'], [], plt)
     plt.plot(np.linspace(0, seconds, len(acvars)), acvars)
     plt.show()
 elif argv[1] == 'ltac':
     vad.plot_segments(truths[scene]['combined'], [], plt)
     plt.plot(np.linspace(0, seconds, len(ltacs)), ltacs)
     plt.show()
 elif argv[1] == 'ac-feature':
     vad.plot_segments(truths[scene][scene + 'i'], 'ti', plt)
     vad.plot_segments(truths[scene][scene + 'j'], 'tj', plt)
     alpha = 0.05
     beta = 2
     seconds = float(len(sig)) / rate
     average = moving_average(ltacs)
     lmin, smoothmin = local_min_array(ltacs)
     threshold = alpha * lmin + (1 - alpha) * average + beta
Ejemplo n.º 4
0
Archivo: pitchvad.py Proyecto: jlep/vad
     filename = random.choice([x for x in os.listdir("tmp/") if os.path.splitext(x)[1] == ".flac"])
     scene = filename[0]
     filename = "tmp/"+filename
     print(filename)
 if argv[1] != 'batch':
     sig, rate, frames, fsize, naccs, acvars, ltacs, more = pipeline(filename)
     predictions = []
     seconds = float(len(sig))/rate
 if argv[1] == 'sig':
     plt.plot(sigutil.deframesig(frames.T,len(sig),fsize,fsize/2,signal.hanning))
     plt.show()
 elif argv[1] == 'ac-spec':
     librosa.display.specshow(naccs)
     plt.show()
 elif argv[1] == 'var':
     vad.plot_segments(truths[scene]['combined'], [], plt)
     plt.plot(np.linspace(0,seconds, len(acvars)), acvars)
     plt.show()
 elif argv[1] == 'ltac':
     vad.plot_segments(truths[scene]['combined'], [], plt)
     plt.plot(np.linspace(0,seconds, len(ltacs)), ltacs)
     plt.show()
 elif argv[1] == 'ac-feature':
     vad.plot_segments(truths[scene][scene+'i'], 'ti', plt)
     vad.plot_segments(truths[scene][scene+'j'], 'tj', plt)
     lmin, smoothmin = local_min_array(ltacs)
     lmin = lmin+7
     vad.plot_segments(predict(ltacs, lmin), 'p', plt)
     #plt.plot(np.linspace(0,seconds, len(acvars)), acvars)
     plt.plot(np.linspace(0,seconds, len(ltacs)), ltacs)
     plt.plot(np.linspace(0,seconds, len(lmin)), lmin+2)
Ejemplo n.º 5
0
     filename = random.choice([x for x in os.listdir("tmp/") if os.path.splitext(x)[1] == ".flac"])
     scene = filename[0]
     filename = "tmp/"+filename
     truths = vad.load_truths()
     print(filename)
     sig, rate, frames, fsize, nacc, acvars, ltacs = pipeline(filename)
     seconds = float(len(sig))/rate
 if argv >= 2 and argv[1] is not 'batch':
     if argv[1] == 'sig':
         plt.plot(sigutil.deframesig(frames.T,len(sig),fsize,fsize/2,signal.hanning))
         plt.show()
     if argv[1] == 'ac':
         librosa.display.specshow(nacc)
         plt.show()
     elif argv[1] == 'var':
         vad.plot_segments(truths[scene][scene+'i'], 'ti', plt)
         vad.plot_segments(truths[scene][scene+'j'], 'tj', plt)
         plt.plot(np.linspace(0,seconds, len(acvars)), acvars)
         plt.show()
     elif argv[1] == 'ltac':
         vad.plot_segments(truths[scene][scene+'i'], 'ti', plt)
         vad.plot_segments(truths[scene][scene+'j'], 'tj', plt)
         plt.plot(np.linspace(0,seconds, len(ltacs)), ltacs)
         plt.show()
     elif argv[1] == 'test':
         print(len(ltacs))
         segments,thresholds = predict(ltacs)
         vad.plot_segments(truths[scene][scene+'i'], 'ti', plt)
         vad.plot_segments(truths[scene][scene+'j'], 'tj', plt)
         vad.plot_segments(segments, 'p', plt)
         plt.plot(np.linspace(0,seconds, len(ltacs)), ltacs)
Ejemplo n.º 6
0
                res_name = argv[3]+"/sosens_"+os.path.basename(os.path.splitext(f)[0])+".txt"
                frame_ms = 64
		tasks.append([filename, res_name, frame_ms])
                #predictions = predict(rms, H, rms_t, H_t)
                #predictions = librosa.core.frames_to_time(predictions, rate, fsize).tolist()
                #write_results(predictions, res_name, seconds)
        r = pool.map_async(compute_vad, tasks)
        r.wait()
	pool.terminate()
	pool.join()
    else:
        print(filename)
        frame_ms = 64
        sig, rate, frames, fsize, rms, H, p = pipeline(filename, frame_ms)
        seconds = float(len(sig))/rate
        vad.plot_segments(truths[scene][scene+'i'], 'ti', plt)
        vad.plot_segments(truths[scene][scene+'j'], 'tj', plt)
        rms_t, rms_t_smooth = local_min_array(rms)
        H_a = average(H, 20)
        H_min, H_min_smooth = local_min_array(H, 30)
        rms_t += 0.012
        H_t = H_min+(H_a*0.2)
        predictions = predict(rms, H, rms_t, H_t)
        predictions = librosa.core.frames_to_time(predictions, rate, fsize).tolist()
        vad.plot_segments(predictions, 'p', plt)
        plt.plot(np.linspace(0,seconds, len(rms)), rms)
        plt.plot(np.linspace(0,seconds, len(H)), H)
        plt.plot(np.linspace(0,seconds, len(rms_t)), rms_t)
        plt.plot(np.linspace(0,seconds, len(H_t)), H_t)
        plt.show()
Ejemplo n.º 7
0
     filename = "tmp/" + filename
     truths = vad.load_truths()
     print(filename)
     sig, rate, frames, fsize, nacc, acvars, ltacs = pipeline(filename)
     seconds = float(len(sig)) / rate
 if argv >= 2 and argv[1] is not 'batch':
     if argv[1] == 'sig':
         plt.plot(
             sigutil.deframesig(frames.T, len(sig), fsize, fsize / 2,
                                signal.hanning))
         plt.show()
     if argv[1] == 'ac':
         librosa.display.specshow(nacc)
         plt.show()
     elif argv[1] == 'var':
         vad.plot_segments(truths[scene][scene + 'i'], 'ti', plt)
         vad.plot_segments(truths[scene][scene + 'j'], 'tj', plt)
         plt.plot(np.linspace(0, seconds, len(acvars)), acvars)
         plt.show()
     elif argv[1] == 'ltac':
         vad.plot_segments(truths[scene][scene + 'i'], 'ti', plt)
         vad.plot_segments(truths[scene][scene + 'j'], 'tj', plt)
         plt.plot(np.linspace(0, seconds, len(ltacs)), ltacs)
         plt.show()
     elif argv[1] == 'test':
         print(len(ltacs))
         segments, thresholds = predict(ltacs)
         vad.plot_segments(truths[scene][scene + 'i'], 'ti', plt)
         vad.plot_segments(truths[scene][scene + 'j'], 'tj', plt)
         vad.plot_segments(segments, 'p', plt)
         plt.plot(np.linspace(0, seconds, len(ltacs)), ltacs)