Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,37 @@
|
|
| 1 |
import torch
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from bark import generate_audio, SAMPLE_RATE
|
| 4 |
from scipy.io.wavfile import write as write_wav
|
| 5 |
-
import
|
| 6 |
-
import os
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
import torch.serialization
|
| 11 |
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
fn=synthesize,
|
| 22 |
inputs=[
|
| 23 |
-
gr.Textbox(label="Enter Text to Speak"),
|
| 24 |
-
gr.
|
| 25 |
],
|
| 26 |
-
outputs=gr.Audio(
|
| 27 |
-
title="
|
| 28 |
-
description="Upload a
|
| 29 |
-
)
|
| 30 |
-
|
| 31 |
-
demo.launch()
|
|
|
|
| 1 |
import torch
|
| 2 |
+
import os
|
| 3 |
import gradio as gr
|
| 4 |
from bark import generate_audio, SAMPLE_RATE
|
| 5 |
from scipy.io.wavfile import write as write_wav
|
| 6 |
+
import shutil
|
|
|
|
| 7 |
|
| 8 |
+
# Make sure history_prompts directory exists
|
| 9 |
+
os.makedirs("history_prompts", exist_ok=True)
|
|
|
|
| 10 |
|
| 11 |
+
def synthesize(text_prompt, demo_voice=None):
|
| 12 |
+
history_prompt = None
|
| 13 |
|
| 14 |
+
# If user uploads a demo voice, save it and use as history prompt
|
| 15 |
+
if demo_voice is not None:
|
| 16 |
+
uploaded_path = "history_prompts/user_prompt.wav"
|
| 17 |
+
shutil.copyfile(demo_voice, uploaded_path)
|
| 18 |
+
history_prompt = uploaded_path
|
| 19 |
|
| 20 |
+
try:
|
| 21 |
+
audio_array = generate_audio(text_prompt, history_prompt=history_prompt)
|
| 22 |
+
output_path = "output.wav"
|
| 23 |
+
write_wav(output_path, SAMPLE_RATE, audio_array)
|
| 24 |
+
return output_path
|
| 25 |
+
except Exception as e:
|
| 26 |
+
return f"Error: {e}"
|
| 27 |
+
|
| 28 |
+
gr.Interface(
|
| 29 |
fn=synthesize,
|
| 30 |
inputs=[
|
| 31 |
+
gr.Textbox(label="💬 Enter Text to Speak"),
|
| 32 |
+
gr.Audio(source="upload", type="filepath", label="📤 Upload Real Voice (optional)", optional=True)
|
| 33 |
],
|
| 34 |
+
outputs=gr.Audio(type="filepath", label="🔊 Cloned Voice Output"),
|
| 35 |
+
title="🧬 CloneVoiceTTS - Real Voice Cloning (Bark)",
|
| 36 |
+
description="Upload a short real voice (.wav), then type any text. Bark will try to clone the uploaded voice tone."
|
| 37 |
+
).launch()
|
|
|
|
|
|