From 734adf4d281a3bbf30c897994774146ebed3281b Mon Sep 17 00:00:00 2001 From: Mikkel Garcia Date: Tue, 29 Mar 2016 20:32:02 -0600 Subject: [PATCH] [feature] composer - samples from saved DCGAN to create bad songs --- composer.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 composer.py diff --git a/composer.py b/composer.py new file mode 100644 index 000000000..44d072fb3 --- /dev/null +++ b/composer.py @@ -0,0 +1,45 @@ +import os +import numpy as np +import tensorflow as tf + +from glob import glob +from model import DCGAN +from utils import pp, visualize, to_json +import tensorflow_wav + + +dataset="audio" +wav_size=64 +is_crop=False +batch_size=16 +checkpoint_dir="checkpoint" +bitrate=4096 + +with tf.Session() as sess: + dcgan = DCGAN(sess, wav_size=wav_size, batch_size=batch_size, + dataset_name=dataset, is_crop=is_crop, checkpoint_dir=checkpoint_dir) + dcgan.load(checkpoint_dir) + + data = glob(os.path.join("./training", "*.wav")) + sample_file = data[0] + sample =tensorflow_wav.get_wav(sample_file) + + full_audio = [] + for i in range(120): + audio = dcgan.sample() + + audio = np.reshape(audio,[-1]) + print("Audio shape", np.shape(audio)) + full_audio += audio[:bitrate].tolist() + print("Full audio shape", np.shape(full_audio)) + + samplewav = sample.copy() + samplewav + samplewav['data']=full_audio + print("samplewav shape", np.shape(samplewav['data'])) + + filename = "./compositions/song.wav" + tensorflow_wav.save_wav(samplewav, filename ) + + +