StevenLimcorn commited on
Commit
3ff8c18
β€’
1 Parent(s): 597e4ad

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # initialize mb_melgan model
15
+ mb_melgan = TFAutoModel.from_pretrained("tensorspeech/tts-mb_melgan-ljspeech-en")
16
+
17
+
18
+ # inference
19
+ processor = AutoProcessor.from_pretrained("tensorspeech/tts-fastspeech2-ljspeech-en")
20
+
21
+ def inference(text):
22
+ input_ids = processor.text_to_sequence(text)
23
+ # fastspeech inference
24
+
25
+ mel_before, mel_after, duration_outputs, _, _ = fastspeech2.inference(
26
+ input_ids=tf.expand_dims(tf.convert_to_tensor(input_ids, dtype=tf.int32), 0),
27
+ speaker_ids=tf.convert_to_tensor([0], dtype=tf.int32),
28
+ speed_ratios=tf.convert_to_tensor([1.0], dtype=tf.float32),
29
+ f0_ratios =tf.convert_to_tensor([1.0], dtype=tf.float32),
30
+ energy_ratios =tf.convert_to_tensor([1.0], dtype=tf.float32),
31
+ )
32
+
33
+ # melgan inference
34
+ audio_before = mb_melgan.inference(mel_before)[0, :, 0]
35
+ audio_after = mb_melgan.inference(mel_after)[0, :, 0]
36
+
37
+ # save to file
38
+ sf.write('./audio_before.wav', audio_before, 22050, "PCM_16")
39
+ sf.write('./audio_after.wav', audio_after, 22050, "PCM_16")
40
+ return './audio_after.wav'
41
+
42
+ inputs = gr.inputs.Textbox(lines=5, label="Input Text")
43
+ outputs = gr.outputs.Audio(type="file", label="Output Audio")
44
+
45
+
46
+ title = "Tensorflow TTS"
47
+ description = "Gradio demo for TensorFlowTTS: Real-Time State-of-the-art Speech Synthesis for Tensorflow 2. To use it, simply add your text, or click one of the examples to load them. Read more at the links below."
48
+ article = "<p style='text-align: center'><a href='https://tensorspeech.github.io/TensorFlowTTS/'>TensorFlowTTS: Real-Time State-of-the-art Speech Synthesis for Tensorflow 2</a> | <a href='https://github.com/TensorSpeech/TensorFlowTTS'>Github Repo</a></p>"
49
+
50
+ examples = [
51
+ ["TensorFlowTTS provides real-time state-of-the-art speech synthesis architectures such as Tacotron-2, Melgan, Multiband-Melgan, FastSpeech, FastSpeech2 based-on TensorFlow 2."],
52
+ ["With Tensorflow 2, we can speed-up training/inference progress, optimizer further by using fake-quantize aware and pruning, make TTS models can be run faster than real-time and be able to deploy on mobile devices or embedded systems."]
53
+ ]
54
+
55
+ gr.Interface(inference, inputs, outputs, title=title, description=description, article=article, examples=examples).launch()