ahassoun commited on
Commit
c9cdb67
β€’
1 Parent(s): eb21a2f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +494 -50
app.py CHANGED
@@ -1,11 +1,10 @@
1
- from TTS.api import TTS
2
- import json
3
  import gradio as gr
4
  from share_btn import community_icon_html, loading_icon_html, share_js
5
- import os
6
  import shutil
7
  import re
8
 
 
9
  import numpy as np
10
  from scipy.io import wavfile
11
  from scipy.io.wavfile import write, read
@@ -14,6 +13,7 @@ from pydub import AudioSegment
14
  file_upload_available = os.environ.get("ALLOW_FILE_UPLOAD")
15
  MAX_NUMBER_SENTENCES = 10
16
 
 
17
  with open("characters.json", "r") as file:
18
  data = json.load(file)
19
  characters = [
@@ -24,17 +24,44 @@ with open("characters.json", "r") as file:
24
  }
25
  for item in data
26
  ]
 
 
 
27
 
28
- tts = TTS("tts_models/multilingual/multi-dataset/bark", gpu=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
 
 
 
 
30
 
31
  def load_hidden_mic(audio_in):
32
  print("USER RECORDED A NEW SAMPLE")
33
-
34
- library_path = 'bark_voices'
35
- folder_name = 'audio-0-100'
36
- second_folder_name = 'audio-0-100_cleaned'
37
-
38
  folder_path = os.path.join(library_path, folder_name)
39
  second_folder_path = os.path.join(library_path, second_folder_name)
40
 
@@ -42,51 +69,184 @@ def load_hidden_mic(audio_in):
42
  if os.path.exists(folder_path):
43
  try:
44
  shutil.rmtree(folder_path)
45
- print(
46
- f"Successfully deleted the folder previously created from last raw recorded sample: {folder_path}")
47
  except OSError as e:
48
  print(f"Error: {folder_path} - {e.strerror}")
49
  else:
50
- print(
51
- f"OK, the folder a raw recorded sample does not exist: {folder_path}")
52
 
53
  if os.path.exists(second_folder_path):
54
  try:
55
  shutil.rmtree(second_folder_path)
56
- print(
57
- f"Successfully deleted the folder previously created from last cleaned recorded sample: {second_folder_path}")
58
  except OSError as e:
59
  print(f"Error: {second_folder_path} - {e.strerror}")
60
  else:
61
- print(
62
- f"Ok, the folderfor a cleaned recorded sample does not exist: {second_folder_path}")
63
-
64
  return audio_in
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
- def infer(hidden_numpy_audio):
 
 
 
68
  print("""
69
  β€”β€”β€”β€”β€”
70
  NEW INFERENCE:
71
  β€”β€”β€”β€”β€”β€”β€”
72
  """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
- prompt = "Hi mom, I have a broken tire and need a transfer. Can you send me some money please?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
  gr.Info("Generating audio from prompt")
77
  tts.tts_to_file(text=prompt,
78
- file_path="output.wav",
79
- voice_dir="bark_voices/",
80
- speaker=f"{file_name}")
81
 
 
 
 
 
 
 
82
  print("Preparing final waveform video ...")
83
  tts_video = gr.make_waveform(audio="output.wav")
84
  print(tts_video)
85
  print("FINISHED")
86
  return "output.wav", tts_video, gr.update(value=f"bark_voices/{file_name}/{contents[1]}", visible=True), gr.Group.update(visible=True), destination_path
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
 
89
  css = """
 
 
90
  .mic-wrap > button {
91
  width: 100%;
92
  height: 60px;
@@ -103,45 +263,329 @@ span.record-icon > span.dot.svelte-1thnwz {
103
  width: 20px!important;
104
  height: 20px!important;
105
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  """
107
- html_header = """
 
 
 
 
108
  <h1 style="text-align: center;">Coqui + Bark Voice Cloning</h1>
109
  <p style="text-align: center;">
110
  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 />
111
- Record a clean 20 seconds voice using the microphone provided.<br />
112
- The hard-coded TTS prompt is: β€œHi mom, I have a broken tire and need an e-transfer. Can you send me some money please?”<br />
113
  </p>
114
- """
115
 
116
- with gr.Blocks(css=css) as demo:
117
- gr.Markdown(html_header)
 
 
 
 
 
 
 
 
 
118
 
119
- micro_in = gr.Audio(
120
- label="Record voice to clone",
121
- type="filepath",
122
- source="microphone",
123
- interactive=True
124
- )
125
- hidden_audio_numpy = gr.Audio(type="numpy", visible=False)
126
- micro_submit_btn = gr.Button("Submit")
127
 
128
- micro_in.stop_recording(fn=load_hidden_mic, inputs=[micro_in], outputs=[
129
- hidden_audio_numpy], queue=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
 
131
- cloned_out = gr.Audio(
132
- label="Text to speech output",
133
- visible=False
134
- )
135
 
136
- video_out = gr.Video(
137
- label="Waveform video",
138
- elem_id="voice-video-out"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  )
140
 
141
  micro_submit_btn.click(
142
- fn=infer,
143
- inputs=[hidden_audio_numpy],
144
- outputs=[cloned_out, video_out]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  )
146
 
147
- demo.queue(api_open=False, max_size=10).launch()
 
 
 
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
  import re
6
 
7
+ #from huggingface_hub import snapshot_download
8
  import numpy as np
9
  from scipy.io import wavfile
10
  from scipy.io.wavfile import write, read
 
13
  file_upload_available = os.environ.get("ALLOW_FILE_UPLOAD")
14
  MAX_NUMBER_SENTENCES = 10
15
 
16
+ import json
17
  with open("characters.json", "r") as file:
18
  data = json.load(file)
19
  characters = [
 
24
  }
25
  for item in data
26
  ]
27
+
28
+ from TTS.api import TTS
29
+ tts = TTS("tts_models/multilingual/multi-dataset/bark", gpu=True)
30
 
31
+ def cut_wav(input_path, max_duration):
32
+ # Load the WAV file
33
+ audio = AudioSegment.from_wav(input_path)
34
+
35
+ # Calculate the duration of the audio
36
+ audio_duration = len(audio) / 1000 # Convert milliseconds to seconds
37
+
38
+ # Determine the duration to cut (maximum of max_duration and actual audio duration)
39
+ cut_duration = min(max_duration, audio_duration)
40
+
41
+ # Cut the audio
42
+ cut_audio = audio[:int(cut_duration * 1000)] # Convert seconds to milliseconds
43
+
44
+ # Get the input file name without extension
45
+ file_name = os.path.splitext(os.path.basename(input_path))[0]
46
+
47
+ # Construct the output file path with the original file name and "_cut" suffix
48
+ output_path = f"{file_name}_cut.wav"
49
+
50
+ # Save the cut audio as a new WAV file
51
+ cut_audio.export(output_path, format="wav")
52
 
53
+ return output_path
54
+
55
+ def load_hidden(audio_in):
56
+ return audio_in
57
 
58
  def load_hidden_mic(audio_in):
59
  print("USER RECORDED A NEW SAMPLE")
60
+
61
+ library_path = 'bark_voices'
62
+ folder_name = 'audio-0-100'
63
+ second_folder_name = 'audio-0-100_cleaned'
64
+
65
  folder_path = os.path.join(library_path, folder_name)
66
  second_folder_path = os.path.join(library_path, second_folder_name)
67
 
 
69
  if os.path.exists(folder_path):
70
  try:
71
  shutil.rmtree(folder_path)
72
+ print(f"Successfully deleted the folder previously created from last raw recorded sample: {folder_path}")
 
73
  except OSError as e:
74
  print(f"Error: {folder_path} - {e.strerror}")
75
  else:
76
+ print(f"OK, the folder for a raw recorded sample does not exist: {folder_path}")
 
77
 
78
  if os.path.exists(second_folder_path):
79
  try:
80
  shutil.rmtree(second_folder_path)
81
+ print(f"Successfully deleted the folder previously created from last cleaned recorded sample: {second_folder_path}")
 
82
  except OSError as e:
83
  print(f"Error: {second_folder_path} - {e.strerror}")
84
  else:
85
+ print(f"Ok, the folder for a cleaned recorded sample does not exist: {second_folder_path}")
86
+
 
87
  return audio_in
88
 
89
+ def clear_clean_ckeck():
90
+ return False
91
+
92
+ def wipe_npz_file(folder_path):
93
+ print("YO β€’ a user is manipulating audio inputs")
94
+
95
+ def split_process(audio, chosen_out_track):
96
+ gr.Info("Cleaning your audio sample...")
97
+ os.makedirs("out", exist_ok=True)
98
+ write('test.wav', audio[0], audio[1])
99
+ os.system("python3 -m demucs.separate -n mdx_extra_q -j 4 test.wav -o out")
100
+ #return "./out/mdx_extra_q/test/vocals.wav","./out/mdx_extra_q/test/bass.wav","./out/mdx_extra_q/test/drums.wav","./out/mdx_extra_q/test/other.wav"
101
+ if chosen_out_track == "vocals":
102
+ print("Audio sample cleaned")
103
+ return "./out/mdx_extra_q/test/vocals.wav"
104
+ elif chosen_out_track == "bass":
105
+ return "./out/mdx_extra_q/test/bass.wav"
106
+ elif chosen_out_track == "drums":
107
+ return "./out/mdx_extra_q/test/drums.wav"
108
+ elif chosen_out_track == "other":
109
+ return "./out/mdx_extra_q/test/other.wav"
110
+ elif chosen_out_track == "all-in":
111
+ return "test.wav"
112
+
113
+ def update_selection(selected_state: gr.SelectData):
114
+ c_image = characters[selected_state.index]["image"]
115
+ c_title = characters[selected_state.index]["title"]
116
+ c_speaker = characters[selected_state.index]["speaker"]
117
 
118
+ return c_title, selected_state
119
+
120
+
121
+ def infer(prompt, input_wav_file, clean_audio, hidden_numpy_audio):
122
  print("""
123
  β€”β€”β€”β€”β€”
124
  NEW INFERENCE:
125
  β€”β€”β€”β€”β€”β€”β€”
126
  """)
127
+ if prompt == "":
128
+ gr.Warning("Do not forget to provide a tts prompt !")
129
+
130
+ if clean_audio is True :
131
+ print("We want to clean audio sample")
132
+ # Extract the file name without the extension
133
+ new_name = os.path.splitext(os.path.basename(input_wav_file))[0]
134
+ print(f"FILE BASENAME is: {new_name}")
135
+ if os.path.exists(os.path.join("bark_voices", f"{new_name}_cleaned")):
136
+ print("This file has already been cleaned")
137
+ check_name = os.path.join("bark_voices", f"{new_name}_cleaned")
138
+ source_path = os.path.join(check_name, f"{new_name}_cleaned.wav")
139
+ else:
140
+ print("This file is new, we need to clean and store it")
141
+ source_path = split_process(hidden_numpy_audio, "vocals")
142
+
143
+ # Rename the file
144
+ new_path = os.path.join(os.path.dirname(source_path), f"{new_name}_cleaned.wav")
145
+ os.rename(source_path, new_path)
146
+ source_path = new_path
147
+ else :
148
+ print("We do NOT want to clean audio sample")
149
+ # Path to your WAV file
150
+ source_path = input_wav_file
151
+
152
+ # Destination directory
153
+ destination_directory = "bark_voices"
154
+
155
+ # Extract the file name without the extension
156
+ file_name = os.path.splitext(os.path.basename(source_path))[0]
157
+
158
+ # Construct the full destination directory path
159
+ destination_path = os.path.join(destination_directory, file_name)
160
+
161
+ # Create the new directory
162
+ os.makedirs(destination_path, exist_ok=True)
163
 
164
+ # Move the WAV file to the new directory
165
+ shutil.move(source_path, os.path.join(destination_path, f"{file_name}.wav"))
166
+
167
+ # β€”β€”β€”β€”β€”
168
+
169
+ # Split the text into sentences based on common punctuation marks
170
+ sentences = re.split(r'(?<=[.!?])\s+', prompt)
171
+
172
+ if len(sentences) > MAX_NUMBER_SENTENCES:
173
+ gr.Info("Your text is too long. To keep this demo enjoyable for everyone, we only kept the first 10 sentences :) Duplicate this space and set MAX_NUMBER_SENTENCES for longer texts ;)")
174
+ # Keep only the first MAX_NUMBER_SENTENCES sentences
175
+ first_nb_sentences = sentences[:MAX_NUMBER_SENTENCES]
176
+
177
+ # Join the selected sentences back into a single string
178
+ limited_prompt = ' '.join(first_nb_sentences)
179
+ prompt = limited_prompt
180
+
181
+ else:
182
+ prompt = prompt
183
 
184
  gr.Info("Generating audio from prompt")
185
  tts.tts_to_file(text=prompt,
186
+ file_path="output.wav",
187
+ voice_dir="bark_voices/",
188
+ speaker=f"{file_name}")
189
 
190
+ # List all the files and subdirectories in the given directory
191
+ contents = os.listdir(f"bark_voices/{file_name}")
192
+
193
+ # Print the contents
194
+ for item in contents:
195
+ print(item)
196
  print("Preparing final waveform video ...")
197
  tts_video = gr.make_waveform(audio="output.wav")
198
  print(tts_video)
199
  print("FINISHED")
200
  return "output.wav", tts_video, gr.update(value=f"bark_voices/{file_name}/{contents[1]}", visible=True), gr.Group.update(visible=True), destination_path
201
 
202
+ def infer_from_c(prompt, c_name):
203
+ print("""
204
+ β€”β€”β€”β€”β€”
205
+ NEW INFERENCE:
206
+ β€”β€”β€”β€”β€”β€”β€”
207
+ """)
208
+ if prompt == "":
209
+ gr.Warning("Do not forget to provide a tts prompt !")
210
+ print("Warning about prompt sent to user")
211
+
212
+ print(f"USING VOICE LIBRARY: {c_name}")
213
+ # Split the text into sentences based on common punctuation marks
214
+ sentences = re.split(r'(?<=[.!?])\s+', prompt)
215
+
216
+ if len(sentences) > MAX_NUMBER_SENTENCES:
217
+ gr.Info("Your text is too long. To keep this demo enjoyable for everyone, we only kept the first 10 sentences :) Duplicate this space and set MAX_NUMBER_SENTENCES for longer texts ;)")
218
+ # Keep only the first MAX_NUMBER_SENTENCES sentences
219
+ first_nb_sentences = sentences[:MAX_NUMBER_SENTENCES]
220
+
221
+ # Join the selected sentences back into a single string
222
+ limited_prompt = ' '.join(first_nb_sentences)
223
+ prompt = limited_prompt
224
+
225
+ else:
226
+ prompt = prompt
227
+
228
+
229
+ if c_name == "":
230
+ gr.Warning("Voice character is not properly selected. Please ensure that the name of the chosen voice is specified in the Character Name input.")
231
+ print("Warning about Voice Name sent to user")
232
+ else:
233
+ print(f"Generating audio from prompt with {c_name} ;)")
234
+
235
+ tts.tts_to_file(text=prompt,
236
+ file_path="output.wav",
237
+ voice_dir="examples/library/",
238
+ speaker=f"{c_name}")
239
+
240
+ print("Preparing final waveform video ...")
241
+ tts_video = gr.make_waveform(audio="output.wav")
242
+ print(tts_video)
243
+ print("FINISHED")
244
+ return "output.wav", tts_video, gr.update(value=f"examples/library/{c_name}/{c_name}.npz", visible=True), gr.Group.update(visible=True)
245
+
246
 
247
  css = """
248
+ #col-container {max-width: 780px; margin-left: auto; margin-right: auto;}
249
+ a {text-decoration-line: underline; font-weight: 600;}
250
  .mic-wrap > button {
251
  width: 100%;
252
  height: 60px;
 
263
  width: 20px!important;
264
  height: 20px!important;
265
  }
266
+ .animate-spin {
267
+ animation: spin 1s linear infinite;
268
+ }
269
+ @keyframes spin {
270
+ from {
271
+ transform: rotate(0deg);
272
+ }
273
+ to {
274
+ transform: rotate(360deg);
275
+ }
276
+ }
277
+ #share-btn-container {
278
+ display: flex;
279
+ padding-left: 0.5rem !important;
280
+ padding-right: 0.5rem !important;
281
+ background-color: #000000;
282
+ justify-content: center;
283
+ align-items: center;
284
+ border-radius: 9999px !important;
285
+ max-width: 15rem;
286
+ height: 36px;
287
+ }
288
+ div#share-btn-container > div {
289
+ flex-direction: row;
290
+ background: black;
291
+ align-items: center;
292
+ }
293
+ #share-btn-container:hover {
294
+ background-color: #060606;
295
+ }
296
+ #share-btn {
297
+ all: initial;
298
+ color: #ffffff;
299
+ font-weight: 600;
300
+ cursor:pointer;
301
+ font-family: 'IBM Plex Sans', sans-serif;
302
+ margin-left: 0.5rem !important;
303
+ padding-top: 0.5rem !important;
304
+ padding-bottom: 0.5rem !important;
305
+ right:0;
306
+ }
307
+ #share-btn * {
308
+ all: unset;
309
+ }
310
+ #share-btn-container div:nth-child(-n+2){
311
+ width: auto !important;
312
+ min-height: 0px !important;
313
+ }
314
+ #share-btn-container .wrap {
315
+ display: none !important;
316
+ }
317
+ #share-btn-container.hidden {
318
+ display: none!important;
319
+ }
320
+ img[src*='#center'] {
321
+ display: block;
322
+ margin: auto;
323
+ }
324
+ .footer {
325
+ margin-bottom: 45px;
326
+ margin-top: 10px;
327
+ text-align: center;
328
+ border-bottom: 1px solid #e5e5e5;
329
+ }
330
+ .footer>p {
331
+ font-size: .8rem;
332
+ display: inline-block;
333
+ padding: 0 10px;
334
+ transform: translateY(10px);
335
+ background: white;
336
+ }
337
+ .dark .footer {
338
+ border-color: #303030;
339
+ }
340
+ .dark .footer>p {
341
+ background: #0b0f19;
342
+ }
343
+
344
+ .disclaimer {
345
+ text-align: left;
346
+ }
347
+ .disclaimer > p {
348
+ font-size: .8rem;
349
+ }
350
  """
351
+
352
+ with gr.Blocks(css=css) as demo:
353
+ with gr.Column(elem_id="col-container"):
354
+
355
+ gr.Markdown("""
356
  <h1 style="text-align: center;">Coqui + Bark Voice Cloning</h1>
357
  <p style="text-align: center;">
358
  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 />
359
+ Upload a clean 20 seconds WAV file of the vocal persona you want to mimic, <br />
360
+ type your text-to-speech prompt and hit submit ! <br />
361
  </p>
 
362
 
363
+ [![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)
364
+
365
+ """)
366
+ with gr.Row():
367
+ with gr.Column():
368
+ prompt = gr.Textbox(
369
+ label = "Text to speech prompt",
370
+ info = "One or two sentences at a time is better* (max: 10)",
371
+ placeholder = "Hello friend! How are you today?",
372
+ elem_id = "tts-prompt"
373
+ )
374
 
375
+ with gr.Tab("File upload"):
376
+
377
+ with gr.Column():
 
 
 
 
 
378
 
379
+ if file_upload_available == "True":
380
+ audio_in = gr.Audio(
381
+ label="WAV voice to clone",
382
+ type="filepath",
383
+ source="upload"
384
+ )
385
+ else:
386
+ audio_in = gr.Audio(
387
+ label="WAV voice to clone",
388
+ type="filepath",
389
+ source="upload",
390
+ interactive = False
391
+ )
392
+ clean_sample = gr.Checkbox(label="Clean sample ?", value=False)
393
+ hidden_audio_numpy = gr.Audio(type="numpy", visible=False)
394
+ submit_btn = gr.Button("Submit")
395
+
396
+ with gr.Tab("Microphone"):
397
+ texts_samples = gr.Textbox(label = "Helpers",
398
+ info = "You can read out loud one of these sentences if you do not know what to record :)",
399
+ value = """"Jazz, a quirky mix of groovy saxophones and wailing trumpets, echoes through the vibrant city streets."
400
+ β€”β€”β€”
401
+ "A majestic orchestra plays enchanting melodies, filling the air with harmony."
402
+ β€”β€”β€”
403
+ "The exquisite aroma of freshly baked bread wafts from a cozy bakery, enticing passersby."
404
+ β€”β€”β€”
405
+ "A thunderous roar shakes the ground as a massive jet takes off into the sky, leaving trails of white behind."
406
+ β€”β€”β€”
407
+ "Laughter erupts from a park where children play, their innocent voices rising like tinkling bells."
408
+ β€”β€”β€”
409
+ "Waves crash on the beach, and seagulls caw as they soar overhead, a symphony of nature's sounds."
410
+ β€”β€”β€”
411
+ "In the distance, a blacksmith hammers red-hot metal, the rhythmic clang punctuating the day."
412
+ β€”β€”β€”
413
+ "As evening falls, a soft hush blankets the world, crickets chirping in a soothing rhythm."
414
+ """,
415
+ interactive = False,
416
+ lines = 5
417
+ )
418
+ micro_in = gr.Audio(
419
+ label="Record voice to clone",
420
+ type="filepath",
421
+ source="microphone",
422
+ interactive = True
423
+ )
424
+ clean_micro = gr.Checkbox(label="Clean sample ?", value=False)
425
+ micro_submit_btn = gr.Button("Submit")
426
+
427
+ audio_in.upload(fn=load_hidden, inputs=[audio_in], outputs=[hidden_audio_numpy], queue=False)
428
+ micro_in.stop_recording(fn=load_hidden_mic, inputs=[micro_in], outputs=[hidden_audio_numpy], queue=False)
429
+
430
+
431
+ with gr.Tab("Voices Characters"):
432
+ selected_state = gr.State()
433
+ gallery_in = gr.Gallery(
434
+ label="Character Gallery",
435
+ value=[(item["image"], item["title"]) for item in characters],
436
+ interactive = True,
437
+ allow_preview=False,
438
+ columns=3,
439
+ elem_id="gallery",
440
+ show_share_button=False
441
+ )
442
+ c_submit_btn = gr.Button("Submit")
443
 
 
 
 
 
444
 
445
+ with gr.Column():
446
+
447
+ cloned_out = gr.Audio(
448
+ label="Text to speech output",
449
+ visible = False
450
+ )
451
+
452
+ video_out = gr.Video(
453
+ label = "Waveform video",
454
+ elem_id = "voice-video-out"
455
+ )
456
+
457
+ npz_file = gr.File(
458
+ label = ".npz file",
459
+ visible = False
460
+ )
461
+
462
+ folder_path = gr.Textbox(visible=False)
463
+
464
+
465
+
466
+ character_name = gr.Textbox(
467
+ label="Character Name",
468
+ placeholder="Name that voice character",
469
+ elem_id = "character-name"
470
+ )
471
+
472
+ voice_description = gr.Textbox(
473
+ label="description",
474
+ placeholder="How would you describe that voice ? ",
475
+ elem_id = "voice-description"
476
+ )
477
+
478
+ with gr.Group(elem_id="share-btn-container", visible=False) as share_group:
479
+ community_icon = gr.HTML(community_icon_html)
480
+ loading_icon = gr.HTML(loading_icon_html)
481
+ share_button = gr.Button("Share with Community", elem_id="share-btn")
482
+
483
+ share_button.click(None, [], [], _js=share_js, queue=False)
484
+
485
+ gallery_in.select(
486
+ update_selection,
487
+ outputs=[character_name, selected_state],
488
+ queue=False,
489
+ show_progress=False,
490
+ )
491
+
492
+ audio_in.change(fn=wipe_npz_file, inputs=[folder_path], queue=False)
493
+ micro_in.clear(fn=wipe_npz_file, inputs=[folder_path], queue=False)
494
+
495
+ gr.Examples(
496
+ examples = [
497
+ [
498
+ "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.",
499
+ "./examples/en_speaker_6.wav",
500
+ False,
501
+ None
502
+ ],
503
+ [
504
+ "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. ",
505
+ "./examples/en_speaker_9.wav",
506
+ False,
507
+ None
508
+ ],
509
+ ],
510
+ fn = infer,
511
+ inputs = [
512
+ prompt,
513
+ audio_in,
514
+ clean_sample,
515
+ hidden_audio_numpy
516
+ ],
517
+ outputs = [
518
+ cloned_out,
519
+ video_out,
520
+ npz_file,
521
+ share_group,
522
+ folder_path
523
+ ],
524
+ cache_examples = False
525
+ )
526
+
527
+ gr.HTML("""
528
+ <div class="footer">
529
+ <p>
530
+ Coqui + Bark Voice Cloning Demo by πŸ€— <a href="https://twitter.com/fffiloni" target="_blank">Sylvain Filoni</a>
531
+ </p>
532
+ </div>
533
+ <div class="disclaimer">
534
+ <h3> * DISCLAIMER </h3>
535
+ <p>
536
+ I hold no responsibility for the utilization or outcomes of audio content produced using the semantic constructs generated by this model. <br />
537
+ Please ensure that any application of this technology remains within legal and ethical boundaries. <br />
538
+ It is important to utilize this technology for ethical and legal purposes, upholding the standards of creativity and innovation.
539
+ </p>
540
+ </div>
541
+ """)
542
+
543
+ submit_btn.click(
544
+ fn = infer,
545
+ inputs = [
546
+ prompt,
547
+ audio_in,
548
+ clean_sample,
549
+ hidden_audio_numpy
550
+ ],
551
+ outputs = [
552
+ cloned_out,
553
+ video_out,
554
+ npz_file,
555
+ share_group,
556
+ folder_path
557
+ ]
558
  )
559
 
560
  micro_submit_btn.click(
561
+ fn = infer,
562
+ inputs = [
563
+ prompt,
564
+ micro_in,
565
+ clean_micro,
566
+ hidden_audio_numpy
567
+ ],
568
+ outputs = [
569
+ cloned_out,
570
+ video_out,
571
+ npz_file,
572
+ share_group,
573
+ folder_path
574
+ ]
575
+ )
576
+
577
+ c_submit_btn.click(
578
+ fn = infer_from_c,
579
+ inputs = [
580
+ prompt,
581
+ character_name
582
+ ],
583
+ outputs = [
584
+ cloned_out,
585
+ video_out,
586
+ npz_file,
587
+ share_group
588
+ ]
589
  )
590
 
591
+ demo.queue(api_open=False, max_size=10).launch()