def main():
sample_rate = 48000
channels = 2
N = 4096 * 4
mic = Microphone(sample_rate, channels)
window = np.hanning(N)
sound_speed = 343.2
distance = 0.14
max_tau = distance / sound_speed
def signal_handler(sig, num):
print('Quit')
mic.close()
signal.signal(signal.SIGINT, signal_handler)
for data in mic.read_chunks(N):
buf = np.fromstring(data, dtype='int16')
mono = buf[0::channels].tostring()
if sample_rate != 16000:
mono, _ = audioop.ratecv(mono, 2, 1, sample_rate, 16000, None)
if vad.is_speech(mono):
tau, _ = gcc_phat(buf[0::channels]*window, buf[1::channels]*window, fs=sample_rate, max_tau=max_tau)
theta = math.asin(tau / max_tau) * 180 / math.pi
print('\ntheta: {}'.format(int(theta)))
评论列表
文章目录