1littlecoder fffiloni commited on
Commit
b167d73
·
0 Parent(s):

Duplicate from fffiloni/instant-TTS-Bark-cloning

Browse files

Co-authored-by: Sylvain Filoni <fffiloni@users.noreply.huggingface.co>

.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Coqui Bark Voice Cloning
3
+ emoji: 🐸🐶
4
+ colorFrom: yellow
5
+ colorTo: gray
6
+ sdk: gradio
7
+ sdk_version: 3.40.1
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: fffiloni/instant-TTS-Bark-cloning
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,422 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from share_btn import community_icon_html, loading_icon_html, share_js
3
+ import os
4
+ import shutil
5
+
6
+ #from huggingface_hub import snapshot_download
7
+ import numpy as np
8
+ from scipy.io import wavfile
9
+ from pydub import AudioSegment
10
+
11
+ file_upload_available = os.environ.get("ALLOW_FILE_UPLOAD")
12
+
13
+ import json
14
+ with open("characters.json", "r") as file:
15
+ data = json.load(file)
16
+ characters = [
17
+ {
18
+ "image": item["image"],
19
+ "title": item["title"],
20
+ "speaker": item["speaker"]
21
+ }
22
+ for item in data
23
+ ]
24
+
25
+ """
26
+ model_ids = [
27
+ 'suno/bark',
28
+ ]
29
+
30
+ for model_id in model_ids:
31
+ model_name = model_id.split('/')[-1]
32
+ snapshot_download(model_id, local_dir=f'checkpoints/{model_name}')
33
+
34
+ from TTS.tts.configs.bark_config import BarkConfig
35
+ from TTS.tts.models.bark import Bark
36
+
37
+ #os.environ['CUDA_VISIBLE_DEVICES'] = '1'
38
+ config = BarkConfig()
39
+ model = Bark.init_from_config(config)
40
+ model.load_checkpoint(config, checkpoint_dir="checkpoints/bark", eval=True)
41
+ """
42
+ from TTS.api import TTS
43
+ tts = TTS("tts_models/multilingual/multi-dataset/bark", gpu=True)
44
+
45
+ def cut_wav(input_path, max_duration):
46
+ # Load the WAV file
47
+ audio = AudioSegment.from_wav(input_path)
48
+
49
+ # Calculate the duration of the audio
50
+ audio_duration = len(audio) / 1000 # Convert milliseconds to seconds
51
+
52
+ # Determine the duration to cut (maximum of max_duration and actual audio duration)
53
+ cut_duration = min(max_duration, audio_duration)
54
+
55
+ # Cut the audio
56
+ cut_audio = audio[:int(cut_duration * 1000)] # Convert seconds to milliseconds
57
+
58
+ # Get the input file name without extension
59
+ file_name = os.path.splitext(os.path.basename(input_path))[0]
60
+
61
+ # Construct the output file path with the original file name and "_cut" suffix
62
+ output_path = f"{file_name}_cut.wav"
63
+
64
+ # Save the cut audio as a new WAV file
65
+ cut_audio.export(output_path, format="wav")
66
+
67
+ return output_path
68
+
69
+ def update_selection(selected_state: gr.SelectData):
70
+ c_image = characters[selected_state.index]["image"]
71
+ c_title = characters[selected_state.index]["title"]
72
+ c_speaker = characters[selected_state.index]["speaker"]
73
+
74
+ return c_title, selected_state
75
+
76
+
77
+ def infer(prompt, input_wav_file):
78
+
79
+ # Path to your WAV file
80
+ source_path = input_wav_file
81
+
82
+ # Destination directory
83
+ destination_directory = "bark_voices"
84
+
85
+ # Extract the file name without the extension
86
+ file_name = os.path.splitext(os.path.basename(source_path))[0]
87
+
88
+ # Construct the full destination directory path
89
+ destination_path = os.path.join(destination_directory, file_name)
90
+
91
+ # Create the new directory
92
+ os.makedirs(destination_path, exist_ok=True)
93
+
94
+ # Move the WAV file to the new directory
95
+ shutil.move(source_path, os.path.join(destination_path, f"{file_name}.wav"))
96
+
97
+ tts.tts_to_file(text=prompt,
98
+ file_path="output.wav",
99
+ voice_dir="bark_voices/",
100
+ speaker=f"{file_name}")
101
+
102
+ # List all the files and subdirectories in the given directory
103
+ contents = os.listdir(f"bark_voices/{file_name}")
104
+
105
+ # Print the contents
106
+ for item in contents:
107
+ print(item)
108
+
109
+ tts_video = gr.make_waveform(audio="output.wav")
110
+
111
+ return "output.wav", tts_video, gr.update(value=f"bark_voices/{file_name}/{contents[1]}", visible=True), gr.Group.update(visible=True)
112
+
113
+ def infer_from_c(prompt, c_name):
114
+
115
+ tts.tts_to_file(text=prompt,
116
+ file_path="output.wav",
117
+ voice_dir="examples/library/",
118
+ speaker=f"{c_name}")
119
+
120
+ tts_video = gr.make_waveform(audio="output.wav")
121
+
122
+ return "output.wav", tts_video, gr.update(value=f"examples/library/{c_name}/{c_name}.npz", visible=True), gr.Group.update(visible=True)
123
+
124
+
125
+ css = """
126
+ #col-container {max-width: 780px; margin-left: auto; margin-right: auto;}
127
+ a {text-decoration-line: underline; font-weight: 600;}
128
+ .mic-wrap > button {
129
+ width: 100%;
130
+ height: 60px;
131
+ font-size: 1.5em!important;
132
+ }
133
+ .record-icon.svelte-1thnwz {
134
+ display: flex;
135
+ position: relative;
136
+ margin-right: var(--size-2);
137
+ width: unset;
138
+ height: unset;
139
+ }
140
+ span.record-icon > span.dot.svelte-1thnwz {
141
+ width: 20px!important;
142
+ height: 20px!important;
143
+ }
144
+ .animate-spin {
145
+ animation: spin 1s linear infinite;
146
+ }
147
+ @keyframes spin {
148
+ from {
149
+ transform: rotate(0deg);
150
+ }
151
+ to {
152
+ transform: rotate(360deg);
153
+ }
154
+ }
155
+ #share-btn-container {
156
+ display: flex;
157
+ padding-left: 0.5rem !important;
158
+ padding-right: 0.5rem !important;
159
+ background-color: #000000;
160
+ justify-content: center;
161
+ align-items: center;
162
+ border-radius: 9999px !important;
163
+ max-width: 15rem;
164
+ height: 36px;
165
+ }
166
+ div#share-btn-container > div {
167
+ flex-direction: row;
168
+ background: black;
169
+ align-items: center;
170
+ }
171
+ #share-btn-container:hover {
172
+ background-color: #060606;
173
+ }
174
+ #share-btn {
175
+ all: initial;
176
+ color: #ffffff;
177
+ font-weight: 600;
178
+ cursor:pointer;
179
+ font-family: 'IBM Plex Sans', sans-serif;
180
+ margin-left: 0.5rem !important;
181
+ padding-top: 0.5rem !important;
182
+ padding-bottom: 0.5rem !important;
183
+ right:0;
184
+ }
185
+ #share-btn * {
186
+ all: unset;
187
+ }
188
+ #share-btn-container div:nth-child(-n+2){
189
+ width: auto !important;
190
+ min-height: 0px !important;
191
+ }
192
+ #share-btn-container .wrap {
193
+ display: none !important;
194
+ }
195
+ #share-btn-container.hidden {
196
+ display: none!important;
197
+ }
198
+ img[src*='#center'] {
199
+ display: block;
200
+ margin: auto;
201
+ }
202
+ .footer {
203
+ margin-bottom: 45px;
204
+ margin-top: 10px;
205
+ text-align: center;
206
+ border-bottom: 1px solid #e5e5e5;
207
+ }
208
+ .footer>p {
209
+ font-size: .8rem;
210
+ display: inline-block;
211
+ padding: 0 10px;
212
+ transform: translateY(10px);
213
+ background: white;
214
+ }
215
+ .dark .footer {
216
+ border-color: #303030;
217
+ }
218
+ .dark .footer>p {
219
+ background: #0b0f19;
220
+ }
221
+
222
+ .disclaimer {
223
+ text-align: left;
224
+ }
225
+ .disclaimer > p {
226
+ font-size: .8rem;
227
+ }
228
+ """
229
+
230
+ with gr.Blocks(css=css) as demo:
231
+ with gr.Column(elem_id="col-container"):
232
+
233
+ gr.Markdown("""
234
+ <h1 style="text-align: center;">Coqui + Bark Voice Cloning</h1>
235
+ <p style="text-align: center;">
236
+ Mimic any voice character in less than 2 minutes with this <a href="https://tts.readthedocs.io/en/dev/models/bark.html" target="_blank">Coqui TTS + Bark</a> demo ! <br />
237
+ Upload a clean 20 seconds WAV file of the vocal persona you want to mimic, <br />
238
+ type your text-to-speech prompt and hit submit ! <br />
239
+ </p>
240
+
241
+ [![Duplicate this Space](https://huggingface.co/datasets/huggingface/badges/raw/main/duplicate-this-space-sm.svg#center)](https://huggingface.co/spaces/fffiloni/instant-TTS-Bark-cloning?duplicate=true)
242
+
243
+ """)
244
+ with gr.Row():
245
+ with gr.Column():
246
+ prompt = gr.Textbox(
247
+ label="Text to speech prompt",
248
+ elem_id = "tts-prompt"
249
+ )
250
+
251
+ with gr.Tab("File upload"):
252
+
253
+ with gr.Column():
254
+
255
+ if file_upload_available == "True":
256
+ audio_in = gr.Audio(
257
+ label="WAV voice to clone",
258
+ type="filepath",
259
+ source="upload"
260
+ )
261
+ else:
262
+ audio_in = gr.Audio(
263
+ label="WAV voice to clone",
264
+ type="filepath",
265
+ source="upload",
266
+ interactive = False
267
+ )
268
+
269
+ submit_btn = gr.Button("Submit")
270
+
271
+ with gr.Tab("Microphone"):
272
+ micro_in = gr.Audio(
273
+ label="Record voice to clone",
274
+ type="filepath",
275
+ source="microphone",
276
+ interactive = True
277
+ )
278
+ micro_submit_btn = gr.Button("Submit")
279
+
280
+ with gr.Tab("Voices Characters"):
281
+ selected_state = gr.State()
282
+ gallery_in = gr.Gallery(
283
+ label="Character Gallery",
284
+ value=[(item["image"], item["title"]) for item in characters],
285
+ interactive = True,
286
+ allow_preview=False,
287
+ columns=2,
288
+ elem_id="gallery",
289
+ show_share_button=False
290
+ )
291
+ c_submit_btn = gr.Button("Submit")
292
+
293
+
294
+ with gr.Column():
295
+
296
+ cloned_out = gr.Audio(
297
+ label="Text to speech output",
298
+ visible = False
299
+ )
300
+
301
+ video_out = gr.Video(
302
+ label = "Waveform video",
303
+ elem_id = "voice-video-out"
304
+ )
305
+
306
+ npz_file = gr.File(
307
+ label = ".npz file",
308
+ visible = False
309
+ )
310
+
311
+ character_name = gr.Textbox(
312
+ label="Character Name",
313
+ placeholder="Name that voice character",
314
+ elem_id = "character-name"
315
+ )
316
+
317
+ voice_description = gr.Textbox(
318
+ label="description",
319
+ placeholder="How would you describe that voice ? ",
320
+ elem_id = "voice-description"
321
+ )
322
+
323
+ with gr.Group(elem_id="share-btn-container", visible=False) as share_group:
324
+ community_icon = gr.HTML(community_icon_html)
325
+ loading_icon = gr.HTML(loading_icon_html)
326
+ share_button = gr.Button("Share with Community", elem_id="share-btn")
327
+
328
+ share_button.click(None, [], [], _js=share_js)
329
+
330
+ gallery_in.select(
331
+ update_selection,
332
+ outputs=[character_name, selected_state],
333
+ queue=False,
334
+ show_progress=False,
335
+ )
336
+
337
+
338
+
339
+ gr.Examples(
340
+ examples = [
341
+ [
342
+ "Once upon a time, in a cozy little shell, lived a friendly crab named Crabby. Crabby loved his cozy home, but he always felt like something was missing.",
343
+ "./examples/en_speaker_6.wav",
344
+ ],
345
+ [
346
+ "It was a typical afternoon in the bustling city, the sun shining brightly through the windows of the packed courtroom. Three people sat at the bar, their faces etched with worry and anxiety. ",
347
+ "./examples/en_speaker_9.wav",
348
+ ],
349
+ ],
350
+ fn = infer,
351
+ inputs = [
352
+ prompt,
353
+ audio_in
354
+ ],
355
+ outputs = [
356
+ cloned_out,
357
+ video_out,
358
+ npz_file,
359
+ share_group
360
+ ],
361
+ cache_examples = False
362
+ )
363
+
364
+ gr.HTML("""
365
+ <div class="footer">
366
+ <p>
367
+ Coqui + Bark Voice Cloning Demo by 🤗 <a href="https://twitter.com/fffiloni" target="_blank">Sylvain Filoni</a>
368
+ </p>
369
+ </div>
370
+ <div class="disclaimer">
371
+ <h3> * DISCLAIMER </h3>
372
+ <p>
373
+ I hold no responsibility for the utilization or outcomes of audio content produced using the semantic constructs generated by this model. <br />
374
+ Please ensure that any application of this technology remains within legal and ethical boundaries. <br />
375
+ It is important to utilize this technology for ethical and legal purposes, upholding the standards of creativity and innovation.
376
+ </p>
377
+ </div>
378
+ """)
379
+
380
+ submit_btn.click(
381
+ fn = infer,
382
+ inputs = [
383
+ prompt,
384
+ audio_in
385
+ ],
386
+ outputs = [
387
+ cloned_out,
388
+ video_out,
389
+ npz_file,
390
+ share_group
391
+ ]
392
+ )
393
+
394
+ micro_submit_btn.click(
395
+ fn = infer,
396
+ inputs = [
397
+ prompt,
398
+ micro_in
399
+ ],
400
+ outputs = [
401
+ cloned_out,
402
+ video_out,
403
+ npz_file,
404
+ share_group
405
+ ]
406
+ )
407
+
408
+ c_submit_btn.click(
409
+ fn = infer_from_c,
410
+ inputs = [
411
+ prompt,
412
+ character_name
413
+ ],
414
+ outputs = [
415
+ cloned_out,
416
+ video_out,
417
+ npz_file,
418
+ share_group
419
+ ]
420
+ )
421
+
422
+ demo.queue(api_open=False, max_size=10).launch()
bark_voices/blank.md ADDED
File without changes
characters.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "image": "examples/library/Rogue/Rogue.jpeg",
4
+ "title": "Rogue",
5
+ "speaker": "Rogue"
6
+ },
7
+ {
8
+ "image": "examples/library/Maleficent/Maleficent.jpeg",
9
+ "title": "Maleficent",
10
+ "speaker": "Maleficent"
11
+ },
12
+ {
13
+ "image": "examples/library/Kuzco/Kuzco.jpeg",
14
+ "title": "Kuzco",
15
+ "speaker": "Kuzco"
16
+ },
17
+ {
18
+ "image": "examples/library/Jasper/Jasper.jpeg",
19
+ "title": "Jasper",
20
+ "speaker": "Jasper"
21
+ }
22
+ ]
checkpoints/blank.md ADDED
File without changes
examples/blank.md ADDED
File without changes
examples/en_speaker_6.wav ADDED
Binary file (300 kB). View file
 
examples/en_speaker_9.wav ADDED
Binary file (356 kB). View file
 
examples/library/Jasper/Jasper.jpeg ADDED
examples/library/Jasper/Jasper.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eeec8431e1f96280a6404ecf166aff6850692a4b1b6e079656abec30fac1e877
3
+ size 40300
examples/library/Jasper/Jasper.wav ADDED
Binary file (563 kB). View file
 
examples/library/Kuzco/Kuzco.jpeg ADDED
examples/library/Kuzco/Kuzco.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:de9f09ff9aa6f13fe0c48f07a805db6d2554ad9ebc8b22deffe9504437adffd6
3
+ size 79036
examples/library/Kuzco/Kuzco.wav ADDED
Binary file (597 kB). View file
 
examples/library/Maleficent/Maleficent.jpeg ADDED
examples/library/Maleficent/Maleficent.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e137ad87614d6807492e0dabcfc55a7fdc2e0553644b13876dc42e996fe15fe4
3
+ size 83812
examples/library/Maleficent/Maleficent.wav ADDED
Binary file (644 kB). View file
 
examples/library/Rogue/Rogue.jpeg ADDED
examples/library/Rogue/Rogue.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cf0f3b03e7627fd925a92d3233a8b708805783f8ef5dd50ca73803c4503fc675
3
+ size 116924
examples/library/Rogue/Rogue.wav ADDED
Binary file (667 kB). View file
 
