Spaces:
Runtime error
Runtime error
Commit
•
cefd927
0
Parent(s):
Duplicate from MattGPT/Text-2-Speech
Browse filesCo-authored-by: Matthew Wade <[email protected]>
- .gitattributes +31 -0
- .gitignore +1 -0
- README.md +13 -0
- app.py +95 -0
- requirements.txt +5 -0
- setup.cfg +12 -0
.gitattributes
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
23 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.idea
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
duplicated_from: MattGPT/Text-2-Speech
|
11 |
+
---
|
12 |
+
|
13 |
+
Text-to-Speech interactive demo, using (balacoon_tts)[https://balacoon.com].
|
app.py
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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">Text-to-Speech</h1>
|
25 |
+
|
26 |
+
1. Write an utterance to generate,
|
27 |
+
2. Select the model to synthesize with
|
28 |
+
3. Select the speaker
|
29 |
+
4. Hit "Generate" and listen to the result!
|
30 |
+
|
31 |
+
When you select a Model for the first time,
|
32 |
+
it will take a little time to download it.
|
33 |
+
"""
|
34 |
+
)
|
35 |
+
with gr.Row(variant="panel"):
|
36 |
+
text = gr.Textbox(label="Text", placeholder="Insert your article here...")
|
37 |
+
|
38 |
+
with gr.Row():
|
39 |
+
with gr.Column(variant="panel"):
|
40 |
+
repo_files = list_repo_files(repo_id="balacoon/tts")
|
41 |
+
model_files = [x for x in repo_files if x.endswith("_cpu.addon")]
|
42 |
+
model_name = gr.Dropdown(
|
43 |
+
label="Model",
|
44 |
+
choices=model_files,
|
45 |
+
)
|
46 |
+
with gr.Column(variant="panel"):
|
47 |
+
speaker = gr.Dropdown(label="Speaker", choices=[])
|
48 |
+
|
49 |
+
def set_model(model_name_str: str):
|
50 |
+
"""
|
51 |
+
gets value from `model_name`, loads model,
|
52 |
+
re-initializes tts object, gets list of
|
53 |
+
speakers that model supports and set them to `speaker`
|
54 |
+
"""
|
55 |
+
model_path = hf_hub_download(
|
56 |
+
repo_id="balacoon/tts", filename=model_name_str
|
57 |
+
)
|
58 |
+
global tts
|
59 |
+
tts = TTS(model_path)
|
60 |
+
speakers = tts.get_speakers()
|
61 |
+
value = speakers[-1]
|
62 |
+
return gr.Dropdown.update(
|
63 |
+
choices=speakers, value=value, visible=True
|
64 |
+
)
|
65 |
+
|
66 |
+
model_name.change(set_model, inputs=model_name, outputs=speaker)
|
67 |
+
|
68 |
+
with gr.Row(variant="panel"):
|
69 |
+
generate = gr.Button("Generate")
|
70 |
+
with gr.Row(variant="panel"):
|
71 |
+
audio = gr.Audio()
|
72 |
+
|
73 |
+
def synthesize_audio(text_str: str, speaker_str: str = ""):
|
74 |
+
"""
|
75 |
+
gets utterance to synthesize from `text` Textbox
|
76 |
+
and speaker name from `speaker` dropdown list.
|
77 |
+
speaker name might be empty for single-speaker models.
|
78 |
+
Synthesizes the waveform and updates `audio` with it.
|
79 |
+
"""
|
80 |
+
if not text_str:
|
81 |
+
logging.info("text or speaker are not provided")
|
82 |
+
return None
|
83 |
+
global tts
|
84 |
+
if len(text_str) > 10024:
|
85 |
+
text_str = text_str[:10024]
|
86 |
+
samples = cast(TTS, tts).synthesize(text_str, speaker_str)
|
87 |
+
return gr.Audio.update(value=(cast(TTS, tts).get_sampling_rate(), samples))
|
88 |
+
|
89 |
+
generate.click(synthesize_audio, inputs=[text, speaker], outputs=audio)
|
90 |
+
|
91 |
+
demo.launch()
|
92 |
+
|
93 |
+
|
94 |
+
if __name__ == "__main__":
|
95 |
+
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.1.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
|