-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #442 from roedoejet/dev.ap/demo-gradio
Dev.ap/demo gradio
- Loading branch information
Showing
7 changed files
with
167 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import os | ||
from functools import partial | ||
|
||
import gradio as gr | ||
import torch | ||
|
||
from everyvoice.config.type_definitions import TargetTrainingTextRepresentationLevel | ||
from everyvoice.model.feature_prediction.FastSpeech2_lightning.fs2.cli.synthesize import ( | ||
synthesize_helper, | ||
) | ||
from everyvoice.model.feature_prediction.FastSpeech2_lightning.fs2.model import ( | ||
FastSpeech2, | ||
) | ||
from everyvoice.model.feature_prediction.FastSpeech2_lightning.fs2.prediction_writing_callback import ( | ||
PredictionWritingWavCallback, | ||
) | ||
from everyvoice.model.feature_prediction.FastSpeech2_lightning.fs2.type_definitions import ( | ||
SynthesizeOutputFormats, | ||
) | ||
from everyvoice.model.vocoder.HiFiGAN_iSTFT_lightning.hfgl.utils import ( | ||
load_hifigan_from_checkpoint, | ||
) | ||
from everyvoice.utils.heavy import get_device_from_accelerator | ||
|
||
os.environ["no_proxy"] = "localhost,127.0.0.1,::1" | ||
|
||
|
||
def synthesize_audio( | ||
text, | ||
duration_control, | ||
text_to_spec_model, | ||
vocoder_model, | ||
vocoder_config, | ||
accelerator, | ||
device, | ||
language=None, | ||
speaker=None, | ||
output_dir=None, | ||
): | ||
config, device, predictions = synthesize_helper( | ||
model=text_to_spec_model, | ||
vocoder_model=vocoder_model, | ||
vocoder_config=vocoder_config, | ||
texts=[text], | ||
language=language, | ||
accelerator=accelerator, | ||
devices="1", | ||
device=device, | ||
global_step=1, | ||
output_type=[], | ||
text_representation=TargetTrainingTextRepresentationLevel.characters, | ||
output_dir=output_dir, | ||
speaker=speaker, | ||
duration_control=duration_control, | ||
filelist=None, | ||
teacher_forcing_directory=None, | ||
batch_size=1, | ||
num_workers=1, | ||
) | ||
output_key = "postnet_output" if text_to_spec_model.config.model.use_postnet else "output" | ||
wav_writer = PredictionWritingWavCallback( | ||
output_dir=output_dir, | ||
config=config, | ||
output_key=output_key, | ||
device=device, | ||
global_step=1, | ||
vocoder_model=vocoder_model, | ||
vocoder_config=vocoder_config, | ||
) | ||
# move to device because lightning accumulates predictions on cpu | ||
predictions[0][output_key] = predictions[0][output_key].to(device) | ||
wav, sr = wav_writer.synthesize_audio(predictions[0]) | ||
return sr, wav[0] | ||
|
||
|
||
def create_demo_app( | ||
text_to_spec_model_path, | ||
spec_to_wav_model_path, | ||
language, | ||
speaker, | ||
output_dir, | ||
accelerator, | ||
) -> gr.Interface: | ||
device = get_device_from_accelerator(accelerator) | ||
vocoder_ckpt = torch.load(spec_to_wav_model_path, map_location=device) | ||
vocoder_model, vocoder_config = load_hifigan_from_checkpoint(vocoder_ckpt, device) | ||
model: FastSpeech2 = FastSpeech2.load_from_checkpoint(text_to_spec_model_path).to( | ||
device | ||
) | ||
model.eval() | ||
return gr.Interface( | ||
partial( | ||
synthesize_audio, | ||
text_to_spec_model=model, | ||
vocoder_model=vocoder_model, | ||
vocoder_config=vocoder_config, | ||
language=language, | ||
speaker=speaker, | ||
output_dir=output_dir, | ||
accelerator=accelerator, | ||
device=device, | ||
), | ||
[ | ||
"textbox", | ||
gr.Slider(0.75, 1.75, 1.0, step=0.25), | ||
], | ||
gr.Audio(format="mp3"), | ||
title="EveryVoice Demo", | ||
) |
Submodule FastSpeech2_lightning
updated
7 files
+149 −64 | fs2/cli/synthesize.py | |
+11 −2 | fs2/dataset.py | |
+23 −5 | fs2/model.py | |
+45 −55 | fs2/prediction_writing_callback.py | |
+0 −67 | fs2/synthesizer.py | |
+3 −0 | fs2/tests/test_cli.py | |
+2 −0 | fs2/tests/test_writing_callbacks.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters