jbetker commited on
Commit
cdc26b5
1 Parent(s): f625a9e

Add sweeper script for finding optimal generation hyperparameters.

Browse files
Files changed (1) hide show
  1. sweep.py +61 -0
sweep.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from random import shuffle
3
+
4
+ import torchaudio
5
+
6
+ from api import TextToSpeech
7
+ from utils.audio import load_audio
8
+
9
+
10
+ def permutations(args):
11
+ res = []
12
+ k = next(iter(args.keys()))
13
+ vals = args[k]
14
+ del args[k]
15
+ if not args:
16
+ return [{k: v} for v in vals]
17
+ lower = permutations(args)
18
+ for v in vals:
19
+ for l in lower:
20
+ lc = l.copy()
21
+ lc[k] = v
22
+ res.append(lc)
23
+ return res
24
+
25
+
26
+ if __name__ == '__main__':
27
+ fname = 'Y:\\libritts\\test-clean\\transcribed-brief-w2v.tsv'
28
+ outpath_base = 'D:\\tmp\\tortoise-tts-eval\\std_sweep_diffusion'
29
+ outpath_real = 'D:\\tmp\\tortoise-tts-eval\\real'
30
+
31
+ arg_ranges = {
32
+ 'diffusion_temperature': [.5, .7, 1],
33
+ 'cond_free_k': [.5, 1, 2],
34
+ }
35
+ cfgs = permutations(arg_ranges)
36
+ shuffle(cfgs)
37
+
38
+ for cfg in cfgs:
39
+ outpath = os.path.join(outpath_base, f'{cfg["cond_free_k"]}_{cfg["diffusion_temperature"]}')
40
+ os.makedirs(outpath, exist_ok=True)
41
+ os.makedirs(outpath_real, exist_ok=True)
42
+ with open(fname, 'r', encoding='utf-8') as f:
43
+ lines = [l.strip().split('\t') for l in f.readlines()]
44
+
45
+ recorder = open(os.path.join(outpath, 'transcript.tsv'), 'w', encoding='utf-8')
46
+ tts = TextToSpeech()
47
+ for e, line in enumerate(lines):
48
+ transcript = line[0]
49
+ if len(transcript) > 120:
50
+ continue # We need to support this, but cannot yet.
51
+ path = os.path.join(os.path.dirname(fname), line[1])
52
+ cond_audio = load_audio(path, 22050)
53
+ torchaudio.save(os.path.join(outpath_real, os.path.basename(line[1])), cond_audio, 22050)
54
+ sample = tts.tts(transcript, [cond_audio, cond_audio], num_autoregressive_samples=256, k=1, diffusion_iterations=200, cond_free=False,
55
+ repetition_penalty=1.5, length_penalty=2, temperature=.9, top_p=.9)
56
+ down = torchaudio.functional.resample(sample, 24000, 22050)
57
+ fout_path = os.path.join(outpath, os.path.basename(line[1]))
58
+ torchaudio.save(fout_path, down.squeeze(0), 22050)
59
+ recorder.write(f'{transcript}\t{fout_path}\n')
60
+ recorder.flush()
61
+ recorder.close()