Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,39 @@
|
|
1 |
import gradio as gr
|
2 |
from gtts import gTTS
|
3 |
-
import
|
|
|
4 |
import os
|
|
|
5 |
|
6 |
def text_to_speech(prompt):
|
7 |
# gTTS๋ฅผ ์ฌ์ฉํ์ฌ Bulgarian ํ
์คํธ๋ฅผ ์์ฑ์ผ๋ก ๋ณํ
|
8 |
-
tts = gTTS(text=prompt, lang="bg")
|
9 |
audio_file = "output.mp3"
|
10 |
tts.save(audio_file)
|
11 |
|
12 |
-
#
|
13 |
-
|
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
|
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 |
|
|
|
1 |
import gradio as gr
|
2 |
from gtts import gTTS
|
3 |
+
from pydub import AudioSegment
|
4 |
+
import numpy as np
|
5 |
import os
|
6 |
+
import io
|
7 |
|
8 |
def text_to_speech(prompt):
|
9 |
# gTTS๋ฅผ ์ฌ์ฉํ์ฌ Bulgarian ํ
์คํธ๋ฅผ ์์ฑ์ผ๋ก ๋ณํ
|
10 |
+
tts = gTTS(text=prompt, lang="bg")
|
11 |
audio_file = "output.mp3"
|
12 |
tts.save(audio_file)
|
13 |
|
14 |
+
# pydub์ ์ฌ์ฉํ์ฌ mp3 ํ์ผ์ ๋ก๋ํฉ๋๋ค.
|
15 |
+
sound = AudioSegment.from_mp3(audio_file)
|
|
|
16 |
|
17 |
+
# pydub์ raw data๋ฅผ numpy ๋ฐฐ์ด๋ก ๋ณํ (16๋นํธ ์ ์ํ)
|
18 |
+
samples = np.array(sound.get_array_of_samples())
|
19 |
+
|
20 |
+
# ๋ชจ๋
ธ ์ฑ๋์ด ์๋๋ผ๋ฉด, ์ฑ๋์ ํฉ์นฉ๋๋ค.
|
21 |
+
if sound.channels > 1:
|
22 |
+
samples = samples.reshape((-1, sound.channels))
|
23 |
+
samples = samples.mean(axis=1).astype(np.int16)
|
24 |
+
|
25 |
+
sample_rate = sound.frame_rate
|
26 |
+
|
27 |
# ์์ mp3 ํ์ผ ์ญ์
|
28 |
os.remove(audio_file)
|
29 |
|
30 |
# gr.Audio(type="numpy")๋ (numpy array, sample_rate) ํํ์ ๊ธฐ๋ํฉ๋๋ค.
|
31 |
+
return samples, sample_rate
|
32 |
|
33 |
with gr.Blocks() as demo:
|
34 |
gr.Markdown("## Bulgarian Text-to-Speech (TTS)")
|
35 |
with gr.Row():
|
36 |
input_prompt = gr.Textbox(label="Enter a prompt in Bulgarian:")
|
|
|
37 |
output_audio = gr.Audio(label="Generated Speech", type="numpy")
|
38 |
generate_button = gr.Button("Generate Speech")
|
39 |
|