(sess, net, fast_generation, gc, samples_placeholder,
gc_placeholder, operations)
| 55 | |
| 56 | |
| 57 | def generate_waveform(sess, net, fast_generation, gc, samples_placeholder, |
| 58 | gc_placeholder, operations): |
| 59 | waveform = [128] * net.receptive_field |
| 60 | if fast_generation: |
| 61 | for sample in waveform[:-1]: |
| 62 | sess.run(operations, feed_dict={samples_placeholder: [sample]}) |
| 63 | |
| 64 | for i in range(GENERATE_SAMPLES): |
| 65 | if i % 100 == 0: |
| 66 | print("Generating {} of {}.".format(i, GENERATE_SAMPLES)) |
| 67 | sys.stdout.flush() |
| 68 | if fast_generation: |
| 69 | window = waveform[-1] |
| 70 | else: |
| 71 | if len(waveform) > net.receptive_field: |
| 72 | window = waveform[-net.receptive_field:] |
| 73 | else: |
| 74 | window = waveform |
| 75 | |
| 76 | # Run the WaveNet to predict the next sample. |
| 77 | feed_dict = {samples_placeholder: window} |
| 78 | if gc is not None: |
| 79 | feed_dict[gc_placeholder] = gc |
| 80 | results = sess.run(operations, feed_dict=feed_dict) |
| 81 | |
| 82 | sample = np.random.choice( |
| 83 | np.arange(QUANTIZATION_CHANNELS), p=results[0]) |
| 84 | waveform.append(sample) |
| 85 | |
| 86 | # Skip the first number of samples equal to the size of the receptive |
| 87 | # field minus one. |
| 88 | waveform = np.array(waveform[net.receptive_field - 1:]) |
| 89 | decode = mu_law_decode(samples_placeholder, QUANTIZATION_CHANNELS) |
| 90 | decoded_waveform = sess.run(decode, |
| 91 | feed_dict={samples_placeholder: waveform}) |
| 92 | return decoded_waveform |
| 93 | |
| 94 | |
| 95 | def generate_waveforms(sess, net, fast_generation, global_condition): |
no test coverage detected