Spaces:
Runtime error
Runtime error
clementruhm
commited on
Commit
•
53f8a32
1
Parent(s):
88ef979
Initial commit
Browse files- .gitignore +1 -0
- README.md +5 -5
- app.py +101 -0
- requirements.txt +5 -0
- setup.cfg +12 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.idea
|
README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.4
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
-
|
|
|
1 |
---
|
2 |
+
title: Text-to-Speech
|
3 |
+
emoji: 💬
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: yellow
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.4
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
+
Text-to-Speech interactive demo, using (balacoon_tts)[https://balacoon.com].
|
app.py
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Copyright 2022 Balacoon
|
3 |
+
|
4 |
+
TTS interactive demo
|
5 |
+
"""
|
6 |
+
|
7 |
+
import logging
|
8 |
+
from typing import cast
|
9 |
+
|
10 |
+
import gradio as gr
|
11 |
+
from balacoon_tts import TTS
|
12 |
+
from huggingface_hub import hf_hub_download, list_repo_files
|
13 |
+
|
14 |
+
# global tts module, initialized from a model selected
|
15 |
+
tts = None
|
16 |
+
|
17 |
+
|
18 |
+
def main():
|
19 |
+
logging.basicConfig(level=logging.INFO)
|
20 |
+
|
21 |
+
with gr.Blocks() as demo:
|
22 |
+
gr.Markdown(
|
23 |
+
"""
|
24 |
+
<h1 align="center">Balacoon🦝 Text-to-Speech</h1>
|
25 |
+
|
26 |
+
1. Write an utterance to generate,
|
27 |
+
2. Select the model to synthesize with
|
28 |
+
3. Select speaker (only for multi-speaker models)
|
29 |
+
4. Hit "Generate" and listen to the result!
|
30 |
+
|
31 |
+
When you select model for the first time,
|
32 |
+
it will take around 30 seconds to download it.
|
33 |
+
You can learn more about models available
|
34 |
+
[here](https://huggingface.co/balacoon/tts),
|
35 |
+
visit [Balacoon website](https://balacoon.com/) for more info.
|
36 |
+
"""
|
37 |
+
)
|
38 |
+
with gr.Row():
|
39 |
+
text = gr.Textbox(label="Text", placeholder="Type something here...")
|
40 |
+
|
41 |
+
with gr.Row():
|
42 |
+
with gr.Column():
|
43 |
+
repo_files = list_repo_files(repo_id="balacoon/tts")
|
44 |
+
model_files = [x for x in repo_files if x.endswith(".addon")]
|
45 |
+
model_name = gr.Dropdown(
|
46 |
+
label="Model",
|
47 |
+
choices=model_files,
|
48 |
+
)
|
49 |
+
with gr.Column():
|
50 |
+
speaker = gr.Dropdown(label="Speaker", choices=[])
|
51 |
+
|
52 |
+
def set_model(model_name_str: str):
|
53 |
+
"""
|
54 |
+
gets value from `model_name`, loads model,
|
55 |
+
re-initializes tts object, gets list of
|
56 |
+
speakers that model supports and set them to `speaker`
|
57 |
+
"""
|
58 |
+
model_path = hf_hub_download(
|
59 |
+
repo_id="balacoon/tts", filename=model_name_str
|
60 |
+
)
|
61 |
+
global tts
|
62 |
+
tts = TTS(model_path)
|
63 |
+
speakers = tts.get_speakers()
|
64 |
+
if speakers:
|
65 |
+
visible = True
|
66 |
+
value = speakers[-1]
|
67 |
+
else:
|
68 |
+
visible = False
|
69 |
+
value = ""
|
70 |
+
return gr.Dropdown.update(
|
71 |
+
choices=speakers, value=value, visible=visible
|
72 |
+
)
|
73 |
+
|
74 |
+
model_name.change(set_model, inputs=model_name, outputs=speaker)
|
75 |
+
|
76 |
+
with gr.Row():
|
77 |
+
generate = gr.Button("Generate")
|
78 |
+
with gr.Row():
|
79 |
+
audio = gr.Audio()
|
80 |
+
|
81 |
+
def synthesize_audio(text_str: str, speaker_str: str = ""):
|
82 |
+
"""
|
83 |
+
gets utterance to synthesize from `text` Textbox
|
84 |
+
and speaker name from `speaker` dropdown list.
|
85 |
+
speaker name might be empty for single-speaker models.
|
86 |
+
Synthesizes the waveform and updates `audio` with it.
|
87 |
+
"""
|
88 |
+
if not text_str:
|
89 |
+
logging.info("text or speaker are not provided")
|
90 |
+
return None
|
91 |
+
global tts
|
92 |
+
samples = cast(TTS, tts).synthesize(text_str, speaker_str)
|
93 |
+
return gr.Audio.update(value=(24000, samples))
|
94 |
+
|
95 |
+
generate.click(synthesize_audio, inputs=[text, speaker], outputs=audio)
|
96 |
+
|
97 |
+
demo.launch()
|
98 |
+
|
99 |
+
|
100 |
+
if __name__ == "__main__":
|
101 |
+
main()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--index-url https://pypi.fury.io/balacoon/
|
2 |
+
--extra-index-url https://pypi.org/simple/
|
3 |
+
balacoon-tts==0.0.1
|
4 |
+
huggingface_hub
|
5 |
+
numpy
|
setup.cfg
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[flake8]
|
2 |
+
max_complexity=10
|
3 |
+
per-file-ignores=__init__.py:F401,F403
|
4 |
+
ignore = E203,W503
|
5 |
+
max-line-length=119
|
6 |
+
|
7 |
+
[isort]
|
8 |
+
profile=black
|
9 |
+
line_length=119
|
10 |
+
|
11 |
+
[mypy]
|
12 |
+
ignore_missing_imports = True
|