examples/library/blank.md ADDED
File without changes
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ git+https://github.com/fffiloni/TTS.git
2
+ git+https://github.com/huggingface/transformers.git
3
+ torch
4
+ scipy
5
+ pydub
share_btn.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ community_icon_html = """<svg id="share-btn-share-icon" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32">
2
+ <path d="M20.6081 3C21.7684 3 22.8053 3.49196 23.5284 4.38415C23.9756 4.93678 24.4428 5.82749 24.4808 7.16133C24.9674 7.01707 25.4353 6.93643 25.8725 6.93643C26.9833 6.93643 27.9865 7.37587 28.696 8.17411C29.6075 9.19872 30.0124 10.4579 29.8361 11.7177C29.7523 12.3177 29.5581 12.8555 29.2678 13.3534C29.8798 13.8646 30.3306 14.5763 30.5485 15.4322C30.719 16.1032 30.8939 17.5006 29.9808 18.9403C30.0389 19.0342 30.0934 19.1319 30.1442 19.2318C30.6932 20.3074 30.7283 21.5229 30.2439 22.6548C29.5093 24.3704 27.6841 25.7219 24.1397 27.1727C21.9347 28.0753 19.9174 28.6523 19.8994 28.6575C16.9842 29.4379 14.3477 29.8345 12.0653 29.8345C7.87017 29.8345 4.8668 28.508 3.13831 25.8921C0.356375 21.6797 0.754104 17.8269 4.35369 14.1131C6.34591 12.058 7.67023 9.02782 7.94613 8.36275C8.50224 6.39343 9.97271 4.20438 12.4172 4.20438H12.4179C12.6236 4.20438 12.8314 4.2214 13.0364 4.25468C14.107 4.42854 15.0428 5.06476 15.7115 6.02205C16.4331 5.09583 17.134 4.359 17.7682 3.94323C18.7242 3.31737 19.6794 3 20.6081 3ZM20.6081 5.95917C20.2427 5.95917 19.7963 6.1197 19.3039 6.44225C17.7754 7.44319 14.8258 12.6772 13.7458 14.7131C13.3839 15.3952 12.7655 15.6837 12.2086 15.6837C11.1036 15.6837 10.2408 14.5497 12.1076 13.1085C14.9146 10.9402 13.9299 7.39584 12.5898 7.1776C12.5311 7.16799 12.4731 7.16355 12.4172 7.16355C11.1989 7.16355 10.6615 9.33114 10.6615 9.33114C10.6615 9.33114 9.0863 13.4148 6.38031 16.206C3.67434 18.998 3.5346 21.2388 5.50675 24.2246C6.85185 26.2606 9.42666 26.8753 12.0653 26.8753C14.8021 26.8753 17.6077 26.2139 19.1799 25.793C19.2574 25.7723 28.8193 22.984 27.6081 20.6107C27.4046 20.212 27.0693 20.0522 26.6471 20.0522C24.9416 20.0522 21.8393 22.6726 20.5057 22.6726C20.2076 22.6726 19.9976 22.5416 19.9116 22.222C19.3433 20.1173 28.552 19.2325 27.7758 16.1839C27.639 15.6445 27.2677 15.4256 26.746 15.4263C24.4923 15.4263 19.4358 19.5181 18.3759 19.5181C18.2949 19.5181 18.2368 19.4937 18.2053 19.4419C17.6743 18.557 17.9653 17.9394 21.7082 15.6009C25.4511 13.2617 28.0783 11.8545 26.5841 10.1752C26.4121 9.98141 26.1684 9.8956 25.8725 9.8956C23.6001 9.89634 18.2311 14.9403 18.2311 14.9403C18.2311 14.9403 16.7821 16.496 15.9057 16.496C15.7043 16.496 15.533 16.4139 15.4169 16.2112C14.7956 15.1296 21.1879 10.1286 21.5484 8.06535C21.7928 6.66715 21.3771 5.95917 20.6081 5.95917Z" fill="#FF9D00"></path>
3
+ <path d="M5.50686 24.2246C3.53472 21.2387 3.67446 18.9979 6.38043 16.206C9.08641 13.4147 10.6615 9.33111 10.6615 9.33111C10.6615 9.33111 11.2499 6.95933 12.59 7.17757C13.93 7.39581 14.9139 10.9401 12.1069 13.1084C9.29997 15.276 12.6659 16.7489 13.7459 14.713C14.8258 12.6772 17.7747 7.44316 19.304 6.44221C20.8326 5.44128 21.9089 6.00204 21.5484 8.06532C21.188 10.1286 14.795 15.1295 15.4171 16.2118C16.0391 17.2934 18.2312 14.9402 18.2312 14.9402C18.2312 14.9402 25.0907 8.49588 26.5842 10.1752C28.0776 11.8545 25.4512 13.2616 21.7082 15.6008C17.9646 17.9393 17.6744 18.557 18.2054 19.4418C18.7372 20.3266 26.9998 13.1351 27.7759 16.1838C28.5513 19.2324 19.3434 20.1173 19.9117 22.2219C20.48 24.3274 26.3979 18.2382 27.6082 20.6107C28.8193 22.9839 19.2574 25.7722 19.18 25.7929C16.0914 26.62 8.24723 28.3726 5.50686 24.2246Z" fill="#FFD21E"></path>
4
+ </svg>"""
5
+
6
+ loading_icon_html = """<svg id="share-btn-loading-icon" style="display:none;" class="animate-spin"
7
+ style="color: #ffffff;
8
+ "
9
+ xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" fill="none" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><circle style="opacity: 0.25;" cx="12" cy="12" r="10" stroke="white" stroke-width="4"></circle><path style="opacity: 0.75;" fill="white" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg>"""
10
+
11
+ share_js = """async () => {
12
+ async function uploadFile(file){
13
+ const UPLOAD_URL = 'https://huggingface.co/uploads';
14
+ const response = await fetch(UPLOAD_URL, {
15
+ method: 'POST',
16
+ headers: {
17
+ 'Content-Type': file.type,
18
+ 'X-Requested-With': 'XMLHttpRequest',
19
+ },
20
+ body: file, /// <- File inherits from Blob
21
+ });
22
+ const url = await response.text();
23
+ return url;
24
+ }
25
+
26
+ async function getVideoBlobFile(videoEL){
27
+ const res = await fetch(videoEL.src);
28
+ const blob = await res.blob();
29
+ const videoId = Date.now() % 200;
30
+ const fileName = `ms-image2video-${{videoId}}.mp4`;
31
+ const videoBlob = new File([blob], fileName, { type: 'video/mp4' });
32
+ console.log(videoBlob);
33
+ return videoBlob;
34
+ }
35
+
36
+ const gradioEl = document.querySelector("gradio-app").shadowRoot || document.querySelector('body > gradio-app');
37
+ const outputVideo = gradioEl.querySelector('#voice-video-out video');
38
+ const ttsprompt = gradioEl.querySelector('#tts-prompt textarea').value;
39
+ const charaName = gradioEl.querySelector('#character-name textarea').value;
40
+ const voiceDesc = gradioEl.querySelector('#voice-description textarea').value;
41
+
42
+
43
+ const shareBtnEl = gradioEl.querySelector('#share-btn');
44
+ const shareIconEl = gradioEl.querySelector('#share-btn-share-icon');
45
+ const loadingIconEl = gradioEl.querySelector('#share-btn-loading-icon');
46
+ if(!outputVideo){
47
+ return;
48
+ };
49
+ shareBtnEl.style.pointerEvents = 'none';
50
+ shareIconEl.style.display = 'none';
51
+ loadingIconEl.style.removeProperty('display');
52
+
53
+
54
+ const videoOutFile = await getVideoBlobFile(outputVideo);
55
+ const dataOutputVid = await uploadFile(videoOutFile);
56
+
57
+ const descriptionMd = `
58
+ #### Character name:
59
+ ${charaName}
60
+
61
+ #### Voice description:
62
+ ${voiceDesc}
63
+
64
+ #### TTS Prompt:
65
+ ${ttsprompt}
66
+
67
+ #### Audio speech generated:
68
+ ${dataOutputVid}
69
+ `;
70
+ const params = new URLSearchParams({
71
+ title: "Please provide a title :)",
72
+ description: descriptionMd,
73
+ });
74
+ const paramsStr = params.toString();
75
+ window.open(`https://huggingface.co/spaces/fffiloni/instant-TTS-Bark-cloning/discussions/new?${paramsStr}`, '_blank');
76
+ shareBtnEl.style.removeProperty('pointer-events');
77
+ shareIconEl.style.removeProperty('display');
78
+ loadingIconEl.style.display = 'none';
79
+ }"""