Spaces:
Runtime error
Runtime error
File size: 1,198 Bytes
dfd2b84 80ee679 dfd2b84 80ee679 dfd2b84 80ee679 2708c6a 80ee679 dfd2b84 80ee679 dfd2b84 80ee679 dfd2b84 80ee679 db425a1 dfd2b84 80ee679 db425a1 80ee679 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | import torch
import os
import gradio as gr
from bark import generate_audio, SAMPLE_RATE
from scipy.io.wavfile import write as write_wav
import shutil
# Make sure history_prompts directory exists
os.makedirs("history_prompts", exist_ok=True)
def synthesize(text_prompt, demo_voice=None):
history_prompt = None
if demo_voice is not None:
uploaded_path = "history_prompts/user_prompt.wav"
shutil.copyfile(demo_voice, uploaded_path)
history_prompt = uploaded_path
try:
audio_array = generate_audio(text_prompt, history_prompt=history_prompt)
output_path = "output.wav"
write_wav(output_path, SAMPLE_RATE, audio_array)
return output_path
except Exception as e:
return f"Error: {e}"
gr.Interface(
fn=synthesize,
inputs=[
gr.Textbox(label="💬 Enter Text to Speak"),
gr.Audio(type="filepath", label="📤 Upload Real Voice (.wav)", optional=True)
],
outputs=gr.Audio(type="filepath", label="🔊 Cloned Voice Output"),
title="🧬 CloneVoiceTTS - Real Voice Cloning (Bark)",
description="Upload a real voice (.wav), then enter text to synthesize it in the same voice."
).launch() |