Created
August 10, 2020 00:26
-
-
Save neelriyer/4f2cb882b2f8def102174681caf5c35c to your computer and use it in GitHub Desktop.
reconstruct the audio from a waveform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# taken from: https://github.com/alishdipani/Neural-Style-Transfer-Audio/blob/master/NeuralStyleTransfer.py | |
if torch.cuda.is_available(): | |
output = output.cpu() | |
output = output.squeeze(0) | |
output = output.numpy() | |
N_FFT=2048 | |
a = np.zeros_like(output) | |
a = np.exp(output) - 1 | |
# This code is supposed to do phase reconstruction | |
p = 2 * np.pi * np.random.random_sample(a.shape) - np.pi | |
for i in range(500): | |
S = a * np.exp(1j*p) | |
x = librosa.istft(S) | |
p = np.angle(librosa.stft(x, N_FFT)) | |
OUTPUT_FILENAME = 'output.wav' | |
librosa.output.write_wav(OUTPUT_FILENAME, x, style_sr) | |
Audio(OUTPUT_FILENAME) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment