stft.analysis(audio) stft.process() # Send audio back to the browser audio[:, 0] = np.sum(stft.synthesis(), axis=1) audio[:, 1] = audio[:, 0] audio[:, 2:] = 0 browserinterface.send_audio(audio) else: # continue estimating covariance matrix bf.estimate_cov(audio) """Interface features""" browserinterface.register_when_new_config(init) browserinterface.register_handle_data(beamform_audio) polar_chart = browserinterface.add_handler(name="Beam pattern", type='base:polar:line', parameters={ 'title': 'Beam pattern', 'series': ['Intensity'], 'numPoints': num_angles }) """START""" browserinterface.start() browserinterface.change_config(buffer_frames=buffer_size, channels=num_channels, rate=sampling_freq, volume=80) browserinterface.loop_callbacks()
doa.locate_sources(X_stft, freq_range=freq_range) # send to browser for visualization # Now map the angles to some function # send to lights if available if led_ring: make_colors(doa.azimuth_recon, doa.alpha_recon.mean(axis=1)) to_send = spatial_spectrum[::-1].tolist() to_send.append(to_send[0]) polar_chart.send_data([{'replace': to_send}]) """Interface features""" browserinterface.register_when_new_config(init) browserinterface.register_handle_data(apply_doa) polar_chart = browserinterface.add_handler(name="Directions", type='base:polar:line', parameters={ 'title': 'Direction', 'series': ['Intensity'], 'numPoints': num_angles }) """START""" browserinterface.start() browserinterface.change_config(channels=num_channels, buffer_frames=buffer_size, rate=sampling_freq, volume=80) browserinterface.loop_callbacks()
# time plot if viz: sig = np.array(audio[:, 0], dtype=np.float32) / 10000 t = np.linspace(frame_num * buffer_size, (frame_num + 1) * buffer_size, buffer_size) / float(sampling_freq) sig = {'x': t[::under].tolist(), 'y': sig[::under].tolist()} time_plot.send_data({'add': [sig]}) light_spectrum(spectrum_before) frame_num += 1 """Interface functions""" browserinterface.register_when_new_config(init) browserinterface.register_handle_data(handle_data) if viz: time_plot = browserinterface.add_handler( "Time domain", 'base:graph:line', { 'xName': 'Duration', 'min': -1, 'max': 1, 'xLimitNb': (sampling_freq / under * num_sec), 'series': [{ 'name': 'Signal', 'color': 'blue' }] }) c_magnitude = browserinterface.add_handler( "Frequency Magnitude", 'base:graph:line', { 'min': 0,
config = json.load(config_file) config_file.close() sampling_freq = config['sampling_frequency'] except: # default when no hw config file is present sampling_freq = 44100 """capture parameters""" buffer_size = 1024; num_channels = 2 """Defining callback""" def example_callback(audio): # check for correct audio shape if audio.shape != (buffer_size, num_channels): print("Did not receive expected audio!") return # play back audio browserinterface.send_audio(audio) browserinterface.register_handle_data(example_callback) """START""" browserinterface.start() browserinterface.change_config(buffer_frames=buffer_size, channels=num_channels, rate=sampling_freq, volume=80) browserinterface.loop_callbacks()