Spaces:
Runtime error
Runtime error
Commit
·
d1d085b
1
Parent(s):
6fa7850
last code forgot input and output . just here to fix that.(lets hope )
Browse files
app.py
CHANGED
@@ -15,55 +15,52 @@ def read_pdf(file):
|
|
15 |
|
16 |
def main():
|
17 |
logging.basicConfig(level=logging.INFO)
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
speaker = gr.inputs.Dropdown(label="Speaker", choices=[])
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
|
38 |
-
|
39 |
|
40 |
-
|
41 |
-
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
|
61 |
-
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
iface.fn = synthesize_audio
|
66 |
-
iface.launch()
|
67 |
|
68 |
|
69 |
if __name__ == "__main__":
|
|
|
15 |
|
16 |
def main():
|
17 |
logging.basicConfig(level=logging.INFO)
|
18 |
+
repo_files = list_repo_files(repo_id="balacoon/tts")
|
19 |
+
model_files = [x for x in repo_files if x.endswith("_cpu.addon")]
|
20 |
+
model_name = gr.inputs.Dropdown(label="Model", choices=model_files)
|
21 |
+
speaker = gr.inputs.Dropdown(label="Speaker", choices=[])
|
|
|
22 |
|
23 |
+
def set_model(model_name_str):
|
24 |
+
"""
|
25 |
+
Gets value from `model_name`, loads the model,
|
26 |
+
re-initializes the tts object, and gets a list of
|
27 |
+
speakers that the model supports and sets them to `speaker`.
|
28 |
+
"""
|
29 |
+
model_path = hf_hub_download(repo_id="balacoon/tts", filename=model_name_str)
|
30 |
+
global tts
|
31 |
+
tts = TTS(model_path)
|
32 |
+
speakers = tts.get_speakers()
|
33 |
+
value = speakers[-1]
|
34 |
+
speaker.choices = speakers
|
35 |
+
speaker.value = value
|
36 |
|
37 |
+
model_name.onChange(set_model)
|
38 |
|
39 |
+
file_input = gr.inputs.File(label="Select a PDF File", type="file")
|
40 |
+
text = gr.outputs.Textbox()
|
41 |
|
42 |
+
def synthesize_audio(file, model_name_str, speaker_str):
|
43 |
+
"""
|
44 |
+
Gets the selected PDF `file`, model name from `model_name`,
|
45 |
+
and speaker name from `speaker`. Synthesizes the audio waveform
|
46 |
+
from the text extracted from the PDF and returns it.
|
47 |
+
"""
|
48 |
+
if file is None or file.name == "":
|
49 |
+
logging.info("No file selected.")
|
50 |
+
return None
|
51 |
|
52 |
+
text_str = read_pdf(file)
|
53 |
+
if len(text_str) > 1024:
|
54 |
+
text_str = text_str[:1024]
|
55 |
|
56 |
+
global tts
|
57 |
+
samples = cast(TTS, tts).synthesize(text_str, speaker_str)
|
58 |
+
return (cast(TTS, tts).get_sampling_rate(), samples)
|
59 |
|
60 |
+
audio = gr.outputs.Audio(label="Generated Audio")
|
61 |
|
62 |
+
iface = gr.Interface(fn=synthesize_audio, inputs=[file_input, model_name, speaker], outputs=audio, title="PDF TO SPEECH CONVERTER", layout="rows", debug=True)
|
63 |
+
iface.launch()
|
|
|
|
|
64 |
|
65 |
|
66 |
if __name__ == "__main__":
|