forked from brain-bzh/fast-wavenet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generating.py
77 lines (51 loc) · 1.67 KB
/
generating.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from time import time
import datetime
import os
import numpy as np
from wavenet.utils import make_batch
from wavenet.models import Model, Generator
import tensorflow as tf
from librosa import output
checkpoint_dir = "/checkpoints"
server_dir = 'datasets/'
local_dir = 'datasets/'
sample_rate = 11025
Quantification = 256
num_blocks = 2
num_layers = 12
num_hidden = 256
duration = 2
if (duration*sample_rate/2) % 2 == 0 :
num_time_samples = int(sample_rate*duration)
else :
num_time_samples = int(sample_rate*duration) - 1
num_channels = 1
gpu_fraction = 1.0
num_classes = Quantification
model = Model(num_time_samples=num_time_samples,
num_channels=num_channels,
gpu_fraction=gpu_fraction,
num_classes=num_classes,
num_blocks=num_blocks,
num_layers=num_layers,
num_hidden=num_hidden)
model.restore()
print("start")
generator = Generator(model)
print("Done")
new_pred = generator.run([[np.random.randn()]], num_time_samples*2)
output.write_wav('1dur_generated.wav', new_pred[0], sample_rate)
#new_pred = generator.run([[np.random.randn()]], num_time_samples*5)
#output.write_wav('5dur_generated.wav', new_pred[0], sample_rate)
#new_pred = generator.run([[np.random.randn()]], num_time_samples*120)
#output.write_wav('120dur_generated.wav', new_pred[0], sample_rate)
def createData() :
sound, latent = generator.getData([[np.random.randn()]], num_time_samples*2)
save(sound, latent)
def save(sound, h) :
x, y = sound, h
np.savez("data.npz", x=x, y=y, allow_pickle=True)
def load() :
data = np.load("data.npz")
data.allow_pickle = True
return data["x"], data["y"]