import gradio as gr import torch import os from TTS.api import TTS # Check if the user has agreed to the terms of service tos_gr = gr.Checkbox( label="Agree", value=True, info="I agree to the terms of the CPML: https://coqui.ai/cpml", ) tos_agreed = tos_gr.value # Set the COQUI_TOS_AGREED environment variable os.environ["COQUI_TOS_AGREED"] = "1" if tos_agreed else "0" def generate_voice(text, language, sample_voice, tos_agreed): # Check if the user has agreed to the terms of service if not tos_agreed: return "Please agree to the terms of service before using the service." # Initialize TTS device = "cuda" if torch.cuda.is_available() else "cpu" tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device) # Load the audio sample from the user's upload speaker_wav_path = sample_voice.name # Use the sample voice to convert text to speech wav = tts.tts(text=text, speaker_wav=speaker_wav_path, language=language) # Play the generated audio return wav # Define the Gradio interface iface = gr.Interface( fn=generate_voice, inputs=[ gr.Textbox(lines=3, label="Enter Text"), # Text input gr.Dropdown(["es", "en", "fr"], label="Select Language"), # Dropdown for language selection gr.File(label="Upload Sample Voice"), # File upload for sample voice tos_gr, # Checkbox for agreeing to the terms of service ], outputs=gr.Audio(label="Generated Audio") ) # Launch the Gradio interface iface.launch(share=True)