tts-webui-extension.tortoise-tts 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (19) hide show
  1. tts_webui_extension_tortoise_tts-0.0.2/LICENSE +21 -0
  2. tts_webui_extension_tortoise_tts-0.0.2/PKG-INFO +17 -0
  3. tts_webui_extension_tortoise_tts-0.0.2/README.md +47 -0
  4. tts_webui_extension_tortoise_tts-0.0.2/setup.cfg +4 -0
  5. tts_webui_extension_tortoise_tts-0.0.2/setup.py +21 -0
  6. tts_webui_extension_tortoise_tts-0.0.2/tts_webui_extension/tortoise_tts/TortoiseParameters.py +190 -0
  7. tts_webui_extension_tortoise_tts-0.0.2/tts_webui_extension/tortoise_tts/__init__.py +1 -0
  8. tts_webui_extension_tortoise_tts-0.0.2/tts_webui_extension/tortoise_tts/api.py +312 -0
  9. tts_webui_extension_tortoise_tts-0.0.2/tts_webui_extension/tortoise_tts/autoregressive_params.py +60 -0
  10. tts_webui_extension_tortoise_tts-0.0.2/tts_webui_extension/tortoise_tts/diffusion_params.py +21 -0
  11. tts_webui_extension_tortoise_tts-0.0.2/tts_webui_extension/tortoise_tts/main.py +203 -0
  12. tts_webui_extension_tortoise_tts-0.0.2/tts_webui_extension/tortoise_tts/presets.py +22 -0
  13. tts_webui_extension_tortoise_tts-0.0.2/tts_webui_extension/tortoise_tts/save_json.py +5 -0
  14. tts_webui_extension_tortoise_tts-0.0.2/tts_webui_extension/tortoise_tts/tortoise_model_settings_ui.py +72 -0
  15. tts_webui_extension_tortoise_tts-0.0.2/tts_webui_extension.tortoise_tts.egg-info/PKG-INFO +17 -0
  16. tts_webui_extension_tortoise_tts-0.0.2/tts_webui_extension.tortoise_tts.egg-info/SOURCES.txt +17 -0
  17. tts_webui_extension_tortoise_tts-0.0.2/tts_webui_extension.tortoise_tts.egg-info/dependency_links.txt +1 -0
  18. tts_webui_extension_tortoise_tts-0.0.2/tts_webui_extension.tortoise_tts.egg-info/requires.txt +1 -0
  19. tts_webui_extension_tortoise_tts-0.0.2/tts_webui_extension.tortoise_tts.egg-info/top_level.txt +3 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 rsxdalv
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,17 @@
1
+ Metadata-Version: 2.4
2
+ Name: tts_webui_extension.tortoise_tts
3
+ Version: 0.0.2
4
+ Summary: Tortoise TTS is a high-quality text-to-speech model with voice cloning capabilities
5
+ Home-page: https://github.com/rsxdalv/tts_webui_extension.tortoise
6
+ Author: rsxdalv
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ License-File: LICENSE
11
+ Requires-Dist: tts-webui.tortoise-tts
12
+ Dynamic: author
13
+ Dynamic: classifier
14
+ Dynamic: home-page
15
+ Dynamic: license-file
16
+ Dynamic: requires-dist
17
+ Dynamic: summary
@@ -0,0 +1,47 @@
1
+ # Extension adapter for Tortoise TTS
2
+
3
+ License - the source code within this repository is licensed under the MIT license.
4
+
5
+ This extension provides a high-quality text-to-speech model with voice cloning capabilities.
6
+
7
+ ## Features
8
+
9
+ - High-quality speech synthesis
10
+ - Voice cloning capabilities
11
+ - Multiple quality presets (ultra_fast, fast, standard, high_quality)
12
+ - Adjustable parameters for both autoregressive and diffusion models
13
+ - Support for custom models and tokenizers
14
+ - Split prompt functionality for long text
15
+
16
+ ## Usage
17
+
18
+ 1. Select a model (Default or custom)
19
+ 2. Choose a voice from the dropdown or upload your own voice samples
20
+ 3. Select a preset quality level
21
+ 4. Adjust parameters as needed
22
+ 5. Enter your text in the prompt field
23
+ 6. Click "Generate" to create speech
24
+
25
+ ## Advanced Options
26
+
27
+ ### Model Settings
28
+ - KV Cache: Enable for faster inference at the cost of more VRAM
29
+ - DeepSpeed: Enable for optimized performance on supported hardware
30
+ - Half Precision: Enable for reduced memory usage
31
+ - Custom Tokenizer: Upload a custom tokenizer file for specialized use cases
32
+
33
+ ### Autoregressive Parameters
34
+ - Num Autoregressive Samples: Higher values produce better quality but slower generation
35
+ - Temperature: Controls randomness in the autoregressive model
36
+ - Length Penalty: Penalizes longer sequences
37
+ - Repetition Penalty: Discourages repetitive outputs
38
+ - Top P: Controls diversity of outputs
39
+ - Max Mel Tokens: Maximum length of generated speech
40
+
41
+ ### Diffusion Parameters
42
+ - Diffusion Iterations: Higher values produce better quality but slower generation
43
+ - Cond Free: Enable for better quality
44
+ - Cond Free K: Controls the strength of conditioning
45
+ - Temperature: Controls randomness in the diffusion model
46
+
47
+ This extension uses the [Tortoise TTS](https://github.com/neonbjb/tortoise-tts) model.
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,21 @@
1
+ import setuptools
2
+
3
+ setuptools.setup(
4
+ name="tts_webui_extension.tortoise_tts",
5
+ packages=setuptools.find_namespace_packages(),
6
+ version="0.0.2",
7
+ author="rsxdalv",
8
+ description="Tortoise TTS is a high-quality text-to-speech model with voice cloning capabilities",
9
+ url="https://github.com/rsxdalv/tts_webui_extension.tortoise",
10
+ project_urls={},
11
+ scripts=[],
12
+ install_requires=[
13
+ "tts-webui.tortoise-tts"
14
+ ],
15
+ classifiers=[
16
+ "Programming Language :: Python :: 3",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Operating System :: OS Independent",
19
+ ],
20
+ )
21
+
@@ -0,0 +1,190 @@
1
+ import gradio as gr
2
+
3
+ from typing import TypedDict, Optional
4
+
5
+
6
+ class _TortoiseParametersTypedDict(TypedDict):
7
+ text: str
8
+ voice: str
9
+ preset: str
10
+ seed: Optional[int]
11
+ cvvp_amount: float
12
+ split_prompt: bool
13
+ num_autoregressive_samples: int
14
+ diffusion_iterations: int
15
+ temperature: float
16
+ length_penalty: float
17
+ repetition_penalty: float
18
+ top_p: float
19
+ max_mel_tokens: int
20
+ cond_free: bool
21
+ cond_free_k: int
22
+ diffusion_temperature: float
23
+ model: str
24
+ name: str
25
+
26
+
27
+ class TortoiseParameters:
28
+ def __init__(
29
+ self,
30
+ text: str,
31
+ voice: str = "random",
32
+ preset: str = "ultra_fast",
33
+ seed: int | None = None,
34
+ cvvp_amount: float = 0.0,
35
+ split_prompt: bool = False,
36
+ num_autoregressive_samples: int = 16,
37
+ diffusion_iterations: int = 16,
38
+ temperature: float = 0.8,
39
+ length_penalty: float = 1.0,
40
+ repetition_penalty: float = 2.0,
41
+ top_p: float = 0.8,
42
+ max_mel_tokens: int = 500,
43
+ cond_free: bool = True,
44
+ cond_free_k: int = 2,
45
+ diffusion_temperature: float = 1.0,
46
+ model: str = "Default",
47
+ name: str = "",
48
+ ): # sourcery skip: remove-unnecessary-cast
49
+ self.text = text
50
+ self.voice = voice
51
+ self.preset = preset
52
+ self.seed = seed
53
+ self.cvvp_amount = float(cvvp_amount)
54
+ self.split_prompt = split_prompt
55
+ self.num_autoregressive_samples = num_autoregressive_samples
56
+ self.diffusion_iterations = diffusion_iterations
57
+ self.temperature = float(temperature)
58
+ self.length_penalty = float(length_penalty)
59
+ self.repetition_penalty = float(repetition_penalty)
60
+ self.top_p = float(top_p)
61
+ self.max_mel_tokens = max_mel_tokens
62
+ self.cond_free = cond_free
63
+ self.cond_free_k = cond_free_k
64
+ self.diffusion_temperature = float(diffusion_temperature)
65
+ self.model = model
66
+ self.name = name
67
+
68
+ def __repr__(self):
69
+ params = ",\n ".join(f"{k}={v!r}" for k, v in self.__dict__.items())
70
+ return f"TortoiseParameters(\n {params}\n)"
71
+
72
+ def __iter__(self):
73
+ return iter(TortoiseParameterZipper.to_list(self))
74
+
75
+ def to_dict(self):
76
+ return self.__dict__
77
+
78
+ def to_metadata(self):
79
+ return {
80
+ **self.__dict__,
81
+ "seed": str(self.seed),
82
+ }
83
+
84
+ @staticmethod
85
+ def from_list(components: list):
86
+ return TortoiseParameters(
87
+ **TortoiseParameterZipper.from_list_to_dict(components)
88
+ )
89
+
90
+
91
+ class TortoiseParameterComponents:
92
+ def __init__(
93
+ self,
94
+ text: gr.Textbox,
95
+ voice: gr.Dropdown,
96
+ preset: gr.Dropdown,
97
+ seed: gr.Textbox,
98
+ cvvp_amount: gr.Slider,
99
+ split_prompt: gr.Checkbox,
100
+ num_autoregressive_samples: gr.Slider,
101
+ diffusion_iterations: gr.Slider,
102
+ temperature: gr.Slider,
103
+ length_penalty: gr.Slider,
104
+ repetition_penalty: gr.Slider,
105
+ top_p: gr.Slider,
106
+ max_mel_tokens: gr.Slider,
107
+ cond_free: gr.Checkbox,
108
+ cond_free_k: gr.Slider,
109
+ diffusion_temperature: gr.Slider,
110
+ model: gr.Dropdown,
111
+ name: gr.Textbox,
112
+ ):
113
+ self.text = text
114
+ self.voice = voice
115
+ self.preset = preset
116
+ self.seed = seed
117
+ self.cvvp_amount = cvvp_amount
118
+ self.split_prompt = split_prompt
119
+ self.num_autoregressive_samples = num_autoregressive_samples
120
+ self.diffusion_iterations = diffusion_iterations
121
+ self.temperature = temperature
122
+ self.length_penalty = length_penalty
123
+ self.repetition_penalty = repetition_penalty
124
+ self.top_p = top_p
125
+ self.max_mel_tokens = max_mel_tokens
126
+ self.cond_free = cond_free
127
+ self.cond_free_k = cond_free_k
128
+ self.diffusion_temperature = diffusion_temperature
129
+ self.model = model
130
+ self.name = name
131
+
132
+ def __repr__(self):
133
+ params = ",\n ".join(f"{k}={v!r}" for k, v in self.__dict__.items())
134
+ return f"TortoiseParameterComponents(\n {params}\n)"
135
+
136
+ def __iter__(self):
137
+ return iter(TortoiseParameterZipper.to_list(self))
138
+
139
+
140
+ class TortoiseParameterZipper:
141
+ @staticmethod
142
+ def to_list(components: TortoiseParameterComponents | TortoiseParameters):
143
+ return [
144
+ components.text,
145
+ components.voice,
146
+ components.preset,
147
+ components.seed,
148
+ components.cvvp_amount,
149
+ components.split_prompt,
150
+ components.num_autoregressive_samples,
151
+ components.diffusion_iterations,
152
+ components.temperature,
153
+ components.length_penalty,
154
+ components.repetition_penalty,
155
+ components.top_p,
156
+ components.max_mel_tokens,
157
+ components.cond_free,
158
+ components.cond_free_k,
159
+ components.diffusion_temperature,
160
+ components.model,
161
+ components.name,
162
+ ]
163
+
164
+ @staticmethod
165
+ def from_list_to_dict(components: list):
166
+ def next_idx():
167
+ next_idx.idx += 1
168
+ return next_idx.idx - 1
169
+
170
+ next_idx.idx = 0
171
+ return {
172
+ "text": components[next_idx()],
173
+ "voice": components[next_idx()],
174
+ "preset": components[next_idx()],
175
+ "seed": components[next_idx()],
176
+ "cvvp_amount": components[next_idx()],
177
+ "split_prompt": components[next_idx()],
178
+ "num_autoregressive_samples": components[next_idx()],
179
+ "diffusion_iterations": components[next_idx()],
180
+ "temperature": components[next_idx()],
181
+ "length_penalty": components[next_idx()],
182
+ "repetition_penalty": components[next_idx()],
183
+ "top_p": components[next_idx()],
184
+ "max_mel_tokens": components[next_idx()],
185
+ "cond_free": components[next_idx()],
186
+ "cond_free_k": components[next_idx()],
187
+ "diffusion_temperature": components[next_idx()],
188
+ "model": components[next_idx()],
189
+ "name": components[next_idx()],
190
+ }
@@ -0,0 +1,312 @@
1
+ import os
2
+ import numpy as np
3
+ import gradio as gr
4
+ from scipy.io.wavfile import write as write_wav
5
+
6
+ from .save_json import save_json
7
+ from tts_webui.utils.split_text_functions import split_by_lines
8
+ from tts_webui.utils.create_base_filename import create_base_filename
9
+ from tts_webui.utils.date import get_date_string
10
+ from tts_webui.utils.save_waveform_plot import middleware_save_waveform_plot
11
+ from .TortoiseParameters import TortoiseParameters
12
+ from tts_webui.utils.get_path_from_root import get_path_from_root
13
+ from tts_webui.utils.torch_clear_memory import torch_clear_memory
14
+
15
+
16
+ SAMPLE_RATE = 24_000
17
+ OUTPUT_PATH = "outputs/"
18
+
19
+ MODEL = None
20
+ TORTOISE_VOICE_DIR = "voices-tortoise"
21
+
22
+ TORTOISE_VOICE_DIR_ABS = get_path_from_root("voices-tortoise")
23
+ TORTOISE_LOCAL_MODELS_DIR = get_path_from_root("data", "models", "tortoise")
24
+
25
+
26
+ class TortoiseOutputUpdate:
27
+ def __init__(
28
+ self,
29
+ audio,
30
+ bundle_name,
31
+ params,
32
+ ):
33
+ self.audio = audio
34
+ self.bundle_name = bundle_name
35
+ self.params = params
36
+
37
+
38
+ def get_model_list():
39
+ try:
40
+ return ["Default"] + [
41
+ x for x in os.listdir(TORTOISE_LOCAL_MODELS_DIR) if x != ".gitkeep"
42
+ ]
43
+ except FileNotFoundError as e:
44
+ print(e)
45
+ return ["Default"]
46
+
47
+
48
+ def get_full_model_dir(model_dir: str):
49
+ return os.path.join(TORTOISE_LOCAL_MODELS_DIR, model_dir)
50
+
51
+
52
+ def switch_model(
53
+ model_dir: str,
54
+ kv_cache=False,
55
+ use_deepspeed=False,
56
+ half=False,
57
+ tokenizer=None,
58
+ use_basic_cleaners=False,
59
+ ):
60
+ from tortoise.api import MODELS_DIR
61
+
62
+ get_tts(
63
+ models_dir=(
64
+ MODELS_DIR if model_dir == "Default" else get_full_model_dir(model_dir)
65
+ ),
66
+ force_reload=True,
67
+ kv_cache=kv_cache,
68
+ use_deepspeed=use_deepspeed,
69
+ half=half,
70
+ tokenizer_path=tokenizer.name if tokenizer else None,
71
+ tokenizer_basic=use_basic_cleaners,
72
+ )
73
+ return gr.Dropdown()
74
+
75
+
76
+ def get_voice_list():
77
+ from tortoise.utils.audio import get_voices
78
+
79
+ return ["random"] + list(get_voices(extra_voice_dirs=[TORTOISE_VOICE_DIR]))
80
+
81
+
82
+ def save_wav_tortoise(audio_array, filename):
83
+ write_wav(filename, SAMPLE_RATE, audio_array)
84
+
85
+
86
+ def unload_tortoise_model():
87
+ global MODEL
88
+ if MODEL is not None:
89
+ del MODEL
90
+ torch_clear_memory()
91
+ MODEL = None
92
+
93
+
94
+ def get_tts(
95
+ models_dir=None,
96
+ force_reload=False,
97
+ kv_cache=False,
98
+ use_deepspeed=False,
99
+ half=False,
100
+ device=None,
101
+ tokenizer_path=None,
102
+ tokenizer_basic=False,
103
+ ):
104
+ from tortoise.api import MODELS_DIR, TextToSpeech
105
+
106
+ if models_dir is None:
107
+ models_dir = MODELS_DIR
108
+ global MODEL
109
+ if MODEL is None or force_reload:
110
+ print("Loading tortoise model: ", models_dir)
111
+ print("Clearing memory...")
112
+ unload_tortoise_model()
113
+ print("Memory cleared")
114
+ print("Loading model...")
115
+ MODEL = TextToSpeech(
116
+ models_dir=models_dir,
117
+ kv_cache=kv_cache,
118
+ use_deepspeed=use_deepspeed,
119
+ half=half,
120
+ device=device,
121
+ tokenizer_vocab_file=tokenizer_path,
122
+ tokenizer_basic=tokenizer_basic,
123
+ )
124
+ print("Model loaded")
125
+ return MODEL
126
+
127
+
128
+ last_voices = None
129
+ voice_samples = None
130
+ conditioning_latents = None
131
+
132
+
133
+ def get_voices_cached(voice):
134
+ from tortoise.utils.audio import load_voices
135
+
136
+ global last_voices, voice_samples, conditioning_latents
137
+
138
+ if voice == last_voices:
139
+ last_voices = voice
140
+ return voice_samples, conditioning_latents
141
+
142
+ voices = voice.split("&") if "&" in voice else [voice]
143
+
144
+ voice_samples, conditioning_latents = load_voices(
145
+ voices, extra_voice_dirs=[TORTOISE_VOICE_DIR]
146
+ )
147
+ last_voices = voices
148
+ return voice_samples, conditioning_latents
149
+
150
+
151
+ def generate_tortoise(
152
+ params: TortoiseParameters,
153
+ text: str,
154
+ candidates: int,
155
+ ):
156
+ os.makedirs(OUTPUT_PATH, exist_ok=True)
157
+
158
+ voice_samples, conditioning_latents = get_voices_cached(params.voice)
159
+
160
+ tts = get_tts()
161
+ result, state = tts.tts_with_preset(
162
+ text,
163
+ return_deterministic_state=True,
164
+ k=candidates,
165
+ voice_samples=voice_samples,
166
+ conditioning_latents=conditioning_latents,
167
+ use_deterministic_seed=get_seed(params),
168
+ **{
169
+ k: v
170
+ for k, v in params.to_dict().items()
171
+ if k not in ["text", "voice", "split_prompt", "seed", "model", "name"]
172
+ },
173
+ )
174
+
175
+ seed, _, _, _ = state
176
+ params.seed = seed # type: ignore
177
+
178
+ gen_list = result if isinstance(result, list) else [result]
179
+ audio_arrays = [tensor_to_audio_array(x) for x in gen_list]
180
+ return [
181
+ _process_gen(candidates, audio_array, id, params)
182
+ for id, audio_array in enumerate(audio_arrays)
183
+ ]
184
+
185
+
186
+ def get_seed(params):
187
+ return params.seed if params.seed != -1 else None
188
+
189
+
190
+ def _process_gen(candidates, audio_array, id, params: TortoiseParameters):
191
+ model = "tortoise"
192
+ date = get_date_string()
193
+
194
+ name = params.name or params.voice
195
+ filename, filename_png, filename_json = get_filenames(
196
+ create_base_filename_tortoise(name, id, model, date)
197
+ )
198
+ save_wav_tortoise(audio_array, filename)
199
+ middleware_save_waveform_plot(audio_array, filename_png)
200
+
201
+ metadata = {
202
+ "_version": "0.0.1",
203
+ "_type": model,
204
+ "date": date,
205
+ "candidates": candidates,
206
+ "index": id if isinstance(id, int) else 0,
207
+ **params.to_metadata(),
208
+ }
209
+
210
+ save_json(filename_json, metadata)
211
+
212
+ folder_root = os.path.dirname(filename)
213
+
214
+ return TortoiseOutputUpdate(
215
+ audio=(SAMPLE_RATE, audio_array),
216
+ bundle_name=folder_root,
217
+ params=gr.JSON(value=metadata), # broken because gradio returns only __type__
218
+ )
219
+
220
+
221
+ def create_base_filename_tortoise(name, j, model, date):
222
+ return f"{create_base_filename(f'{name}__n{j}', OUTPUT_PATH, model, date)}"
223
+
224
+
225
+ def tensor_to_audio_array(gen):
226
+ return gen.squeeze(0).cpu().t().numpy()
227
+
228
+
229
+ def get_filenames(base_filename):
230
+ filename = f"{base_filename}.wav"
231
+ filename_png = f"{base_filename}.png"
232
+ filename_json = f"{base_filename}.json"
233
+ return filename, filename_png, filename_json
234
+
235
+
236
+ def generate_tortoise_long(count: int, params: TortoiseParameters):
237
+ print("Generating tortoise with params:")
238
+ print(params)
239
+ prompt_raw = params.text
240
+ split_prompt = params.split_prompt
241
+
242
+ prompts = split_by_lines(prompt_raw) if split_prompt else [prompt_raw]
243
+ audio_pieces = [[] for _ in range(count)]
244
+
245
+ for prompt in prompts:
246
+ datas = generate_tortoise(
247
+ params,
248
+ text=prompt,
249
+ candidates=count,
250
+ )
251
+ for data in datas:
252
+ yield [data.audio, data.bundle_name, data.params]
253
+
254
+ for i in range(count):
255
+ audio_array = datas[i].audio[1]
256
+ audio_pieces[i].append(audio_array)
257
+
258
+ # if there is only one prompt, then we don't need to concatenate
259
+ if len(prompts) == 1:
260
+ # return [None, None, None]
261
+ return {}
262
+
263
+ for i in range(count):
264
+ res = _process_gen(
265
+ count, np.concatenate(audio_pieces[i]), id=f"_long_{str(i)}", params=params
266
+ )
267
+ yield [res.audio, res.bundle_name, res.params]
268
+
269
+ # return [None, None, None]
270
+ return {}
271
+
272
+ def tts(
273
+ text: str,
274
+ voice: str = "random",
275
+ preset: str = "ultra_fast",
276
+ seed: int | None = None,
277
+ cvvp_amount: float = 0.0,
278
+ split_prompt: bool = False,
279
+ num_autoregressive_samples: int = 16,
280
+ diffusion_iterations: int = 16,
281
+ temperature: float = 0.8,
282
+ length_penalty: float = 1.0,
283
+ repetition_penalty: float = 2.0,
284
+ top_p: float = 0.8,
285
+ max_mel_tokens: int = 500,
286
+ cond_free: bool = True,
287
+ cond_free_k: int = 2,
288
+ diffusion_temperature: float = 1.0,
289
+ model: str = "Default",
290
+ name: str = "",
291
+ ):
292
+ result = next(generate_tortoise_long(1, TortoiseParameters(
293
+ text=text,
294
+ voice=voice,
295
+ preset=preset,
296
+ seed=seed,
297
+ cvvp_amount=cvvp_amount,
298
+ split_prompt=split_prompt,
299
+ num_autoregressive_samples=num_autoregressive_samples,
300
+ diffusion_iterations=diffusion_iterations,
301
+ temperature=temperature,
302
+ length_penalty=length_penalty,
303
+ repetition_penalty=repetition_penalty,
304
+ top_p=top_p,
305
+ max_mel_tokens=max_mel_tokens,
306
+ cond_free=cond_free,
307
+ cond_free_k=cond_free_k,
308
+ diffusion_temperature=diffusion_temperature,
309
+ model=model,
310
+ name=name,
311
+ )))
312
+ return result
@@ -0,0 +1,60 @@
1
+ import gradio as gr
2
+
3
+
4
+ def autoregressive_params():
5
+ with gr.Accordion(label="Autoregressive Parameters", open=False):
6
+ samples = gr.Slider(
7
+ label="Samples",
8
+ value=16,
9
+ minimum=4,
10
+ maximum=256,
11
+ step=1,
12
+ )
13
+
14
+ temperature = gr.Slider(
15
+ label="Temperature",
16
+ value=0.8,
17
+ minimum=0.0,
18
+ maximum=1.0,
19
+ step=0.1,
20
+ )
21
+
22
+ length_penalty = gr.Slider(
23
+ label="Length Penalty",
24
+ value=1.0,
25
+ minimum=0.0,
26
+ maximum=10.0,
27
+ step=0.1,
28
+ )
29
+
30
+ repetition_penalty = gr.Slider(
31
+ label="Repetition Penalty",
32
+ value=2.0,
33
+ minimum=0.0,
34
+ maximum=10.0,
35
+ step=0.1,
36
+ )
37
+
38
+ top_p = gr.Slider(
39
+ label="Top P",
40
+ value=0.8,
41
+ minimum=0.0,
42
+ maximum=1.0,
43
+ step=0.1,
44
+ )
45
+ max_mel_tokens = gr.Slider(
46
+ label="Max Mel Tokens",
47
+ value=500,
48
+ minimum=10,
49
+ maximum=600,
50
+ step=1,
51
+ )
52
+
53
+ return (
54
+ samples,
55
+ temperature,
56
+ length_penalty,
57
+ repetition_penalty,
58
+ top_p,
59
+ max_mel_tokens,
60
+ )
@@ -0,0 +1,21 @@
1
+ import gradio as gr
2
+
3
+
4
+ def diffusion_params():
5
+ with gr.Accordion(label="Diffusion Parameters", open=False):
6
+ iterations = gr.Slider(
7
+ label="Diffusion Iterations", value=30, minimum=4, maximum=400, step=1
8
+ )
9
+ cond_free = gr.Checkbox(label="Cond Free", value=False)
10
+ cond_free_k = gr.Slider(
11
+ label="Cond Free K", value=2, minimum=0, maximum=10, step=1
12
+ )
13
+ diffusion_temperature = gr.Slider(
14
+ label="Temperature",
15
+ value=1.0,
16
+ minimum=0.0,
17
+ maximum=1.0,
18
+ step=0.1,
19
+ )
20
+
21
+ return iterations, cond_free, cond_free_k, diffusion_temperature
@@ -0,0 +1,203 @@
1
+ import gradio as gr
2
+
3
+ from .api import (
4
+ generate_tortoise_long,
5
+ get_voice_list,
6
+ TORTOISE_VOICE_DIR_ABS,
7
+ )
8
+ from .TortoiseParameters import (
9
+ TortoiseParameterComponents,
10
+ TortoiseParameters,
11
+ )
12
+ from .autoregressive_params import autoregressive_params
13
+ from .diffusion_params import diffusion_params
14
+ from .presets import presets
15
+ from gradio_iconbutton import IconButton
16
+ from .tortoise_model_settings_ui import tortoise_model_settings_ui
17
+ from tts_webui.utils.OpenFolderButton import OpenFolderButton
18
+ from tts_webui.utils.randomize_seed import randomize_seed_ui
19
+ from tts_webui.decorators.gradio_dict_decorator import dictionarize
20
+
21
+ MAX_OUTPUTS = 9
22
+
23
+
24
+ def ui():
25
+ with gr.Row():
26
+ with gr.Column():
27
+ model = tortoise_model_settings_ui()
28
+ with gr.Column():
29
+ gr.Markdown("Voice")
30
+ with gr.Row():
31
+ voice = gr.Dropdown(
32
+ choices=["Press refresh to load the list"],
33
+ value="Press refresh to load the list",
34
+ show_label=False,
35
+ container=False,
36
+ allow_custom_value=True,
37
+ )
38
+ OpenFolderButton(TORTOISE_VOICE_DIR_ABS, api_name="tortoise_open_voices")
39
+ IconButton("refresh").click(
40
+ fn=lambda: gr.Dropdown(choices=get_voice_list()),
41
+ outputs=[voice],
42
+ api_name="tortoise_refresh_voices",
43
+ )
44
+ with gr.Column():
45
+ gr.Markdown("Preset")
46
+ preset = gr.Dropdown(
47
+ show_label=False,
48
+ choices=[
49
+ "ultra_fast",
50
+ "fast",
51
+ "standard",
52
+ "high_quality",
53
+ ],
54
+ value="ultra_fast",
55
+ container=False,
56
+ )
57
+
58
+ (
59
+ num_autoregressive_samples,
60
+ temperature,
61
+ length_penalty,
62
+ repetition_penalty,
63
+ top_p,
64
+ max_mel_tokens,
65
+ ) = autoregressive_params()
66
+
67
+ with gr.Column():
68
+ cvvp_amount = gr.Slider(
69
+ label="CVVP Amount (Deprecated, always 0)",
70
+ value=0.0,
71
+ minimum=0.0,
72
+ maximum=1.0,
73
+ step=0.1,
74
+ interactive=False,
75
+ )
76
+ seed, randomize_seed_callback = randomize_seed_ui()
77
+
78
+ split_prompt = gr.Checkbox(label="Split prompt by lines", value=False)
79
+
80
+ (
81
+ diffusion_iterations,
82
+ cond_free,
83
+ cond_free_k,
84
+ diffusion_temperature,
85
+ ) = diffusion_params()
86
+
87
+ name = gr.Textbox(label="Generation Name", placeholder="Enter name here...")
88
+
89
+ preset.change(
90
+ fn=lambda x: [
91
+ gr.Slider(value=presets[x]["num_autoregressive_samples"]),
92
+ gr.Slider(value=presets[x]["diffusion_iterations"]),
93
+ gr.Checkbox(
94
+ value=presets[x]["cond_free"] if "cond_free" in presets[x] else True
95
+ ),
96
+ ],
97
+ inputs=[preset],
98
+ outputs=[num_autoregressive_samples, diffusion_iterations, cond_free],
99
+ )
100
+
101
+ text = gr.Textbox(label="Prompt", lines=3, placeholder="Enter text here...")
102
+
103
+ inputs = list(
104
+ TortoiseParameterComponents(
105
+ text=text,
106
+ voice=voice,
107
+ preset=preset,
108
+ seed=seed,
109
+ cvvp_amount=cvvp_amount,
110
+ split_prompt=split_prompt,
111
+ num_autoregressive_samples=num_autoregressive_samples,
112
+ diffusion_iterations=diffusion_iterations,
113
+ temperature=temperature,
114
+ length_penalty=length_penalty,
115
+ repetition_penalty=repetition_penalty,
116
+ top_p=top_p,
117
+ max_mel_tokens=max_mel_tokens,
118
+ cond_free=cond_free,
119
+ cond_free_k=cond_free_k,
120
+ diffusion_temperature=diffusion_temperature,
121
+ model=model,
122
+ name=name,
123
+ )
124
+ )
125
+
126
+ with gr.Column():
127
+ audio = gr.Audio(type="filepath", label="Generated audio")
128
+ folder_root = gr.Textbox(visible=False)
129
+ metadata = gr.JSON(visible=False)
130
+ with gr.Row():
131
+ from tts_webui.history_tab.save_to_favorites import save_to_favorites
132
+
133
+ gr.Button("Save to favorites").click(
134
+ fn=save_to_favorites,
135
+ inputs=[folder_root],
136
+ )
137
+
138
+ def generate_button(count):
139
+ def gen(*args):
140
+ yield from generate_tortoise_long(
141
+ count,
142
+ TortoiseParameters.from_list(list(args)),
143
+ )
144
+
145
+ return (
146
+ gr.Button(
147
+ value=f"Generate {count if count > 1 else ''}",
148
+ variant="primary" if count == 1 else "secondary",
149
+ )
150
+ .click(**randomize_seed_callback)
151
+ .then(
152
+ fn=gen,
153
+ inputs=inputs,
154
+ outputs=[audio, folder_root, metadata],
155
+ api_name=f"generate_tortoise_{count}",
156
+ # **dictionarize(
157
+ # fn=gen,
158
+ # inputs=inputs_dict,
159
+ # outputs={
160
+ # "audio_out": audio,
161
+ # "folder_root": folder_root,
162
+ # "metadata": metadata,
163
+ # },
164
+ # ),
165
+ )
166
+ )
167
+
168
+ with gr.Row():
169
+ for i in range(MAX_OUTPUTS):
170
+ generate_button(MAX_OUTPUTS - i)
171
+
172
+
173
+ def extension__tts_generation_webui():
174
+ ui()
175
+
176
+ return {
177
+ "package_name": "tts_webui_extension.tortoise_tts",
178
+ "name": "Tortoise TTS",
179
+ "requirements": "git+https://github.com/rsxdalv/tts_webui_extension.tortoise_tts@main",
180
+ "description": "Tortoise TTS is a high-quality text-to-speech model with voice cloning capabilities",
181
+ "extension_type": "interface",
182
+ "extension_class": "text-to-speech",
183
+ "author": "neonbjb",
184
+ "extension_author": "rsxdalv",
185
+ "license": "MIT",
186
+ "website": "https://github.com/neonbjb/tortoise-tts",
187
+ "extension_website": "https://github.com/rsxdalv/tts_webui_extension.tortoise_tts",
188
+ "extension_platform_version": "0.0.1",
189
+ }
190
+
191
+
192
+ if __name__ == "__main__":
193
+ if "demo" in locals():
194
+ locals()["demo"].close()
195
+ from tts_webui.gradio.css import full_css
196
+
197
+ with gr.Blocks(css=full_css) as demo:
198
+ with gr.Tab("Tortoise TTS"):
199
+ ui()
200
+
201
+ demo.launch(
202
+ server_port=7771,
203
+ )
@@ -0,0 +1,22 @@
1
+ presets = {
2
+ "ultra_fast": {
3
+ "num_autoregressive_samples": 16,
4
+ "diffusion_iterations": 16,
5
+ "cond_free": True,
6
+ },
7
+ "fast": {
8
+ "num_autoregressive_samples": 96,
9
+ "diffusion_iterations": 80,
10
+ "cond_free": True,
11
+ },
12
+ "standard": {
13
+ "num_autoregressive_samples": 256,
14
+ "diffusion_iterations": 200,
15
+ "cond_free": True,
16
+ },
17
+ "high_quality": {
18
+ "num_autoregressive_samples": 256,
19
+ "diffusion_iterations": 400,
20
+ "cond_free": True,
21
+ },
22
+ }
@@ -0,0 +1,5 @@
1
+ def save_json(filename: str, data):
2
+ import json
3
+
4
+ with open(filename, "w") as f:
5
+ json.dump(data, f)
@@ -0,0 +1,72 @@
1
+ import gradio as gr
2
+ from .gen_tortoise import (
3
+ TORTOISE_LOCAL_MODELS_DIR,
4
+ get_model_list,
5
+ switch_model,
6
+ unload_tortoise_model,
7
+ )
8
+ from gradio_iconbutton import IconButton
9
+ from tts_webui.utils.OpenFolderButton import OpenFolderButton
10
+
11
+
12
+ def tortoise_model_settings_ui_inner():
13
+ with gr.Row():
14
+ model = gr.Dropdown(
15
+ choices=get_model_list(),
16
+ value="Default",
17
+ show_label=False,
18
+ container=False,
19
+ )
20
+ OpenFolderButton(TORTOISE_LOCAL_MODELS_DIR, api_name="tortoise_open_models")
21
+ IconButton("refresh").click(
22
+ fn=lambda: gr.Dropdown(choices=get_model_list()),
23
+ outputs=[model],
24
+ api_name="tortoise_refresh_models",
25
+ )
26
+
27
+ with gr.Row():
28
+ kv_cache = gr.Checkbox(label="KV Cache", value=False)
29
+ use_deepspeed = gr.Checkbox(label="Use Deepspeed", value=False)
30
+ half = gr.Checkbox(label="Half", value=False)
31
+ use_basic_cleaners = gr.Checkbox(label="Use basic cleaners", value=False)
32
+ tokenizer = gr.File(
33
+ label="Tokenizer",
34
+ file_types=[".json"],
35
+ )
36
+
37
+ unload_model = gr.Button(
38
+ "Unload model",
39
+ variant="secondary",
40
+ )
41
+
42
+ unload_model.click(
43
+ fn=unload_tortoise_model,
44
+ api_name="tortoise_unload_model",
45
+ )
46
+
47
+ apply_model_settings = gr.Button(
48
+ "Apply model settings",
49
+ variant="secondary",
50
+ )
51
+
52
+ apply_model_settings.click(
53
+ fn=switch_model,
54
+ inputs=[model, kv_cache, use_deepspeed, half, tokenizer, use_basic_cleaners],
55
+ outputs=[model],
56
+ api_name="tortoise_apply_model_settings",
57
+ )
58
+
59
+ model.select(
60
+ fn=switch_model,
61
+ inputs=[model, kv_cache, use_deepspeed, half, tokenizer, use_basic_cleaners],
62
+ outputs=[model],
63
+ )
64
+
65
+ return model
66
+
67
+
68
+ def tortoise_model_settings_ui():
69
+ with gr.Column():
70
+ gr.Markdown("Model")
71
+ with gr.Column():
72
+ return tortoise_model_settings_ui_inner()
@@ -0,0 +1,17 @@
1
+ Metadata-Version: 2.4
2
+ Name: tts_webui_extension.tortoise_tts
3
+ Version: 0.0.2
4
+ Summary: Tortoise TTS is a high-quality text-to-speech model with voice cloning capabilities
5
+ Home-page: https://github.com/rsxdalv/tts_webui_extension.tortoise
6
+ Author: rsxdalv
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ License-File: LICENSE
11
+ Requires-Dist: tts-webui.tortoise-tts
12
+ Dynamic: author
13
+ Dynamic: classifier
14
+ Dynamic: home-page
15
+ Dynamic: license-file
16
+ Dynamic: requires-dist
17
+ Dynamic: summary
@@ -0,0 +1,17 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ tts_webui_extension.tortoise_tts.egg-info/PKG-INFO
5
+ tts_webui_extension.tortoise_tts.egg-info/SOURCES.txt
6
+ tts_webui_extension.tortoise_tts.egg-info/dependency_links.txt
7
+ tts_webui_extension.tortoise_tts.egg-info/requires.txt
8
+ tts_webui_extension.tortoise_tts.egg-info/top_level.txt
9
+ tts_webui_extension/tortoise_tts/TortoiseParameters.py
10
+ tts_webui_extension/tortoise_tts/__init__.py
11
+ tts_webui_extension/tortoise_tts/api.py
12
+ tts_webui_extension/tortoise_tts/autoregressive_params.py
13
+ tts_webui_extension/tortoise_tts/diffusion_params.py
14
+ tts_webui_extension/tortoise_tts/main.py
15
+ tts_webui_extension/tortoise_tts/presets.py
16
+ tts_webui_extension/tortoise_tts/save_json.py
17
+ tts_webui_extension/tortoise_tts/tortoise_model_settings_ui.py