Voice-clon / app.py
Doubleupai's picture
Create app.py
2e0b69b verified
raw
history blame
1.17 kB
import gradio as gr
from TTS.api import TTS
# Load a pre-trained TTS model
tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False, gpu=False)
def clone_voice(text, audio_file):
# Convert the input audio to a format that the model can use
# This step is simplified; in a real-world scenario, you might need to preprocess the audio
wav, sr = tts.load_audio(audio_file)
# Clone the voice using the input audio as a reference
# This is a simplified example; in a real-world scenario, you might use a more complex cloning process
cloned_wav = tts.tts(text, speaker_wav=wav, language="en")
# Save the cloned audio to a file
output_file = "cloned_voice.wav"
tts.save_wav(cloned_wav, output_file)
return output_file
# Create the Gradio interface
iface = gr.Interface(
fn=clone_voice,
inputs=[
gr.Textbox(label="Text to Clone"),
gr.Audio(label="Reference Audio", type="filepath")
],
outputs=gr.Audio(label="Cloned Voice"),
title="Voice Cloning",
description="Upload a reference audio and input text to clone the voice."
)
# Launch the interface
iface.launch()