englissi commited on
Commit
437795b
·
verified ·
1 Parent(s): 3274aa9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -19
app.py CHANGED
@@ -1,30 +1,24 @@
1
- # Install the necessary libraries
2
- # !pip install gtts gradio
3
 
4
- from gtts import gTTS
5
  import gradio as gr
6
 
7
- # Function to convert text to audio
8
- def text_to_audio(mytext):
9
- # Create a gTTS object with Bulgarian language
10
- tts = gTTS(text=mytext, lang='bg')
11
- # Save the audio file
12
- filename = "output.mp3"
13
- tts.save(filename)
14
- return filename
15
 
16
- # Gradio interface
17
- def gradio_interface(text):
18
- audio_file = text_to_audio(text)
19
- return audio_file
20
 
21
  # Create a Gradio interface
22
  iface = gr.Interface(
23
- fn=gradio_interface,
24
  inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
25
- outputs=gr.Audio(type="file"), # Changed to 'file'
26
- title="Text to Speech Application (Bulgarian audio)",
27
- description="Type your text and to generate the corresponding audio in Bulgarian."
28
  )
29
 
30
  # Launch the interface
 
1
+ # Install transformers if not installed
2
+ # !pip install transformers gradio
3
 
4
+ from transformers import pipeline
5
  import gradio as gr
6
 
7
+ # Load a pre-trained TTS pipeline
8
+ tts_pipeline = pipeline("text-to-speech", model="facebook/fastspeech2-en-ljspeech")
 
 
 
 
 
 
9
 
10
+ # Function to convert text to audio using the Hugging Face TTS model
11
+ def text_to_audio(mytext):
12
+ audio = tts_pipeline(mytext) # Generate audio
13
+ return audio["filename"] # Return the filename of the generated audio
14
 
15
  # Create a Gradio interface
16
  iface = gr.Interface(
17
+ fn=text_to_audio,
18
  inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
19
+ outputs=gr.Audio(type="file"), # Gradio expects a file for audio output
20
+ title="Text to Speech Application",
21
+ description="Type your text and generate the corresponding audio."
22
  )
23
 
24
  # Launch the interface