Example #1
0
        t = x[ni, 0]
        t = t[:, 0]
        orig_buf[ni * step:(ni * step) + cut] += t

    x_o = orig_buf
    x_r = rec_buf

    f, axarr = plt.subplots(2, 1)
    axarr[0].plot(x_r)
    axarr[0].set_title("Reconstruction")
    axarr[1].plot(x_o)
    axarr[1].set_title("Original")

    plt.savefig("vq_vae_generation_results")
    plt.close()

    f, axarr = plt.subplots(2, 1)
    specplot(specgram(x_r), axarr[0])
    axarr[0].set_title("Reconstruction")
    specplot(specgram(x_o), axarr[1])
    axarr[1].set_title("Original")

    plt.savefig("vq_vae_generation_results_spec")
    plt.close()

    wavfile.write("original_wav.wav", 8000, soundsc(x_o))
    wavfile.write("reconstructed_wav.wav", 8000, soundsc(x_r))
    from IPython import embed
    embed()
    raise ValueError()
Example #2
0
post_time = 0
joint_time = 0
for jj in range(n_plot):
    # use extra steps from earlier
    pjj = preds[:(finished_step[jj] + extra_steps), jj]
    spectrogram = pjj * itr._std + itr._mean
    prename = "{}_{}_sample_{}_pre.wav".format(file_names[jj], args.input_type, jj)

    this_time = time.time()
    if os.path.exists(prename):
        print("{} file already found, not redoing calculations".format(prename))
        fs, reconstructed_waveform = wavfile.read(prename)
    else:
        reconstructed_waveform = sonify(spectrogram, len(spectrogram) * step, logmel)
        end_this_time = time.time()
        wavfile.write(prename, sample_rate, soundsc(reconstructed_waveform))
    elapsed = end_this_time - this_time
    print("Elapsed pre sampling time {} s".format(elapsed))
    pre_time += elapsed
    joint_time += elapsed

    fftsize = 512
    substep = 32
    postname = "{}_{}_sample_{}_post.wav".format(file_names[jj], args.input_type, jj)
    this_time = time.time()
    if not os.path.exists(postname):
        rw_s = np.abs(stft(reconstructed_waveform, fftsize=fftsize, step=substep, real=False,
                           compute_onesided=False))
        rw = iterate_invert_spectrogram(rw_s, fftsize, substep, n_iter=gl_steps, verbose=True)
        end_this_time = time.time()
        wavfile.write(postname, sample_rate, soundsc(rw))
# put all the shorter traces into one long sequence, no overlap add or anything
i_rec = final_hidden_indices
rec_buf = np.zeros((len(x_rec) * step + 2 * cut))
i_buf = np.zeros((len(x_rec) * step + 2 * cut))
for ni in range(len(x_rec)):
    t = x_rec[ni, 0]
    t = t[:, 0]
    rec_buf[ni * step:(ni * step) + cut] += t
    i_buf[ni * step:(ni * step) + cut] = i_rec[ni]

x_r = rec_buf
i_r = i_buf

f, axarr = plt.subplots(2, 1)
axarr[0].plot(x_r)
axarr[0].set_title("Generation")
axarr[1].plot(i_r, color="r")

plt.savefig("vq_vae_generation_results")
plt.close()

f, axarr = plt.subplots(1, 1)
specplot(specgram(x_r), axarr)
axarr.set_title("Generation")
#axarr[1].plot(i_r, color="r")

plt.savefig("vq_vae_generation_results_spec")
plt.close()

wavfile.write("generated_wav.wav", 8000, soundsc(x_r))
Example #4
0
with tf.Session():
    spectrogram = logmel(waveform).eval()

spectrogram2 = logmel2(waveform)
spectrogram = (spectrogram - spectrogram.min()) / float(spectrogram.max() -
                                                        spectrogram.min())
spectrogram2 = (spectrogram2 - spectrogram2.min()) / float(spectrogram2.max() -
                                                           spectrogram2.min())

f, axarr = plt.subplots(1, 2)
axarr[0].imshow(spectrogram)
axarr[1].imshow(spectrogram2)
plt.savefig("tmpspec")

reconstructed_waveform = sonify(spectrogram, len(waveform), logmel)
wavfile.write("tmp.wav", sample_rate, soundsc(reconstructed_waveform))
reconstructed_waveform2 = sonify(spectrogram2, len(waveform), logmel)
wavfile.write("tmp2.wav", sample_rate, soundsc(reconstructed_waveform2))

fftsize = 512
substep = 32
rw_s = np.abs(
    stft(reconstructed_waveform,
         fftsize=fftsize,
         step=substep,
         real=False,
         compute_onesided=False))
rw = iterate_invert_spectrogram(rw_s,
                                fftsize,
                                substep,
                                n_iter=100,