Voice.clone / app.py
deekshachilukuri's picture
init!
3226f5e verified
raw
history blame
1.12 kB
!pip install ipykernel
!pip install TTS
!pip install torch
import gradio as gr
import torch
from TTS.api import TTS
import os
# Assume that the TTS and its required setup are correctly configured similar to your script above
device = "cuda:0" if torch.cuda.is_available() else "cpu"
tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2", progress_bar=False).to(device)
def generate_voice(text, audio_file_path):
output_path = "/content/cloned_audio.wav" # Setting the output path
tts.tts_to_file(text,
speaker_wav=audio_file_path, # Directly use the file path string
language="en", # Assuming the language is English
file_path=output_path,
split_sentences=True)
return output_path
import gradio as gr
# Define the Gradio interface
iface = gr.Interface(
fn=generate_voice,
inputs=[
gr.Textbox(label="Input Text"),
gr.Audio(label="Input Audio", type="filepath")
],
outputs=gr.Audio(label="Cloned Voice"),
title="Voice Cloning TTS"
)
# Launch the interface
iface.launch()