Spaces:
Runtime error
Runtime error
| 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() |