ragha108 commited on
Commit
9a2d609
·
1 Parent(s): 0065076

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -17
app.py CHANGED
@@ -1,22 +1,20 @@
1
  import gradio as gr
2
  from gtts import gTTS
3
- import os
 
4
 
5
- def virtual_meditation_class(input_text):
6
- # Use text-to-speech to convert the input_text to audio
7
- tts = gTTS(input_text)
8
- audio_file = "output.mp3"
9
- tts.save(audio_file)
10
-
11
- # Play the audio file
12
- os.system("mpg321 " + audio_file)
13
 
14
- # Create a Gradio interface with a text input and an audio output
15
- gradio_interface = gr.Interface(
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
- # Launch the interface
22
- gradio_interface.launch()
 
 
 
 
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()