File size: 2,260 Bytes
cdc26b5 9db06e1 cdc26b5 9db06e1 cdc26b5 9db06e1 cdc26b5 9db06e1 cdc26b5 |
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 |
import os
from random import shuffle
import torchaudio
from api import TextToSpeech
from utils.audio import load_audio
def permutations(args):
res = []
k = next(iter(args.keys()))
vals = args[k]
del args[k]
if not args:
return [{k: v} for v in vals]
lower = permutations(args)
for v in vals:
for l in lower:
lc = l.copy()
lc[k] = v
res.append(lc)
return res
if __name__ == '__main__':
fname = 'Y:\\libritts\\test-clean\\transcribed-brief-w2v.tsv'
outpath_base = 'D:\\tmp\\tortoise-tts-eval\\std_sweep3'
outpath_real = 'D:\\tmp\\tortoise-tts-eval\\real'
arg_ranges = {
'top_p': [.3,.4,.5,.6],
'temperature': [.5, .6],
}
cfgs = permutations(arg_ranges)
shuffle(cfgs)
for cfg in cfgs:
outpath = os.path.join(outpath_base, f'{cfg["top_p"]}_{cfg["temperature"]}')
os.makedirs(outpath, exist_ok=True)
os.makedirs(outpath_real, exist_ok=True)
with open(fname, 'r', encoding='utf-8') as f:
lines = [l.strip().split('\t') for l in f.readlines()]
recorder = open(os.path.join(outpath, 'transcript.tsv'), 'w', encoding='utf-8')
tts = TextToSpeech()
for e, line in enumerate(lines):
transcript = line[0]
if len(transcript) > 120:
continue # We need to support this, but cannot yet.
path = os.path.join(os.path.dirname(fname), line[1])
cond_audio = load_audio(path, 22050)
torchaudio.save(os.path.join(outpath_real, os.path.basename(line[1])), cond_audio, 22050)
sample = tts.tts(transcript, [cond_audio, cond_audio], num_autoregressive_samples=256, k=1, diffusion_iterations=200,
repetition_penalty=2.0, length_penalty=2, temperature=.5, top_p=.5,
diffusion_temperature=.7, cond_free_k=2, **cfg)
down = torchaudio.functional.resample(sample, 24000, 22050)
fout_path = os.path.join(outpath, os.path.basename(line[1]))
torchaudio.save(fout_path, down.squeeze(0), 22050)
recorder.write(f'{transcript}\t{fout_path}\n')
recorder.flush()
recorder.close() |