2016-12-08 4 views
2

수천 개의 녹화가 있습니다. 제작중인 앱에 사용하고 있습니다. 최근 녹음 중 일부에 이상한 반향이 있음을 알았습니다.사운드 파일에 에코가 있는지 확인합니다.

녹음은 .wav 형식이며 파이썬을 사용하여 처리합니다.

pepole이 에코를 취소하려고하는 많은 질문을 보았지만 그 파일을 찾아야합니다.

해당 파일을 찾는 데 사용할 수있는 도구 또는 코드가 있습니까 (에코를 취소 할 필요 없음).

에코를 취소하는 코드를 작성하고 파일 에코가 발생했을 때이를 이해하는 데 도움이되는지 확인했지만 작동하지 않았습니다. 결과 파일은 잡음 이었기 때문에 알고리즘이 잘못되었다고 생각합니다.

def nlms(u, d, M, step, eps=0.001, leak=0, initCoeffs=None, N=None, returnCoeffs=False): 
    # Initialization 
    if N is None: 
    N = len(u)-M+1 
    if initCoeffs is None: 
    initCoeffs = np.zeros(M) 
    y = np.zeros(N) # Filter output 
    e = np.zeros(N) # Error signal 
    w = initCoeffs # Initial filter coeffs 
    leakstep = (1 - step*leak) 
    if returnCoeffs: 
     W = np.zeros((N, M)) # Matrix to hold coeffs for each iteration 

    # Perform filtering 
    for n in xrange(N): 
     x = np.flipud(u[n:n+M]) # Slice to get view of M latest datapoints 
     y[n] = np.dot(x, w) 
     e[n] = d[n+M-1] - y[n] 

     normFactor = 1./(np.dot(x, x) + eps) 
     w = leakstep * w + step * normFactor * x * e[n] 
     y[n] = np.dot(x, w) 
     if returnCoeffs: 
      W[n] = w 

    if returnCoeffs: 
     w = W 

    return y, e, w 



def CancelEcho(file_path): 
    np.seterr(all='raise') 

    audio_file = wave.open(file_path, 'r') 
    audio_params = audio_file.getparams() 
    new_frames = [] 
    u = 'a' 
    while u != " ": 
     data = audio_file.readframes(1024) 
     u = np.fromstring(data, np.int16) 
     u = np.float64(u) 
     if len(u) ==0: 
     break 
     # Generate received signal d(n) using randomly chosen coefficients 
     coeffs = np.concatenate(([0.8], np.zeros(8), [-0.7], np.zeros(9), 
           [0.5], np.zeros(11), [-0.3], np.zeros(3), 
           [0.1], np.zeros(20), [-0.05])) 

     coeffs.dtype = np.int16 
     d = np.convolve(u, coeffs) 

     # Add background noise 
     v = np.random.randn(len(d)) * np.sqrt(5000) 
     d += v 

     # Apply adaptive filter 
     M = 100 # Number of filter taps in adaptive filter 
     step = 0.1 # Step size 
     y, e, w = nlms(u, d, M, step, returnCoeffs=True) 

     new_frames.extend(y) 

    audio_file.close() 
    audio_file = wave.open(out_file, 'w') 
    audio_file.setparams(audio_params) 
    audio_file.writeframes(y.astype(np.int16).tostring()) 
    audio_file.close() 
+0

음이 취소 에코는 파일에 에코 노이즈를 생성 한 다음 제거합니다. – cjds

+0

"하지만 작동하지 않았습니다."- 작동하지 않는 코드, 에코를 취소하는 코드 또는 코드를 작성하여 얻은 바가 있다는 것을 이해하는 데 도움이되는 사항? –

답변

0

아이디어는 파일의 부분을 다음 파일의 나머지 부분을 통해 그것을 이동하고 하나 개의 신호가 다른로 전환하는 것이 걸릴 것 배율을 발견하는 것입니다.

코드 속성은 : https://docs.python.org/2/library/audioop.html

이 작동 할 수 있습니다

def echocancel(outputdata, inputdata): 
    pos = audioop.findmax(outputdata, 800) # one tenth second 
    out_test = outputdata[pos*2:] 
    in_test = inputdata[pos*2:] 
    ipos, factor = audioop.findfit(in_test, out_test) 
    # Optional (for better cancellation): 
    # factor = audioop.findfactor(in_test[ipos*2:ipos*2+len(out_test)], 
    #    out_test) 
    return factor 

계수가 1.0에 가까울수록, 더 많은 가능성이 ... 할 수있는 거 코드 에코

+0

출력/입력 데이터는 어떻게 만듭니 까? – user844541

관련 문제