Spaces:
Running
Running
Update app.py
Browse files
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
|
29 |
-
if file_extension
|
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,
|
38 |
-
#
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
|
51 |
-
# Convert audio file to
|
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.
|
67 |
-
outputs=gr.Audio(type=
|
68 |
-
title=
|
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 |
)
|