store generation time per generation rather than per entire request

This commit is contained in:
mrq 2023-02-11 13:00:39 +00:00
parent 44eba62dc8
commit 841754602e

View File

@ -121,7 +121,7 @@ def generate(
else: else:
texts = split_and_recombine_text(text) texts = split_and_recombine_text(text)
start_time = time.time() full_start_time = time.time()
outdir = f"./results/{voice}/" outdir = f"./results/{voice}/"
os.makedirs(outdir, exist_ok=True) os.makedirs(outdir, exist_ok=True)
@ -166,8 +166,10 @@ def generate(
print(f"[{str(line+1)}/{str(len(texts))}] Generating line: {cut_text}") print(f"[{str(line+1)}/{str(len(texts))}] Generating line: {cut_text}")
start_time = time.time()
gen, additionals = tts.tts(cut_text, **settings ) gen, additionals = tts.tts(cut_text, **settings )
seed = additionals[0] seed = additionals[0]
run_time = time.time()-start_time
if isinstance(gen, list): if isinstance(gen, list):
for j, g in enumerate(gen): for j, g in enumerate(gen):
@ -175,12 +177,14 @@ def generate(
audio_cache[name] = { audio_cache[name] = {
'audio': g, 'audio': g,
'text': cut_text, 'text': cut_text,
'time': run_time
} }
else: else:
name = get_name(line=line) name = get_name(line=line)
audio_cache[name] = { audio_cache[name] = {
'audio': gen, 'audio': gen,
'text': cut_text, 'text': cut_text,
'time': run_time,
} }
for k in audio_cache: for k in audio_cache:
@ -215,6 +219,7 @@ def generate(
audio_cache[name] = { audio_cache[name] = {
'audio': audio, 'audio': audio,
'text': text, 'text': text,
'time': time.time()-full_start_time
} }
output_voices.append(f'{outdir}/{voice}_{name}.wav') output_voices.append(f'{outdir}/{voice}_{name}.wav')
@ -252,7 +257,7 @@ def generate(
'repetition_penalty': repetition_penalty, 'repetition_penalty': repetition_penalty,
'cond_free_k': cond_free_k, 'cond_free_k': cond_free_k,
'experimentals': experimental_checkboxes, 'experimentals': experimental_checkboxes,
'time': time.time()-start_time, 'time': time.time()-full_start_time,
} }
with open(f'{outdir}/input_{idx}.json', 'w', encoding="utf-8") as f: with open(f'{outdir}/input_{idx}.json', 'w', encoding="utf-8") as f:
@ -265,6 +270,7 @@ def generate(
if args.embed_output_metadata: if args.embed_output_metadata:
for path in audio_cache: for path in audio_cache:
info['text'] = audio_cache[path]['text'] info['text'] = audio_cache[path]['text']
info['time'] = audio_cache[path]['time']
metadata = music_tag.load_file(f"{outdir}/{voice}_{path}.wav") metadata = music_tag.load_file(f"{outdir}/{voice}_{path}.wav")
metadata['lyrics'] = json.dumps(info) metadata['lyrics'] = json.dumps(info)