ragha108 commited on
Commit
0a73c95
·
1 Parent(s): dea0ceb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -1,20 +1,25 @@
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()
 
1
  import gradio as gr
2
+ import librosa
3
  from gtts import gTTS
 
4
  import base64
5
+ from io import BytesIO
6
 
7
  def text_to_audio(text):
8
+ # Generate audio from text using gTTS
9
+ tts = gTTS(text, lang='en')
10
+ audio_bytes = BytesIO()
11
+ tts.write_to_fp(audio_bytes)
12
+ audio_bytes.seek(0)
13
 
14
+ # Load audio file with librosa
15
+ audio, sr = librosa.load(audio_bytes)
16
 
17
+ # Encode audio file as base64 string
18
+ audio_base64 = base64.b64encode(audio_bytes.read()).decode('utf-8')
19
+ return audio_base64
20
+
21
+ # Create a Gradio interface
22
+ input_text = gr.inputs.Textbox(label="Meditation Instructions")
23
  output_audio = gr.outputs.Audio(label="Meditation Instructions")
24
 
25
+ gr.Interface(fn=text_to_audio, inputs=input_text, outputs=output_audio, title="Meditation Instructions").launch()