def expe_2(): sig_1_path = '/sons/voxforge/main/Learn/cmu_us_slt_arctic/wav/arctic_a0372.wav' sig_2_path = '/sons/voxforge/main/Learn/cmu_us_rms_arctic/wav/arctic_a0372.wav' i = 0 for sig_path in [sig_1_path, sig_2_path]: synth_sig = Signal(sig_path, normalize=True, mono=True) #synth_sig.crop(0.1*synth_sig.fs, 3.5*synth_sig.fs) #synth_sig.resample(32000) plt.figure(figsize=(10, 10)) plt.subplot(211) plt.plot( np.arange(.0, synth_sig.length) / float(synth_sig.fs), synth_sig.data) plt.xticks([]) plt.ylim([-1, 1]) plt.grid() plt.subplot(212) synth_sig.spectrogram(1024, 64, order=0.5, log=False, cmap=cm.hot, cbar=False) plt.savefig(op.join(figure_output_path, 'voice_%d_spectro.pdf' % i)) synth_sig.write(op.join(audio_output_path, 'voice_%d_spectro.wav' % i)) i += 1
def recons_save_fig_audio(magspec, target_name, n_max_frames, fs=22050, format=(8, 3), nb_gl_iter=30): init_vec = np.random.randn(128 * n_max_frames) x_recon = transforms.gl_recons(magspec[:, :n_max_frames], init_vec, nb_gl_iter, 512, 128, display=False) rec_sig = Signal(x_recon, fs, normalize=True) rec_sig.write(os.path.join(output_audio_path, '%s.wav' % target_name)) plt.figure(figsize=format) rec_sig.spectrogram(512, 128, order=1, log=True, cmap=cm.jet, cbar=False) plt.savefig(os.path.join(output_fig_path, '%s.png' % target_name))
def expe_1(): synth_sig = Signal(audio_test_file, normalize=True, mono=True) synth_sig.crop(0.1 * synth_sig.fs, 3.5 * synth_sig.fs) #synth_sig.resample(32000) plt.figure(figsize=(10, 5)) plt.subplot(211) plt.plot( np.arange(.0, synth_sig.length) / float(synth_sig.fs), synth_sig.data) plt.xticks([]) plt.ylim([-1, 1]) plt.grid() plt.subplot(212) synth_sig.spectrogram(1024, 64, order=0.25, log=False, cmap=cm.hot, cbar=False) plt.savefig(op.join(figure_output_path, 'glocs_spectro.pdf')) plt.show()
sk = STFTPeaksSketch(**{'scale': 2048, 'step': 512}) orig_sig = Signal(audio_test_file, normalize=True, mono=True) noisy_sig = Signal(orig_sig.data + 0.2 * np.random.randn(orig_sig.length), orig_sig.fs, normalize=True, mono=True) sk.recompute(orig_sig) sk.sparsify(20) plt.figure(figsize=(10, 6)) plt.subplot(221) orig_sig.spectrogram(512, 128, order=2, log=True, ax=plt.gca(), cmap=cm.bone_r, cbar=False) plt.subplot(222) noisy_sig.spectrogram(512, 128, order=2, log=True, ax=plt.gca(), cmap=cm.bone_r, cbar=False) plt.subplot(223) fgpthandle._build_pairs(sk.fgpt(), sk.params, display=True, ax=plt.gca()) plt.gca().invert_yaxis() plt.yticks([])
output_fig_path = '/home/manu/Documents/Articles/ISMIR2013/ListeningMSD/Figures/' colormap = cm.jet format = (8,3) # also load the Dan Ellis's synthesized version # The Piano cross-synthesis and the Viterbi smoothed Musaicing? # resynthesize using the first N frames n_max_frames = 900 nb_gl_iter = 30 init_vec = np.random.randn(128*n_max_frames) x_recon_median = transforms.gl_recons(median_magspec[:,:n_max_frames], init_vec, nb_gl_iter, 512, 128, display=False) sig_median = Signal(x_recon_median, 22050,normalize=True) sig_median.write(os.path.join(output_audio_path, '%s_add_median.wav'%t_name)) plt.figure(figsize=format) sig_median.spectrogram(512, 128, order=1, log=True, cmap=colormap, cbar=False) plt.savefig(os.path.join(output_fig_path, '%s_add_median.png'%t_name)) init_vec = np.random.randn(128*n_max_frames) x_recon_orig = transforms.gl_recons(orig_spec[:,:n_max_frames], init_vec, nb_gl_iter, 512, 128, display=False) sig_orig= Signal(x_recon_orig, 22050,normalize=True) sig_orig.write(os.path.join(output_audio_path, '%s_original.wav'%t_name)) plt.figure(figsize=format) sig_orig.spectrogram(512, 128, order=1, log=True, cmap=colormap, cbar=False) plt.savefig(os.path.join(output_fig_path, '%s_original.png'%t_name)) init_vec = np.random.randn(128*n_max_frames) x_recon_max = transforms.gl_recons(max_magspec[:,:n_max_frames], init_vec, nb_gl_iter, 512, 128, display=False) sig_max= Signal(x_recon_max, 22050,normalize=True)
''' doc.pyplots.Spectro_example - Created on Apr 23, 2013 @author: M. Moussallam ''' import os.path as op from PyMP import Signal, approx import matplotlib.pyplot as plt abPath = op.abspath('../../data/') sig = Signal(op.join(abPath, 'glocs.wav'), normalize=True, mono=True) import matplotlib.cm as cm plt.figure() sig.spectrogram(1024, 128, order=2, log=True, cmap=cm.hot, cbar=True) plt.show()
print t_path + '/' + t_name + '.au' from feat_invert.transforms import get_audio orig, fs = get_audio(t_path + '/' + t_name + '.au', 0, np.sum(t_seg_duration[:nb_max_seg]) + marge, targetfs=22050) #orig = Signal(t_path + t_name + '.au', normalize=True) print "Working on %s duration of %2.2f" % ( t_name, np.sum(t_seg_duration[:nb_max_seg])) orig_spec = np.abs(stft.stft(orig, 512, 128)[0, :, :]) sig_ellis = Signal('%sellis_resynth%s.wav' % (output_audio_path, t_name), normalize=True) #sig_ellis.crop(0,orig_spec.shape[1]*128 + 512-128) plt.figure(figsize=(8, 3)) sig_ellis.spectrogram(512, 128, order=1, log=True, cmap=cm.jet, cbar=False) plt.savefig(os.path.join(output_fig_path, '%s_ellis.png' % t_name)) feat_idxs = get_feat_idx_from_name(feat_combs[0]) # limit the size of the l_features vector: l_feats = l_feats_all[:M, feat_idxs] # and the t_feats vector t_feats = t_feats_all[:nb_max_seg, feat_idxs] # standardizing the features for f in range(l_feats.shape[1]): mu = np.mean(l_feats[:, f]) sigma = np.std(l_feats[:, f]) # print "Mu %2.4f Sigma: %2.4f"%(mu,sigma) l_feats[:, f] = (l_feats[:, f] - mu) / sigma t_feats[:, f] = (t_feats[:, f] - mu) / sigma
import matplotlib.colors as cc import matplotlib.cm as cm from PyMP import Signal import stft from scipy.signal import lfilter, hann plt.switch_backend('Agg') audio_test_file = '/home/manu/workspace/recup_angelique/Sketches/NLS Toolbox/Hand-made Toolbox/forAngelique/61_sadness.wav' audio_test_file = '/sons/jingles/panzani.wav' figure_output_path = '/home/manu/workspace/audio-sketch/src/reporting/figures/' sig = Signal(audio_test_file, mono=True, normalize=True) sig.downsample(16000) scale = 512 step = 32 sig.spectrogram(scale, step, order=1, log=False, cmap=cm.coolwarm) def plot_spectrogram(sig_stft, scale=512, step=128): plt.figure() plt.imshow(20 * np.log10(np.abs(sig_stft[0, :, :])), aspect='auto', origin='lower', interpolation='nearest', cmap=cm.copper_r) x_tick_vec = (np.linspace(0, sig_stft.shape[2], 10)).astype(int) x_label_vec = (x_tick_vec * float(step)) / float(sig.fs) y_tick_vec = (np.linspace(0, sig_stft.shape[1], 6)).astype(int) y_label_vec = (y_tick_vec / float(scale)) * float(sig.fs)
name="unnamed") plt.figure() plt.plot(x_recon_viterbi - x_recon_1nn) plt.show() # is the reconstructed spectrogram relevantly statistically distributed ? import matplotlib.cm as cm from scipy.ndimage import median_filter plt.figure() plt.subplot(311) plt.imshow(np.log10(median_filter(Y_hat.T, [3, 1])), origin='lower') plt.subplot(312) plt.imshow(np.log10(Y_hat_viterbi.T), origin='lower') plt.plot([i * 2 for i in best_path], 'k') plt.subplot(313) orig_sig.spectrogram(win_size, 128, order=1, log=True, cmap=cm.jet, cbar=False) plt.show() filt_sizes = [[1, 1], [3, 1], [5, 1], [10, 1], [1, 3], [1, 5], [1, 10], [3, 3], [5, 5], [10, 10]] x_recons = [] for filt_size in filt_sizes: guess_yhat = median_filter(Y_hat_viterbi, filt_size) init_vec = np.random.randn(128 * guess_yhat.shape[0]) x_recons.append( transforms.gl_recons(guess_yhat.T, init_vec, 50, win_size, 128, display=False))