示例#1
0
def estimate(valid, v_W, c_W, valid_v, valid_c, r, score_inf=None):
    fn  = 'est/0' + r
    W = np.append(v_W, c_W, axis=1)
    H = NMF.extractActivation(valid, W)
    t_num = v_W.shape[1]
    
    if score_inf is not None :
        print('apply score inf')
        H = NMF.cons_Activation(score_inf, H) 

    v_H = H[0:t_num]
    c_H = H[t_num:H.shape[0]]
   
    o_v, o_c = reconstruct(valid, v_W, v_H, c_W, c_H)
    
    librosa.output.write_wav(fn + '_vio_est.wav', o_v, 44100)
    librosa.output.write_wav(fn + '_cla_est.wav', o_c, 44100)
    
    valid_v = valid_v[0:220160]
    valid_c = valid_c[0:220160]
    
    sdr, sir, sar, perm = basic.evalBSS(np.array([valid_v, valid_c]), np.array([o_v, o_c]))
   
    print(sdr)
    print(sir)
    print(sar)
def R2(valid, W):
    H = NMF.extractActivation(valid, W)
    r = np.dot(W, H)
    o = librosa.core.istft(r, win_length=NMF.d_w, hop_length=NMF.d_h)
    """showDicSpectr(W)
    showActSpectr(H)
    showReconSpectr(r)"""
    librosa.output.write_wav('01_cla.wav', o, 44100)
def R4(v_W, c_W):
    path = '../audio/test/'
    fn = '../pred/'
    test_clips = u.readClips(path)
    W = np.append(v_W, c_W, axis=1)
  
    for i in range(0, len(test_clips)):
        p = fn + '0' + str(i + 6)
        H = NMF.extractActivation(test_clips[i][0], W)
        v_H = H[0:t_num]
        c_H = H[t_num:H.shape[0]]
        o_v, o_c = est.reconstruct(test_clips[i][0], v_W, v_H, c_W, c_H)
        librosa.output.write_wav(p + '_vio_est.wav', o_v, 44100)
        librosa.output.write_wav(p + '_cla_est.wav', o_c, 44100)