AngeT10 commited on
Commit
405296c
1 Parent(s): da1866b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -20
app.py CHANGED
@@ -25,8 +25,8 @@ def convert_to_wav(audio_file):
25
  # Extract file extension
26
  file_extension = os.path.splitext(audio_file)[-1].lower()
27
 
28
- # Convert audio file to .wav format
29
- if file_extension != ".wav":
30
  audio = AudioSegment.from_file(audio_file)
31
  audio.export("temp.wav", format="wav")
32
  os.remove(audio_file)
@@ -34,21 +34,21 @@ def convert_to_wav(audio_file):
34
 
35
  return audio_file
36
 
37
- def clone(text, url, language):
38
- # Download zip file
39
- response = requests.get(url)
40
- with open("temp.zip", "wb") as f:
41
- f.write(response.content)
42
-
43
- # Extract audio file from zip archive
44
- with zipfile.ZipFile("temp.zip", "r") as zip_ref:
45
- for file in zip_ref.namelist():
46
- if os.path.splitext(file)[-1].lower() in AUDIO_FORMATS:
47
- zip_ref.extract(file, ".")
48
- audio_file = file
49
- break
50
 
51
- # Convert audio file to .wav format
52
  audio_file = convert_to_wav(audio_file)
53
 
54
  # Generate audio using TTS model
@@ -56,16 +56,15 @@ def clone(text, url, language):
56
 
57
  # Clean up
58
  os.remove(audio_file)
59
- os.remove("temp.zip")
60
 
61
  return "./output.wav"
62
 
63
  # Create Gradio interface
64
  iface = gr.Interface(
65
  fn=clone,
66
- inputs=["text", gr.components.Text(label="URL"), gr.Dropdown(choices=LANGUAGES, label="Language")],
67
- outputs=gr.Audio(type='filepath'),
68
- title='Voice Clone',
69
  description=""" by [Angetyde](https://youtube.com/@Angetyde?si=7nusP31nTumIkPTF) and [Tony Assi](https://www.tonyassi.com/ ) use this colab with caution <3. """,
70
  theme=gr.themes.Base(primary_hue="teal", secondary_hue="teal", neutral_hue="slate")
71
  )
 
25
  # Extract file extension
26
  file_extension = os.path.splitext(audio_file)[-1].lower()
27
 
28
+ # Convert audio file to.wav format
29
+ if file_extension!= ".wav":
30
  audio = AudioSegment.from_file(audio_file)
31
  audio.export("temp.wav", format="wav")
32
  os.remove(audio_file)
 
34
 
35
  return audio_file
36
 
37
+ def clone(text, audio_or_url, language):
38
+ # Check if audio_or_url is a file object or a string
39
+ if isinstance(audio_or_url, str):
40
+ # Download audio file from URL
41
+ response = requests.get(audio_or_url)
42
+ with open("temp.wav", "wb") as f:
43
+ f.write(response.content)
44
+ audio_file = "temp.wav"
45
+ else:
46
+ # Save uploaded audio file to a temporary location
47
+ audio_file = "temp.wav"
48
+ with open(audio_file, "wb") as f:
49
+ f.write(audio_or_url.read())
50
 
51
+ # Convert audio file to.wav format
52
  audio_file = convert_to_wav(audio_file)
53
 
54
  # Generate audio using TTS model
 
56
 
57
  # Clean up
58
  os.remove(audio_file)
 
59
 
60
  return "./output.wav"
61
 
62
  # Create Gradio interface
63
  iface = gr.Interface(
64
  fn=clone,
65
+ inputs=["text", gr.Audio(label="Upload audio file or enter URL"), gr.Dropdown(choices=LANGUAGES, label="Language")],
66
+ outputs=gr.outputs.Audio(type="filepath"),
67
+ title="Voice Clone",
68
  description=""" by [Angetyde](https://youtube.com/@Angetyde?si=7nusP31nTumIkPTF) and [Tony Assi](https://www.tonyassi.com/ ) use this colab with caution <3. """,
69
  theme=gr.themes.Base(primary_hue="teal", secondary_hue="teal", neutral_hue="slate")
70
  )