<jupyter_start><jupyter_text>Time domain<jupyter_code>plt.plot(wav_data)<jupyter_output><empty_output><jupyter_text>Spectrogram parameters<jupyter_code>#window length 30 ms
window_sec = .02
seg_size = int(SMP_RATE*window_sec)

#overlap
overlap_size=0#int(seg_size*.25)<jupyter_output><empty_output><jupyter_text>Spectrogram<jupyter_code>plt.imshow(np.real(stft.spectrogram(wav_data,framelength=seg_size,overlap=2)))
specgram = stft.spectrogram(wav_data,framelength=seg_size,overlap=2)
reals,ims = np.real(specgram),np.imag(specgram)
output = stft.ispectrogram(reals+1j*ims,framelength=seg_size,overlap=2)
write_audio(output)
print reals.shape
#generated
f = open('samples/inverse_audio_spec.wav','wr')
wavfile.write(f,SMP_RATE,output.astype(np.int16))
f.close()
plt.plot(reals[0,:])<jupyter_output><empty_output><jupyter_text>Just FFT<jupyter_code>from scipy.fftpack import fft, ifft
fft_result = fft(wav_data)
fft_result.shape
np.real(fft(wav_data))
plt.plot(ifft(np.real(fft(wav_data))))
write_audio(ifft(fft(wav_data)))<jupyter_output>/Users/tmulc/anaconda2/envs/tensorflow1/lib/python2.7/site-packages/ipykernel_launcher.py:3: ComplexWarning: Casting complex values to real discards the imaginary part
  This is separate from the ipykernel package so we can avoid doing imports until<jupyter_text>Doesn't work  Using SciPy<jupyter_code>overlap_size
spec = signal.spectrogram(wav_data,fm,window='cosine',nperseg=seg_size,noverlap=None)
#t,inverse_audio = signal.istft(Sxx,fm,window='cosine',nperseg=seg_size,noverlap=None)
#plt.plot(inverse_audio)
f,t,Sxx = spec
len(f)
len(t)
Sxx.shape
plt.imshow(Sxx)
plt.plot(Sxx[0,:])
plt.pcolormesh(t, f, Sxx)
plt.ylabel('Frequency [Hz]')
plt.xlabel('Time [sec]')
plt.show()
#spec = signal.stft(wav_data,fm)
#f,t,Sxx = spec
#Sxx.shape<jupyter_output><empty_output><jupyter_text>Spectrogram notesThe spectrogram is really just a 2D input, but we will need to get information like the frequencies and length of time if we are going to invert it.  Since all the data is sampled at the same rate and we are using binning, we can keep the same frequency vector for all audio sample and just change the time vector for each bin (binning is of course happening at the time level)  Test Inverse Spectorgram<jupyter_code>t,inverse_audio = signal.istft(Sxx,fm,window='cosine',nperseg=seg_size)
plt.plot(inverse_audio)<jupyter_output><empty_output><jupyter_text>Write audio<jupyter_code>f = open('samples/org_audio_spec.wav','wr')
wavfile.write(f,SMP_RATE,wav_data.astype(np.int16))
f.close()
#generated
f = open('samples/inverse_audio_spec.wav','wr')
wavfile.write(f,SMP_RATE,inverse_audio.astype(np.int16))
f.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1262135922330097, 'fraction_numerical': 0.009335324869305451, 'mean_word_length': 9.303846153846154, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '585020', 'license': 'MIT', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1056, 'n_words': 177, 'path': 'SEGAN/Spectrogram.ipynb', 'repo_name': 'tmulc18/S2SCycleGAN', 'size': '2678'}