Spaces:
Running
Running
First commit
Browse files- README.md +5 -5
- app.py +51 -0
- packages.txt +1 -0
- requirements.txt +5 -0
README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version:
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
|
|
1 |
---
|
2 |
+
title: TensorFlowTTS
|
3 |
+
emoji: π
|
4 |
+
colorFrom: green
|
5 |
+
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 2.8.13
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import soundfile as sf
|
3 |
+
import yaml
|
4 |
+
import tensorflow as tf
|
5 |
+
from tensorflow_tts.inference import TFAutoModel
|
6 |
+
from tensorflow_tts.inference import AutoProcessor
|
7 |
+
import gradio as gr
|
8 |
+
|
9 |
+
# initialize fastspeech2 model.
|
10 |
+
fastspeech2 = TFAutoModel.from_pretrained("ruslanmv/TensorFlowTTS")
|
11 |
+
|
12 |
+
# initialize mb_melgan model
|
13 |
+
mb_melgan = TFAutoModel.from_pretrained("tensorspeech/tts-mb_melgan-ljspeech-en")
|
14 |
+
|
15 |
+
# inference
|
16 |
+
processor = AutoProcessor.from_pretrained("ruslanmv/TensorFlowTTS")
|
17 |
+
|
18 |
+
def inference(text):
|
19 |
+
input_ids = processor.text_to_sequence(text)
|
20 |
+
# fastspeech inference
|
21 |
+
|
22 |
+
mel_before, mel_after, duration_outputs, _, _ = fastspeech2.inference(
|
23 |
+
input_ids=tf.expand_dims(tf.convert_to_tensor(input_ids, dtype=tf.int32), 0),
|
24 |
+
speaker_ids=tf.convert_to_tensor([0], dtype=tf.int32),
|
25 |
+
speed_ratios=tf.convert_to_tensor([1.0], dtype=tf.float32),
|
26 |
+
f0_ratios =tf.convert_to_tensor([1.0], dtype=tf.float32),
|
27 |
+
energy_ratios =tf.convert_to_tensor([1.0], dtype=tf.float32),
|
28 |
+
)
|
29 |
+
|
30 |
+
# melgan inference
|
31 |
+
audio_before = mb_melgan.inference(mel_before)[0, :, 0]
|
32 |
+
audio_after = mb_melgan.inference(mel_after)[0, :, 0]
|
33 |
+
|
34 |
+
# save to file
|
35 |
+
sf.write('./audio_before.wav', audio_before, 22050, "PCM_16")
|
36 |
+
sf.write('./audio_after.wav', audio_after, 22050, "PCM_16")
|
37 |
+
return './audio_after.wav'
|
38 |
+
|
39 |
+
inputs = gr.inputs.Textbox(lines=5, label="Input Text")
|
40 |
+
outputs = gr.outputs.Audio(type="file", label="Output Audio")
|
41 |
+
|
42 |
+
title = "Tensorflow TTS"
|
43 |
+
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."
|
44 |
+
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>"
|
45 |
+
|
46 |
+
examples = [
|
47 |
+
["TensorFlowTTS provides real-time state-of-the-art speech synthesis architectures such as Tacotron-2, Melgan, Multiband-Melgan, FastSpeech, FastSpeech2 based-on TensorFlow 2."],
|
48 |
+
["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."]
|
49 |
+
]
|
50 |
+
|
51 |
+
gr.Interface(inference, inputs, outputs, title=title, description=description, article=article, examples=examples).launch()
|
packages.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
libsndfile1
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
git+https://github.com/ruslanmv/TensorFlow-TTS.git
|
2 |
+
numpy
|
3 |
+
SoundFile
|
4 |
+
git+https://github.com/repodiac/german_transliterate
|
5 |
+
Jinja2
|