import numpy
import sys
import time
import soundfile
#import wave
import hark


audio, rate = soundfile.read('input.wav', dtype=numpy.float32)

nch = audio.shape[1]
length = 512
advance = 160

frames = numpy.lib.stride_tricks.sliding_window_view(audio, length, axis=0)[::advance, :, :]
#print(frames.shape)

multifft_node = hark.node.MultiFFT()
multifft_out = multifft_node(INPUT=frames)
#print(multifft_out)
#print(multifft_out.OUTPUT.shape)

noisecm = numpy.eye(nch, dtype=numpy.complex64).flatten()
#print(noisecm)
#print(noisecm.shape)
noisecm_bins = numpy.broadcast_to(noisecm, (multifft_out.OUTPUT.shape[0], multifft_out.OUTPUT.shape[1], nch*nch))
#print(noisecm_bins)
#print(noisecm_bins.shape)

localizemusic_node = hark.node.LocalizeMUSIC()
localizemusic_out = localizemusic_node(INPUT=multifft_out.OUTPUT, NOISECM=noisecm_bins, A_MATRIX='tf.zip', MUSIC_ALGORITHM='SEVD', PERIOD=1, WINDOW_TYPE="PAST")
print(localizemusic_out)


