Spaces:
Running
Running
import torch | |
import os | |
import streamlit as st | |
from TTS.api import TTS | |
# By using XTTS you agree to CPML license https://coqui.ai/cpml | |
os.environ["COQUI_TOS_AGREED"] = "1" | |
# Initialize model | |
model = "tts_models/multilingual/multi-dataset/xtts_v2" | |
device = 'cuda' if torch.cuda.is_available() else 'cpu' | |
tts = TTS(model).to(device) | |
# Title | |
st.title('Voice Cloning') | |
# Upload audio file | |
uploaded_file = st.file_uploader('Add an audio file of the voice you want to clone...', type=['wav']) | |
if uploaded_file: | |
st.audio(uploaded_file, format='audio/wav') | |
# Input text | |
text_input = st.text_input('Enter the text to synthesize:') | |
if text_input: | |
if st.button('Synthesize'): | |
try: | |
output_audio = tts.tts_to_file(text=text_input, speaker_wav=uploaded_file, language='en') | |
st.audio(output_audio, format='audio/wav') | |
except: | |
st.error('An error occured during synthesis. Please check your input and try again.') | |