ainz Has-ai commited on
Commit
80305f7
0 Parent(s):

Duplicate from Has-ai/text-speech

Browse files

Co-authored-by: Hasmit Singla <[email protected]>

Files changed (5) hide show
  1. .gitattributes +34 -0
  2. README.md +13 -0
  3. app.py +92 -0
  4. requirements.txt +5 -0
  5. setup.cfg +12 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Text Speech
3
+ emoji: 🏆
4
+ colorFrom: yellow
5
+ colorTo: yellow
6
+ sdk: gradio
7
+ sdk_version: 3.29.0
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: Has-ai/text-speech
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ import logging
4
+ from typing import cast
5
+
6
+ import gradio as gr
7
+ from balacoon_tts import TTS
8
+ from huggingface_hub import hf_hub_download, list_repo_files
9
+
10
+
11
+ # global tts module, initialized from a model selected
12
+ tts = None
13
+
14
+
15
+ def main():
16
+ logging.basicConfig(level=logging.INFO)
17
+
18
+ with gr.Blocks() as demo:
19
+ gr.Markdown(
20
+ """
21
+ <h1 align="center">Clone your voice</h1>
22
+
23
+ 1. Write an utterance to generate,
24
+ 2. Select the model to synthesize with
25
+ 3. Select speaker
26
+ 4. Hit "Generate" and listen to the result!
27
+
28
+ When you select model for the first time,
29
+ it will take a little time to download it.
30
+ """
31
+ )
32
+ with gr.Row(variant="panel"):
33
+ text = gr.Textbox(label="Text", placeholder="Type something here...")
34
+
35
+ with gr.Row():
36
+ with gr.Column(variant="panel"):
37
+ repo_files = list_repo_files(repo_id="balacoon/tts")
38
+ model_files = [x for x in repo_files if x.endswith("_cpu.addon")]
39
+ model_name = gr.Dropdown(
40
+ label="Model",
41
+ choices=model_files,
42
+ )
43
+ with gr.Column(variant="panel"):
44
+ speaker = gr.Dropdown(label="Speaker", choices=[])
45
+
46
+ def set_model(model_name_str: str):
47
+ """
48
+ gets value from `model_name`, loads model,
49
+ re-initializes tts object, gets list of
50
+ speakers that model supports and set them to `speaker`
51
+ """
52
+ model_path = hf_hub_download(
53
+ repo_id="balacoon/tts", filename=model_name_str
54
+ )
55
+ global tts
56
+ tts = TTS(model_path)
57
+ speakers = tts.get_speakers()
58
+ value = speakers[-1]
59
+ return gr.Dropdown.update(
60
+ choices=speakers, value=value, visible=True
61
+ )
62
+
63
+ model_name.change(set_model, inputs=model_name, outputs=speaker)
64
+
65
+ with gr.Row(variant="panel"):
66
+ generate = gr.Button("Generate")
67
+ with gr.Row(variant="panel"):
68
+ audio = gr.Audio()
69
+
70
+ def synthesize_audio(text_str: str, speaker_str: str = ""):
71
+ """
72
+ gets utterance to synthesize from `text` Textbox
73
+ and speaker name from `speaker` dropdown list.
74
+ speaker name might be empty for single-speaker models.
75
+ Synthesizes the waveform and updates `audio` with it.
76
+ """
77
+ if not text_str:
78
+ logging.info("text or speaker are not provided")
79
+ return None
80
+ global tts
81
+ if len(text_str) > 1024:
82
+ text_str = text_str[:1024]
83
+ samples = cast(TTS, tts).synthesize(text_str, speaker_str)
84
+ return gr.Audio.update(value=(cast(TTS, tts).get_sampling_rate(), samples))
85
+
86
+ generate.click(synthesize_audio, inputs=[text, speaker], outputs=audio)
87
+
88
+ demo.launch()
89
+
90
+
91
+ if __name__ == "__main__":
92
+ 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