Spaces:
Build error
Build error
Commit
·
04c250d
1
Parent(s):
a0c9b7d
Create new file
Browse files
app.py
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import time
|
3 |
+
import urllib.request
|
4 |
+
from pathlib import Path
|
5 |
+
import os
|
6 |
+
import torch
|
7 |
+
import scipy.io.wavfile
|
8 |
+
from espnet2.bin.tts_inference import Text2Speech
|
9 |
+
from espnet2.utils.types import str_or_none
|
10 |
+
|
11 |
+
|
12 |
+
# def load_model(model_tag, vocoder_tag):
|
13 |
+
# from espnet_model_zoo.downloader import ModelDownloader
|
14 |
+
|
15 |
+
# kwargs = {}
|
16 |
+
|
17 |
+
# # Model
|
18 |
+
# d = ModelDownloader()
|
19 |
+
# kwargs = d.download_and_unpack(model_tag)
|
20 |
+
|
21 |
+
# # Vocoder
|
22 |
+
# download_dir = Path(os.path.expanduser("~/.cache/parallel_wavegan"))
|
23 |
+
# vocoder_dir = download_dir / vocoder_tag
|
24 |
+
# os.makedirs(vocoder_dir, exist_ok=True)
|
25 |
+
|
26 |
+
# kwargs["vocoder_config"] = vocoder_dir / "config.yml"
|
27 |
+
# if not kwargs["vocoder_config"].exists():
|
28 |
+
# urllib.request.urlretrieve(f"https://huggingface.co/{vocoder_tag}/resolve/main/config.yml", kwargs["vocoder_config"])
|
29 |
+
|
30 |
+
# kwargs["vocoder_file"] = vocoder_dir / "checkpoint-50000steps.pkl"
|
31 |
+
# if not kwargs["vocoder_file"].exists():
|
32 |
+
# urllib.request.urlretrieve(f"https://huggingface.co/{vocoder_tag}/resolve/main/checkpoint-50000steps.pkl", kwargs["vocoder_file"])
|
33 |
+
|
34 |
+
# return Text2Speech(
|
35 |
+
# **kwargs,
|
36 |
+
# device="cpu",
|
37 |
+
# threshold=0.5,
|
38 |
+
# minlenratio=0.0,
|
39 |
+
# maxlenratio=10.0,
|
40 |
+
# use_att_constraint=True,
|
41 |
+
# backward_window=1,
|
42 |
+
# forward_window=4,
|
43 |
+
# )
|
44 |
+
|
45 |
+
# gos_text2speech = load_model('https://huggingface.co/wietsedv/tacotron2-gronings/resolve/main/tts_ljspeech_finetune_tacotron2.v5_train.loss.ave.zip', 'wietsedv/parallelwavegan-gronings')
|
46 |
+
# nld_text2speech = load_model('https://huggingface.co/wietsedv/tacotron2-dutch/resolve/main/tts_ljspeech_finetune_tacotron2.v5_train.loss.ave.zip', 'wietsedv/parallelwavegan-dutch')
|
47 |
+
|
48 |
+
gos_text2speech = Text2Speech.from_pretrained(
|
49 |
+
model_tag="https://huggingface.co/wietsedv/tacotron2-gronings/resolve/main/tts_ljspeech_finetune_tacotron2.v5_train.loss.ave.zip",
|
50 |
+
vocoder_tag="parallel_wavegan/ljspeech_parallel_wavegan.v3",
|
51 |
+
device="cpu",
|
52 |
+
threshold=0.5,
|
53 |
+
minlenratio=0.0,
|
54 |
+
maxlenratio=10.0,
|
55 |
+
use_att_constraint=True,
|
56 |
+
backward_window=1,
|
57 |
+
forward_window=4,
|
58 |
+
)
|
59 |
+
nld_text2speech = Text2Speech.from_pretrained(
|
60 |
+
model_tag="https://huggingface.co/wietsedv/tacotron2-dutch/resolve/main/tts_ljspeech_finetune_tacotron2.v5_train.loss.ave.zip",
|
61 |
+
vocoder_tag="parallel_wavegan/ljspeech_parallel_wavegan.v3",
|
62 |
+
device="cpu",
|
63 |
+
threshold=0.5,
|
64 |
+
minlenratio=0.0,
|
65 |
+
maxlenratio=10.0,
|
66 |
+
use_att_constraint=True,
|
67 |
+
backward_window=1,
|
68 |
+
forward_window=4,
|
69 |
+
)
|
70 |
+
#eng_text2speech = Text2Speech.from_pretrained(
|
71 |
+
# model_tag="kan-bayashi/ljspeech_tacotron2",
|
72 |
+
# vocoder_tag="parallel_wavegan/ljspeech_parallel_wavegan.v3",
|
73 |
+
# device="cpu",
|
74 |
+
# threshold=0.5,
|
75 |
+
# minlenratio=0.0,
|
76 |
+
# maxlenratio=10.0,
|
77 |
+
# use_att_constraint=True,
|
78 |
+
# backward_window=1,
|
79 |
+
# forward_window=4,
|
80 |
+
#)
|
81 |
+
|
82 |
+
def inference(text,lang):
|
83 |
+
with torch.no_grad():
|
84 |
+
if lang == "gronings":
|
85 |
+
wav = gos_text2speech(text)["wav"]
|
86 |
+
scipy.io.wavfile.write("out.wav", gos_text2speech.fs , wav.view(-1).cpu().numpy())
|
87 |
+
if lang == "dutch":
|
88 |
+
wav = nld_text2speech(text)["wav"]
|
89 |
+
scipy.io.wavfile.write("out.wav", nld_text2speech.fs , wav.view(-1).cpu().numpy())
|
90 |
+
#if lang == "english":
|
91 |
+
# wav = eng_text2speech(text)["wav"]
|
92 |
+
# scipy.io.wavfile.write("out.wav", eng_text2speech.fs , wav.view(-1).cpu().numpy())
|
93 |
+
|
94 |
+
return "out.wav", "out.wav"
|
95 |
+
|
96 |
+
title = "GroTTS"
|
97 |
+
examples = [
|
98 |
+
['Ze gingen mit klas noar waddendiek, over en deur bragel lopen.', 'gronings']
|
99 |
+
]
|
100 |
+
|
101 |
+
gr.Interface(
|
102 |
+
inference,
|
103 |
+
[gr.inputs.Textbox(label="input text", lines=3), gr.inputs.Radio(choices=["gronings", "dutch"], type="value", default="gronings", label="language")],
|
104 |
+
[gr.outputs.Audio(type="file", label="Output"), gr.outputs.File()],
|
105 |
+
title=title,
|
106 |
+
examples=examples
|
107 |
+
).launch(enable_queue=True)
|