DaxtonBrandon commited on
Commit
f835a88
1 Parent(s): 255d96a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
- import pyttsx3
 
3
 
4
  def text_to_speech(text):
5
  # Check for specific keywords and modify input text accordingly
@@ -10,12 +11,12 @@ def text_to_speech(text):
10
  text = text.replace("[music in background]", "")
11
  text = "♫ " + text + " ♫"
12
 
13
- # Use pyttsx3 library to generate speech from input text
14
- engine = pyttsx3.init()
15
- engine.setProperty("rate", 150)
16
- engine.say(text)
17
- engine.runAndWait()
18
- engine.stop()
19
 
20
  # Define input text box for Gradio interface
21
  text_input = gr.inputs.Textbox(label="Enter Text")
 
1
  import gradio as gr
2
+ import os
3
+ from gtts import gTTS
4
 
5
  def text_to_speech(text):
6
  # Check for specific keywords and modify input text accordingly
 
11
  text = text.replace("[music in background]", "")
12
  text = "♫ " + text + " ♫"
13
 
14
+ # Use gTTS library to generate speech from input text
15
+ tts = gTTS(text)
16
+ tts.save("output.mp3")
17
+
18
+ # Play the audio file using OS audio player
19
+ os.system("mpg123 output.mp3")
20
 
21
  # Define input text box for Gradio interface
22
  text_input = gr.inputs.Textbox(label="Enter Text")