""" Multiple Implementations of Power Spectral Entropy """ from utils import readMonoWav import matplotlib.pyplot as plt import numpy as np np.set_printoptions(edgeitems=50) # sampRate, sig = readMonoWav('./METU Recordings/hh2_48kHz_Mono_32bitFloat.wav') # sampRate, sig = readMonoWav('./METU Recordings/hh2_breath/hh2_04_00.34.164_270_en.wav') # sampRate, sig = readMonoWav('./METU Recordings/hh2_breath/hh2_09_01.20.741_134_en2.wav') # sampRate, sig = readMonoWav('./METU Recordings/hh2_breath/hh2_09_01.20.741_134_en3_16bit.wav') # sampRate, sig = readMonoWav('./METU Recordings/hh2_breath/hh2_23_03.02.050_149_tr.wav') sampRate, sig = readMonoWav( './METU Recordings/hh2_withEdges/hh2_random001.wav') # print(sig) print(len(sig)) print(sampRate) print('######') readWholeFile = True # set to False for trials only if readWholeFile is False: # take a sample for better visualising, huge chunks crashes in hilbert() sig = sig[sampRate * 0:sampRate * 1] # read only first 1 second # sig = sig / max(sig) # normalization partLen = sampRate // 100 # divide into 10 ms parts
plot_spectrogram(noise_stft_db, title='Noise') if visual: plot_statistics_and_filter(mean_freq_noise, std_freq_noise, noise_thresh, smoothing_filter) if visual: plot_spectrogram(sig_stft_db, title='Signal') if visual: plot_spectrogram(sig_mask, title='Mask applied') if visual: plot_spectrogram(sig_stft_db_masked, title='Masked signal') if visual: plot_spectrogram(recovered_spec, title='Recovered spectrogram') return recovered_signal filepath = './METU Recordings/hh2_bg/hh2_00.09.569-2266_bg.wav' _, bgData = utils.readMonoWav(filepath) filepath = './METU Recordings/hh2_speechAndBreath/hh2_00.17.614-1629_spAndBr.wav' filename = str(os.path.basename(filepath).rsplit('.', 1)[0]) sampRate, speechData = utils.readMonoWav(filepath) sd.play(speechData, sampRate) time.sleep(len(speechData)/sampRate) sd.stop() output = removeNoise(audio_clip=speechData, noise_clip=bgData, verbose=False, visual=False) # output = removeNoise(audio_clip=output, noise_clip=bgData, verbose=False, visual=False) sd.play(output, sampRate) time.sleep(len(output)/sampRate) sd.stop() scipy.io.wavfile.write('outputs/before.wav', sampRate, speechData)
# filepath = './TED Recordings/BillGates_2009/non-voiced/BillGates_2009_00.21.576-326_nv.wav' # filepath = './TED Recordings/BillGates_2009/non-voiced/BillGates_2009_00.24.897-274_nv.wav' # filepath = './TED Recordings/BillGates_2009/non-voiced/BillGates_2009_00.31.490-324_nv.wav' # filepath = './TED Recordings/BillGates_2009/non-voiced/BillGates_2009_00.42.814-516_nv.wav' # filepath = './TED Recordings/BillGates_2009/non-voiced/BillGates_2009_01.18.383-252_nv.wav' # filepath = './TED Recordings/BillGates_2009/non-voiced/BillGates_2009_01.32.227-273_nv.wav' # filepath = './TED Recordings/BillGates_2009/non-voiced/BillGates_2009_01.35.925-301_nv.wav' # filepath = './TED Recordings/BillGates_2009/non-voiced/BillGates_2009_02.59.372-200_nv.wav' # filepath = './TED Recordings/BillGates_2009/non-voiced/BillGates_2009_03.18.690-234_nv.wav' # filepath = './TED Recordings/BillGates_2009/non-voiced/BillGates_2009_03.35.168-364_nv.wav' # filepath = './TED Recordings/BillGates_2009/non-voiced/BillGates_2009_03.47.911-201_nv.wav' # filepath = './TED Recordings/BillGates_2009/non-voiced/BillGates_2009_04.25.179-287_nv.wav' # filepath = './TED Recordings/BillGates_2009/non-voiced/BillGates_2009_04.35.304-254_nv.wav' # filepath = './TED Recordings/BillGates_2009/non-voiced/BillGates_2009_05.04.223-208_nv.wav' sampRate, sig = readMonoWav(filepath) filename = str(os.path.basename(filepath).rsplit('.', 1)[0]) # todo - remove when mid signal tests completed mid = len(sig) // 2 centerFrameLenBySamples = min(int(sampRate * 0.2), len(sig)) # center frame is 200 ms sig = sig[mid - (centerFrameLenBySamples // 2):mid + (centerFrameLenBySamples // 2)] print('FileName:', filename) print('Length:', len(sig), 'samples') print('SamplingRate:', sampRate) print('######') readWholeFile = True # set to False for trials only
import numpy as np import os import utils import sounddevice as sd import time # filepath = './TED Recordings/BillGates_2009/BillGates_2009.wav' # filepath = './TED Recordings/BillGates_2009/bg/BillGates_2009_00.55.000-571_bg.wav' # filepath = './TED Recordings/BillGates_2009/breath/BillGates_2009_00.32.850-525_breath.wav' # filepath = './TED Recordings/BillGates_2009/non-voiced/BillGates_2009_00.21.576-326_nv.wav' # filepath = './TED Recordings/BillGates_2009/speech/BillGates_2009_01.32.610-614_spch.wav' # filepath = './METU Recordings/hh2_bg/hh2_00.09.569-2266_bg.wav' # filepath = './METU Recordings/hh2_breath/hh2_08_01.05.315_246_en.wav' filepath = './METU Recordings/hh2_speech/hh2_01.28.155-896_sp.wav' sampRate, sig = utils.readMonoWav(filepath) filename = str(os.path.basename(filepath).rsplit('.', 1)[0]) sp = np.fft.fft(sig) freq = np.fft.fftfreq(len(sig)) plotlen = int(len(freq) / 2) plt.figure(figsize=(10, 10)) plt.subplot(311) plt.title('Signal: ' + filename) plt.plot(sig) plt.subplot(323) plt.title('FFT Real') plt.plot(freq[:plotlen], sp.real[:plotlen]) plt.subplot(325) plt.title('FFT Imaginary') plt.plot(freq[:plotlen], sp.imag[:plotlen])
""" Code taken from: https://pytftb.readthedocs.io/en/master/nonstationary_signals.html#instantaneous-frequency [2018.08.30]: Tried, works as example """ import numpy as np from tftb.generators import fmlin from tftb.processing import inst_freq, plotifl from utils import readMonoWav import numpy numpy.set_printoptions(edgeitems=50) signal = readMonoWav('./METU Recordings/hh2_48kHz_Mono_32bitFloat.wav')[1] print(signal, len(signal)) print('##########################################################################') # signal, _ = fmlin(256) # time_samples = np.arange(3, 257) ifr = inst_freq(signal)[0] print(ifr, len(ifr)) # todo - atili: try more with whole_speech and hh2 wave files # plotifl(time_samples, ifr)