수천 개의 녹화가 있습니다. 제작중인 앱에 사용하고 있습니다. 최근 녹음 중 일부에 이상한 반향이 있음을 알았습니다.사운드 파일에 에코가 있는지 확인합니다.
녹음은 .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()
음이 취소 에코는 파일에 에코 노이즈를 생성 한 다음 제거합니다. – cjds
"하지만 작동하지 않았습니다."- 작동하지 않는 코드, 에코를 취소하는 코드 또는 코드를 작성하여 얻은 바가 있다는 것을 이해하는 데 도움이되는 사항? –