speaker-verification
audio
nemotron
tyger
experimental
File size: 1,121 Bytes
b21cfae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""Residual acoustic echo delay estimation; no recording or guessed delay."""
import numpy as np
from scipy.signal import correlate,correlation_lags


def estimate_echo_delay(mic,reference,sr=16000,max_delay=.45):
    mic=np.asarray(mic,np.float64);reference=np.asarray(reference,np.float64)
    n=min(len(mic),len(reference));mic=mic[:n];reference=reference[:n]
    if n<sr//2 or np.linalg.norm(mic)<1e-5 or np.linalg.norm(reference)<1e-5:
        return {'available':False,'reason':'No measurable reference/echo','confidence':0.}
    corr=correlate(mic,reference,mode='full',method='fft');lags=correlation_lags(n,n)
    keep=(lags>=0)&(lags<=round(max_delay*sr));indexes=np.flatnonzero(keep)
    index=indexes[np.argmax(corr[keep])];lag=int(lags[index])
    a=mic[lag:];b=reference[:n-lag]
    confidence=float(np.dot(a,b)/max(np.linalg.norm(a)*np.linalg.norm(b),1e-10))
    available=confidence>=.45
    return {'available':available,'delay_ms':lag/sr*1000 if available else None,
        'confidence':confidence,'reason':'Measured acoustic residual' if available else 'Echo cancellation/noise makes delay uncertain'}