englissi commited on
Commit
740beea
β€’
1 Parent(s): aa294bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -28
app.py CHANGED
@@ -1,33 +1,22 @@
1
-
2
-
3
- # Install transformers if not installed
4
- # !pip install transformers gradio
5
-
6
- from transformers import pipeline
7
  import gradio as gr
 
 
8
 
9
- # Install transformers and gradio if not installed
10
- import os
11
- os.system('pip install transformers gradio')
12
-
13
-
14
-
15
- # Load a pre-trained TTS pipeline
16
- tts_pipeline = pipeline("text-to-speech", model="facebook/fastspeech2-en-ljspeech")
17
 
18
- # Function to convert text to audio using the Hugging Face TTS model
19
- def text_to_audio(mytext):
20
- audio = tts_pipeline(mytext) # Generate audio
21
- return audio["filename"] # Return the filename of the generated audio
22
 
23
- # Create a Gradio interface
24
- iface = gr.Interface(
25
- fn=text_to_audio,
26
- inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
27
- outputs=gr.Audio(type="file"), # Gradio expects a file for audio output
28
- title="Text to Speech Application",
29
- description="Type your text and generate the corresponding audio."
30
- )
31
 
32
- # Launch the interface
33
- iface.launch(share=True)
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import torch
3
+ from transformers import pipeline
4
 
5
+ # Hugging Face TTS λͺ¨λΈ λ‘œλ“œ (λΆˆκ°€λ¦¬μ•„μ–΄ λͺ¨λΈλ‘œ λ³€κ²½ ν•„μš”)
6
+ tts = pipeline(task="text-to-speech", model="facebook/mms-tts-bul", device=0 if torch.cuda.is_available() else -1)
 
 
 
 
 
 
7
 
8
+ # TTS λ³€ν™˜ ν•¨μˆ˜
9
+ def tts_generate(text):
10
+ audio = tts(text, return_tensors=True)
11
+ return (audio['speech'].numpy(), 22050) # λ°˜ν™˜ν•  μƒ˜ν”Œλ§ 속도와 μ˜€λ””μ˜€ 데이터
12
 
13
+ # Gradio μΈν„°νŽ˜μ΄μŠ€ 생성
14
+ iface = gr.Interface(fn=tts_generate,
15
+ inputs="text",
16
+ outputs="audio",
17
+ title="Bulgarian TTS Generator",
18
+ description="Enter text to generate speech in Bulgarian.")
 
 
19
 
20
+ # μΈν„°νŽ˜μ΄μŠ€ μ‹€ν–‰
21
+ if __name__ == "__main__":
22
+ iface.launch()