Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,49 +1,39 @@
|
|
1 |
import gradio as gr
|
2 |
from gtts import gTTS
|
3 |
from pydub import AudioSegment
|
4 |
-
|
5 |
-
import os
|
6 |
|
7 |
-
def
|
8 |
-
|
9 |
-
|
10 |
-
tts = gTTS(text=prompt, lang="bg")
|
11 |
-
audio_file = "output.mp3"
|
12 |
-
tts.save(audio_file)
|
13 |
-
except Exception as e:
|
14 |
-
print("gTTS ์์ฑ ์ค๋ฅ:", e)
|
15 |
-
raise e # ์๋ฌ๋ฅผ ๋ค์ ๋ฐ์์์ผ Gradio์์ ๊ฐ์งํ๋๋ก ํจ
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
# ์คํ
๋ ์ค๋ฉด ๋ชจ๋
ธ๋ก ๋ณํ
|
23 |
-
if sound.channels > 1:
|
24 |
-
samples = samples.reshape((-1, sound.channels))
|
25 |
-
samples = samples.mean(axis=1)
|
26 |
-
|
27 |
-
# int16 -> float32 ์ ๊ทํ
|
28 |
-
samples = samples.astype(np.float32) / 32768.0
|
29 |
-
sample_rate = sound.frame_rate
|
30 |
-
except Exception as e:
|
31 |
-
print("pydub ๋ก๋ฉ/์ฒ๋ฆฌ ์ค๋ฅ:", e)
|
32 |
-
raise e
|
33 |
-
finally:
|
34 |
-
if os.path.exists(audio_file):
|
35 |
-
os.remove(audio_file)
|
36 |
|
37 |
-
|
|
|
|
|
|
|
|
|
38 |
|
39 |
with gr.Blocks() as demo:
|
40 |
gr.Markdown("## Bulgarian Text-to-Speech (TTS)")
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
44 |
generate_button = gr.Button("Generate Speech")
|
45 |
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
if __name__ == "__main__":
|
49 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from gtts import gTTS
|
3 |
from pydub import AudioSegment
|
4 |
+
from io import BytesIO
|
|
|
5 |
|
6 |
+
def bulgarian_tts(bulgarian_text):
|
7 |
+
# gTTS๋ฅผ ์ด์ฉํด ๋ถ๊ฐ๋ฆฌ์์ด ํ
์คํธ๋ฅผ ์์ฑ์ผ๋ก ๋ณํ
|
8 |
+
tts = gTTS(text=bulgarian_text, lang="bg")
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
+
# ๋ฉ๋ชจ๋ฆฌ ๋ฒํผ์ mp3๋ก ์ ์ฅ ํ, pydub ์ค๋์ค ์ธ๊ทธ๋จผํธ๋ก ๋ก๋ฉ
|
11 |
+
audio_buffer = BytesIO()
|
12 |
+
tts.write_to_fp(audio_buffer)
|
13 |
+
audio_buffer.seek(0)
|
14 |
+
tts_audio = AudioSegment.from_file(audio_buffer, format="mp3")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
# mp3 ํ์ผ๋ก ๋ด๋ณด๋ด๊ธฐ
|
17 |
+
output_file = "bulgarian_output.mp3"
|
18 |
+
tts_audio.export(output_file, format="mp3")
|
19 |
+
|
20 |
+
return output_file
|
21 |
|
22 |
with gr.Blocks() as demo:
|
23 |
gr.Markdown("## Bulgarian Text-to-Speech (TTS)")
|
24 |
+
|
25 |
+
# ๋จ์ผ ๋ถ๊ฐ๋ฆฌ์์ด ์
๋ ฅ๋ง ๋ฐ๋๋ก ๊ตฌ์ฑ
|
26 |
+
bulgarian_input = gr.Textbox(label="Enter Bulgarian Text:", placeholder="ะะดัะฐะฒะตะนัะต")
|
27 |
+
output_audio = gr.Audio(label="Generated Speech", type="filepath")
|
28 |
+
|
29 |
generate_button = gr.Button("Generate Speech")
|
30 |
|
31 |
+
# ๋ถ๊ฐ๋ฆฌ์์ด ํ
์คํธ๋ง ๋ฐ์ TTS ์ค๋์ค ํ์ผ ์์ฑ
|
32 |
+
generate_button.click(
|
33 |
+
bulgarian_tts,
|
34 |
+
inputs=bulgarian_input,
|
35 |
+
outputs=output_audio
|
36 |
+
)
|
37 |
|
38 |
if __name__ == "__main__":
|
39 |
demo.launch()
|