Ahsen Khaliq commited on
Commit
fc89950
1 Parent(s): 64f9439

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import soundfile as sf
3
+ import yaml
4
+
5
+ import tensorflow as tf
6
+
7
+ from tensorflow_tts.inference import TFAutoModel
8
+ from tensorflow_tts.inference import AutoProcessor
9
+ import gradio as gr
10
+
11
+ # initialize fastspeech2 model.
12
+ fastspeech2 = TFAutoModel.from_pretrained("tensorspeech/tts-fastspeech2-ljspeech-en")
13
+
14
+
15
+ # initialize mb_melgan model
16
+ mb_melgan = TFAutoModel.from_pretrained("tensorspeech/tts-mb_melgan-ljspeech-en")
17
+
18
+
19
+ # inference
20
+ processor = AutoProcessor.from_pretrained("tensorspeech/tts-fastspeech2-ljspeech-en")
21
+
22
+ def inference(text):
23
+ input_ids = processor.text_to_sequence(text)
24
+ # fastspeech inference
25
+
26
+ mel_before, mel_after, duration_outputs, _, _ = fastspeech2.inference(
27
+ input_ids=tf.expand_dims(tf.convert_to_tensor(input_ids, dtype=tf.int32), 0),
28
+ speaker_ids=tf.convert_to_tensor([0], dtype=tf.int32),
29
+ speed_ratios=tf.convert_to_tensor([1.0], dtype=tf.float32),
30
+ f0_ratios =tf.convert_to_tensor([1.0], dtype=tf.float32),
31
+ energy_ratios =tf.convert_to_tensor([1.0], dtype=tf.float32),
32
+ )
33
+
34
+ # melgan inference
35
+ audio_before = mb_melgan.inference(mel_before)[0, :, 0]
36
+ audio_after = mb_melgan.inference(mel_after)[0, :, 0]
37
+
38
+ # save to file
39
+ sf.write('./audio_before.wav', audio_before, 22050, "PCM_16")
40
+ sf.write('./audio_after.wav', audio_after, 22050, "PCM_16")
41
+ return './audio_after.wav'
42
+
43
+ inputs = gr.inputs.Textbox(lines=5, label="Input Text")
44
+ outputs = gr.outputs.Audio(type="file", label="Output Audio")
45
+
46
+
47
+ title = "Tensorflow TTS"
48
+ description = "demo for VITS: Conditional Variational Autoencoder with Adversarial Learning for End-to-End Text-to-Speech. To use it, simply add your text, or click one of the examples to load them. Read more at the links below."
49
+ article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2106.06103'>Conditional Variational Autoencoder with Adversarial Learning for End-to-End Text-to-Speech</a> | <a href='https://github.com/jaywalnut310/vits'>Github Repo</a></p>"
50
+
51
+ examples = [
52
+ ["We propose VITS, Conditional Variational Autoencoder with Adversarial Learning for End-to-End Text-to-Speech."],
53
+ ["Our method adopts variational inference augmented with normalizing flows and an adversarial training process, which improves the expressive power of generative modeling."]
54
+ ]
55
+
56
+ gr.Interface(inference, inputs, outputs, title=title, description=description, article=article, examples=examples).launch()