AngeT10 commited on
Commit
17855f6
·
verified ·
1 Parent(s): bdeb120

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -2
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  import os
3
  import requests
4
  import torch
 
5
  from TTS.api import TTS
6
  from pydub import AudioSegment
7
 
@@ -28,6 +29,15 @@ def download_audio_file(url):
28
  print(f"Error downloading audio file: {e}")
29
  return None
30
 
 
 
 
 
 
 
 
 
 
31
  def convert_to_wav(input_audio_file):
32
  file_extension = os.path.splitext(input_audio_file)[-1].lower()
33
  if file_extension!= ".wav":
@@ -45,13 +55,21 @@ def synthesize_text(text, input_audio_file, language):
45
  def clone(text, input_file, language):
46
  if input_file is None:
47
  return None
48
- input_audio_file = input_file.name
 
 
 
 
 
 
 
 
49
  output_file_path = synthesize_text(text, input_audio_file, language)
50
  return output_file_path
51
 
52
  iface = gr.Interface(
53
  fn=clone,
54
- inputs=["text", gr.File(label="Input File", file_types=AUDIO_FORMATS), gr.Dropdown(choices=LANGUAGES, label="Language")],
55
  outputs=gr.Audio(type='filepath'),
56
  title='Voice Clone',
57
  description=""" by [Angetyde](https://youtube.com/@Angetyde?si=7nusP31nTumIkPTF) and [Tony Assi](https://www.tonyassi.com/ ) use this colab with caution <3. """,
 
2
  import os
3
  import requests
4
  import torch
5
+ import zipfile
6
  from TTS.api import TTS
7
  from pydub import AudioSegment
8
 
 
29
  print(f"Error downloading audio file: {e}")
30
  return None
31
 
32
+ def extract_zip_file(zip_file):
33
+ try:
34
+ with zipfile.ZipFile(zip_file, 'r') as zip_ref:
35
+ zip_ref.extractall()
36
+ return True
37
+ except zipfile.BadZipfile as e:
38
+ print(f"Error extracting zip file: {e}")
39
+ return False
40
+
41
  def convert_to_wav(input_audio_file):
42
  file_extension = os.path.splitext(input_audio_file)[-1].lower()
43
  if file_extension!= ".wav":
 
55
  def clone(text, input_file, language):
56
  if input_file is None:
57
  return None
58
+ if input_file.name.endswith(".zip"):
59
+ if extract_zip_file(input_file):
60
+ input_audio_file = [f for f in os.listdir('.') if os.path.isfile(f) and f.endswith(tuple(AUDIO_FORMATS))]
61
+ if len(input_audio_file) == 1:
62
+ input_audio_file = input_audio_file[0]
63
+ else:
64
+ return "Error: Please select a single audio file from the extracted files."
65
+ else:
66
+ input_audio_file = input_file.name
67
  output_file_path = synthesize_text(text, input_audio_file, language)
68
  return output_file_path
69
 
70
  iface = gr.Interface(
71
  fn=clone,
72
+ inputs=["text", gr.File(label="Input File", file_types=[".zip", *AUDIO_FORMATS]), gr.Dropdown(choices=LANGUAGES, label="Language")],
73
  outputs=gr.Audio(type='filepath'),
74
  title='Voice Clone',
75
  description=""" by [Angetyde](https://youtube.com/@Angetyde?si=7nusP31nTumIkPTF) and [Tony Assi](https://www.tonyassi.com/ ) use this colab with caution <3. """,