ruslanmv commited on
Commit
2496352
·
1 Parent(s): f763f1e

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 = "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."
49
+ 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>"
50
+
51
+ examples = [
52
+ ["TensorFlowTTS provides real-time state-of-the-art speech synthesis architectures such as Tacotron-2, Melgan, Multiband-Melgan, FastSpeech, FastSpeech2 based-on TensorFlow 2."],
53
+ ["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."]
54
+ ]
55
+
56
+ gr.Interface(inference, inputs, outputs, title=title, description=description, article=article, examples=examples).launch()