englissi commited on
Commit
eefe9ae
ยท
verified ยท
1 Parent(s): 3bafd35

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gtts import gTTS
3
+ import os
4
+
5
+ def text_to_speech(prompt):
6
+ # ์ž…๋ ฅ๋œ Bulgarian ํ…์ŠคํŠธ๋ฅผ ์Œ์„ฑ์œผ๋กœ ๋ณ€ํ™˜
7
+ tts = gTTS(text=prompt, lang="bg") # 'bg'๋Š” Bulgarian ์–ธ์–ด ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค.
8
+ audio_file = "output.mp3"
9
+ tts.save(audio_file)
10
+
11
+ # ํŒŒ์ผ ๊ฒฝ๋กœ ๋Œ€์‹  ๋ฐ”์ด๋„ˆ๋ฆฌ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
12
+ with open(audio_file, "rb") as f:
13
+ audio_binary = f.read()
14
+ # ์ž„์‹œ ํŒŒ์ผ ์‚ญ์ œ
15
+ os.remove(audio_file)
16
+
17
+ return audio_binary
18
+
19
+ with gr.Blocks() as demo:
20
+ gr.Markdown("## Bulgarian Text-to-Speech (TTS)")
21
+ with gr.Row():
22
+ input_prompt = gr.Textbox(label="Enter a prompt in Bulgarian:")
23
+ # gr.Audio์˜ type์„ "binary"๋กœ ์ง€์ •ํ•˜์—ฌ ํŒŒ์ผ ๊ฒฝ๋กœ ๋Œ€์‹  ๋ฐ”์ด๋„ˆ๋ฆฌ ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
24
+ output_audio = gr.Audio(label="Generated Speech", type="binary")
25
+ generate_button = gr.Button("Generate Speech")
26
+
27
+ generate_button.click(text_to_speech, inputs=input_prompt, outputs=output_audio)
28
+
29
+ if __name__ == "__main__":
30
+ demo.launch()