Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
audio base64 output
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import argparse
|
|
2 |
import json
|
3 |
import os
|
4 |
import re
|
|
|
5 |
|
6 |
import librosa
|
7 |
import numpy as np
|
@@ -10,6 +11,8 @@ from torch import no_grad, LongTensor
|
|
10 |
import commons
|
11 |
import utils
|
12 |
import gradio as gr
|
|
|
|
|
13 |
from models import SynthesizerTrn
|
14 |
from text import text_to_sequence, _clean_text
|
15 |
from mel_processing import spectrogram_torch
|
@@ -17,6 +20,27 @@ from mel_processing import spectrogram_torch
|
|
17 |
limitation = os.getenv("SYSTEM") == "spaces" # limit text and audio length in huggingface spaces
|
18 |
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
def get_text(text, hps, is_symbol):
|
21 |
text_norm = text_to_sequence(text, hps.symbols, [] if is_symbol else hps.data.text_cleaners)
|
22 |
if hps.data.add_blank:
|
|
|
2 |
import json
|
3 |
import os
|
4 |
import re
|
5 |
+
import tempfile
|
6 |
|
7 |
import librosa
|
8 |
import numpy as np
|
|
|
11 |
import commons
|
12 |
import utils
|
13 |
import gradio as gr
|
14 |
+
import gradio.utils as gr_utils
|
15 |
+
import gradio.processing_utils as gr_processing_utils
|
16 |
from models import SynthesizerTrn
|
17 |
from text import text_to_sequence, _clean_text
|
18 |
from mel_processing import spectrogram_torch
|
|
|
20 |
limitation = os.getenv("SYSTEM") == "spaces" # limit text and audio length in huggingface spaces
|
21 |
|
22 |
|
23 |
+
def audio_postprocess(self, y):
|
24 |
+
if y is None:
|
25 |
+
return None
|
26 |
+
|
27 |
+
if gr_utils.validate_url(y):
|
28 |
+
file = gr_processing_utils.download_to_file(y, dir=self.temp_dir)
|
29 |
+
elif isinstance(y, tuple):
|
30 |
+
sample_rate, data = y
|
31 |
+
file = tempfile.NamedTemporaryFile(
|
32 |
+
suffix=".wav", dir=self.temp_dir, delete=False
|
33 |
+
)
|
34 |
+
gr_processing_utils.audio_to_file(sample_rate, data, file.name)
|
35 |
+
else:
|
36 |
+
file = gr_processing_utils.create_tmp_copy_of_file(y, dir=self.temp_dir)
|
37 |
+
|
38 |
+
return gr_processing_utils.encode_url_or_file_to_base64(file.name)
|
39 |
+
|
40 |
+
|
41 |
+
gr.Audio.postprocess = audio_postprocess
|
42 |
+
|
43 |
+
|
44 |
def get_text(text, hps, is_symbol):
|
45 |
text_norm = text_to_sequence(text, hps.symbols, [] if is_symbol else hps.data.text_cleaners)
|
46 |
if hps.data.add_blank:
|