-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_script.py
49 lines (42 loc) · 1.4 KB
/
generate_script.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
# Adapted from https://github.com/vincentherrmann/pytorch-wavenet
import librosa
from wavenet_model import *
from audio_data import WavenetDataset
from wavenet_training import *
import soundfile as sf
import time
model = load_latest_model_from("snapshots", use_cuda=False)
print("model: ", model)
print("receptive field: ", model.receptive_field)
print("parameter count: ", model.parameter_count())
data = WavenetDataset(
dataset_file="train_samples/bach_chaconne/dataset.npz",
item_length=model.receptive_field + model.output_length - 1,
target_length=model.output_length,
file_location="train_samples/bach_chaconne",
test_stride=20,
)
print("the dataset has " + str(len(data)) + " items")
start_data = data[250000][0]
start_data = torch.max(start_data, 0)[1]
def prog_callback(step, total_steps):
print(str(100 * step // total_steps) + "% generated")
start = time.time
generated = model.generate(
num_samples=100000,
first_samples=start_data,
temperature=1.0,
)
end = time.time() - start
print("Time taken: ", end)
# generated = model.generate_fast(
# num_samples=100000,
# first_samples=start_data,
# progress_callback=prog_callback,
# progress_interval=1000,
# temperature=1.0,
# regularize=0.0,
# )
print(generated)
# librosa.output.write_wav('latest_generated_clip.wav', generated, sr=16000)
sf.write("latest_generated_clip.wav", generated, samplerate=16000)