Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,30 @@
|
|
1 |
import gradio as gr
|
2 |
from gtts import gTTS
|
|
|
3 |
import os
|
4 |
|
5 |
def text_to_speech(prompt):
|
6 |
-
#
|
7 |
tts = gTTS(text=prompt, lang="bg") # 'bg'๋ Bulgarian ์ธ์ด ์ฝ๋์
๋๋ค.
|
8 |
audio_file = "output.mp3"
|
9 |
tts.save(audio_file)
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
15 |
os.remove(audio_file)
|
16 |
|
17 |
-
|
|
|
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 |
-
#
|
24 |
-
output_audio = gr.Audio(label="Generated Speech", type="
|
25 |
generate_button = gr.Button("Generate Speech")
|
26 |
|
27 |
generate_button.click(text_to_speech, inputs=input_prompt, outputs=output_audio)
|
|
|
1 |
import gradio as gr
|
2 |
from gtts import gTTS
|
3 |
+
import librosa
|
4 |
import os
|
5 |
|
6 |
def text_to_speech(prompt):
|
7 |
+
# gTTS๋ฅผ ์ฌ์ฉํ์ฌ Bulgarian ํ
์คํธ๋ฅผ ์์ฑ์ผ๋ก ๋ณํ
|
8 |
tts = gTTS(text=prompt, lang="bg") # 'bg'๋ Bulgarian ์ธ์ด ์ฝ๋์
๋๋ค.
|
9 |
audio_file = "output.mp3"
|
10 |
tts.save(audio_file)
|
11 |
|
12 |
+
# librosa๋ฅผ ์ฌ์ฉํ์ฌ mp3 ํ์ผ์ numpy ๋ฐฐ์ด๊ณผ ์ํ๋ ์ดํธ๋ก ๋ก๋ํฉ๋๋ค.
|
13 |
+
# sr=None๋ก ์ค์ ํ๋ฉด ์๋ณธ ์ํ๋ ์ดํธ๋ฅผ ์ ์งํฉ๋๋ค.
|
14 |
+
audio_array, sample_rate = librosa.load(audio_file, sr=None)
|
15 |
+
|
16 |
+
# ์์ mp3 ํ์ผ ์ญ์
|
17 |
os.remove(audio_file)
|
18 |
|
19 |
+
# gr.Audio(type="numpy")๋ (numpy array, sample_rate) ํํ์ ๊ธฐ๋ํฉ๋๋ค.
|
20 |
+
return audio_array, sample_rate
|
21 |
|
22 |
with gr.Blocks() as demo:
|
23 |
gr.Markdown("## Bulgarian Text-to-Speech (TTS)")
|
24 |
with gr.Row():
|
25 |
input_prompt = gr.Textbox(label="Enter a prompt in Bulgarian:")
|
26 |
+
# type์ "numpy"๋ก ์ค์ ํ์ฌ numpy ๋ฐฐ์ด์ ์ฌ์ฉํฉ๋๋ค.
|
27 |
+
output_audio = gr.Audio(label="Generated Speech", type="numpy")
|
28 |
generate_button = gr.Button("Generate Speech")
|
29 |
|
30 |
generate_button.click(text_to_speech, inputs=input_prompt, outputs=output_audio)
|