import gradio as gr import os from gtts import gTTS def text_to_speech(text): # Check for specific keywords and modify input text accordingly if "[laughs]" in text: text = text.replace("[laughs]", "ha ha ha") if "[music]" in text or "[music in background]" in text: text = text.replace("[music]", "") text = text.replace("[music in background]", "") text = "♫ " + text + " ♫" # Use gTTS library to generate speech from input text tts = gTTS(text) tts.save("output.mp3") # Play the audio file using OS audio player os.system("mpg123 output.mp3") # Define input text box for Gradio interface text_input = gr.inputs.Textbox(label="Enter Text") # Define Gradio interface and launch app gr.Interface(text_to_speech, inputs=text_input, outputs=None, title="Text-to-Speech", description="Enter text and listen to it being spoken. Keywords [laughs], [music], and [music in background] modify the speech accordingly.").launch()