Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,20 @@
|
|
1 |
import gradio as gr
|
2 |
from gtts import gTTS
|
3 |
-
import
|
|
|
4 |
|
5 |
-
def
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
# Play the audio file
|
12 |
-
os.system("mpg321 " + audio_file)
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
fn=virtual_meditation_class,
|
17 |
-
inputs=gr.inputs.Textbox(lines=10, label="Enter your guided meditation instructions here"),
|
18 |
-
outputs=gr.outputs.Audio(label="Meditation instructions")
|
19 |
-
)
|
20 |
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from gtts import gTTS
|
3 |
+
import io
|
4 |
+
import base64
|
5 |
|
6 |
+
def text_to_audio(text):
|
7 |
+
with io.BytesIO() as file:
|
8 |
+
gTTS(text=text).write_to_fp(file)
|
9 |
+
audio_bytes = file.getvalue()
|
10 |
+
encoded_audio = base64.b64encode(audio_bytes).decode('utf-8')
|
11 |
+
return encoded_audio
|
|
|
|
|
12 |
|
13 |
+
def generate_audio(text):
|
14 |
+
return text_to_audio(text)
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
input_text = gr.inputs.Textbox(label="Meditation Text")
|
17 |
+
output_audio = gr.outputs.Audio(label="Meditation Instructions")
|
18 |
+
|
19 |
+
interface = gr.Interface(fn=generate_audio, inputs=input_text, outputs=output_audio)
|
20 |
+
interface.launch()
|