Shanulhaq commited on
Commit
a03b7f2
1 Parent(s): eb6aa36

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from TTS.api import TTS
3
+
4
+ # Initialize the TTS model
5
+ tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False, gpu=False)
6
+
7
+ def text_to_speech(text):
8
+ # Generate speech from text
9
+ audio_path = tts.tts_to_file(text=text, file_path="output.wav")
10
+ # Read the audio file
11
+ with open("output.wav", "rb") as f:
12
+ audio_bytes = f.read()
13
+ return audio_bytes
14
+
15
+ # Create Gradio interface
16
+ interface = gr.Interface(
17
+ fn=text_to_speech,
18
+ inputs=gr.inputs.Textbox(lines=5, placeholder="Enter text here..."),
19
+ outputs=gr.outputs.Audio(type="file"),
20
+ title="AI-Powered Text-to-Speech Converter",
21
+ description="Convert text to speech using AI models.",
22
+ )
23
+
24
+ # Launch the interface
25
+ if __name__ == "__main__":
26
+ interface.launch()