Added tab to read and copy settings from a voice clip (in the future, I'll see about enmbedding the latent used to generate the voice)

This commit is contained in:
mrq 2023-02-06 16:00:44 +00:00
parent edb6a173d3
commit e25ec325fe

66
app.py
View File

@ -130,7 +130,7 @@ def generate(text, delimiter, emotion, prompt, voice, mic_audio, preset, seed, c
info = {
'text': text,
'delimiter': delimiter,
'delimiter': '\\n' if delimiter == "\n" else delimiter,
'emotion': emotion,
'prompt': prompt,
'voice': voice,
@ -185,11 +185,44 @@ def update_presets(value):
else:
return (gr.update(), gr.update())
def read_metadata(file):
j = None
if file is not None:
metadata = music_tag.load_file(file.name)
if 'lyrics' in metadata:
j = json.loads(str(metadata['lyrics']))
print(j)
return j
def copy_settings(file):
metadata = read_metadata(file)
if metadata is None:
return None
return (
metadata['text'],
metadata['delimiter'],
metadata['emotion'],
metadata['prompt'],
metadata['voice'],
metadata['mic_audio'],
metadata['preset'],
metadata['seed'],
metadata['candidates'],
metadata['num_autoregressive_samples'],
metadata['diffusion_iterations'],
metadata['temperature'],
metadata['diffusion_sampler'],
metadata['breathing_room'],
metadata['experimentals'],
)
def update_voices():
return gr.Dropdown.update(choices=os.listdir(os.path.join("tortoise", "voices")) + ["microphone"])
def main():
with gr.Blocks() as demo:
with gr.Blocks() as webui:
with gr.Tab("Generate"):
with gr.Row():
with gr.Column():
text = gr.Textbox(lines=4, label="Prompt")
@ -266,8 +299,7 @@ def main():
submit = gr.Button(value="Generate")
#stop = gr.Button(value="Stop")
submit_event = submit.click(generate,
inputs=[
input_settings = [
text,
delimiter,
emotion,
@ -283,13 +315,34 @@ def main():
diffusion_sampler,
breathing_room,
experimentals,
],
]
submit_event = submit.click(generate,
inputs=input_settings,
outputs=[selected_voice, output_audio, usedSeed],
)
#stop.click(fn=None, inputs=None, outputs=None, cancels=[submit_event])
with gr.Tab("Utilities"):
with gr.Row():
with gr.Column():
audio_in = gr.File(type="file", label="Audio Input", file_types=["audio"])
copy_button = gr.Button(value="Copy Settings")
with gr.Column():
metadata_out = gr.JSON(label="Audio Metadata")
demo.queue().launch(share=args.share)
audio_in.upload(
fn=read_metadata,
inputs=audio_in,
outputs=metadata_out,
)
copy_button.click(copy_settings,
inputs=audio_in, # JSON elements cannt be used as inputs
outputs=input_settings
)
webui.queue().launch(share=args.share)
if __name__ == "__main__":
@ -299,6 +352,7 @@ if __name__ == "__main__":
parser.add_argument("--cond-latent-max-chunk-size", type=int, default=1000000, help="Sets an upper limit to audio chunk size when computing conditioning latents")
args = parser.parse_args()
print("Initializating TorToiSe...")
tts = TextToSpeech(minor_optimizations=not args.low_vram)
main()