cymic commited on
Commit
d08be73
1 Parent(s): ba7a5e3

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -97
app.py DELETED
@@ -1,97 +0,0 @@
1
- import os
2
-
3
- os.system('cd monotonic_align && python setup.py build_ext --inplace && cd ..')
4
-
5
- import logging
6
-
7
- numba_logger = logging.getLogger('numba')
8
- numba_logger.setLevel(logging.WARNING)
9
-
10
- import librosa
11
-
12
- import matplotlib.pyplot as plt
13
- import IPython.display as ipd
14
-
15
- import os
16
- import json
17
- import math
18
- import torch
19
- from torch import nn
20
- from torch.nn import functional as F
21
- from torch.utils.data import DataLoader
22
-
23
- import commons
24
- import utils
25
- from data_utils import TextAudioLoader, TextAudioCollate, TextAudioSpeakerLoader, TextAudioSpeakerCollate
26
- from models import SynthesizerTrn
27
- from text.symbols import symbols
28
- from text.cleaners import japanese_phrase_cleaners
29
- from text import cleaned_text_to_sequence
30
- from pypinyin import lazy_pinyin, Style
31
-
32
- from scipy.io.wavfile import write
33
-
34
- def get_text(text, hps):
35
- text_norm = cleaned_text_to_sequence(text)
36
- if hps.data.add_blank:
37
- text_norm = commons.intersperse(text_norm, 0)
38
- text_norm = torch.LongTensor(text_norm)
39
- return text_norm
40
- # hps_ms = utils.get_hparams_from_file("./configs/vctk_base.json")
41
-
42
-
43
- hps = utils.get_hparams_from_file("./configs/tokaiteio.json")
44
- # net_g_ms = SynthesizerTrn(
45
- # len(symbols),
46
- # hps_ms.data.filter_length // 2 + 1,
47
- # hps_ms.train.segment_size // hps.data.hop_length,
48
- # n_speakers=hps_ms.data.n_speakers,
49
- # **hps_ms.model)
50
-
51
- net_g = SynthesizerTrn(
52
- len(symbols),
53
- hps.data.filter_length // 2 + 1,
54
- hps.train.segment_size // hps.data.hop_length,
55
- **hps.model)
56
- _ = net_g.eval()
57
-
58
-
59
- def tts(text):
60
- if len(text) > 150:
61
- return "Error: Text is too long", None
62
- stn_tst = get_text(text, hps)
63
- with torch.no_grad():
64
- x_tst = stn_tst.unsqueeze(0)
65
- x_tst_lengths = torch.LongTensor([stn_tst.size(0)])
66
- audio = net_g.infer(x_tst, x_tst_lengths, noise_scale=.667, noise_scale_w=0.8, length_scale=1)[0][0,0].data.float().numpy()
67
- ipd.display(ipd.Audio(audio, rate=hps.data.sampling_rate))
68
-
69
-
70
- def tts_fn(text, speaker_id):
71
- if len(text) > 150:
72
- return "Error: Text is too long", None
73
- stn_tst = get_text(text, hps)
74
- with torch.no_grad():
75
- x_tst = stn_tst.unsqueeze(0)
76
- x_tst_lengths = LongTensor([stn_tst.size(0)])
77
- audio = net_g.infer(x_tst, x_tst_lengths, noise_scale=.667, noise_scale_w=0.8, length_scale=1)[0][
78
- 0, 0].data.cpu().float().numpy()
79
- return "Success", (hps.data.sampling_rate, audio)
80
-
81
-
82
- if __name__ == '__main__':
83
- _ = utils.load_checkpoint("G_50000.pth", net_g, None)
84
-
85
- app = gr.Blocks()
86
-
87
- with app:
88
- with gr.Tabs():
89
- with gr.Column():
90
- tts_input1 = gr.TextArea(label="Text (150 words limitation)", value="こんにちは。")
91
- tts_submit = gr.Button("Generate", variant="primary")
92
- tts_output1 = gr.Textbox(label="Output Message")
93
- tts_output2 = gr.Audio(label="Output Audio")
94
-
95
- tts_submit.click(tts_fn, [tts_input1, tts_input2], [tts_output1, tts_output2])
96
-
97
- app.launch()