Spaces:
Sleeping
Sleeping
File size: 1,056 Bytes
eefe9ae |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import gradio as gr
from gtts import gTTS
import os
def text_to_speech(prompt):
# ์
๋ ฅ๋ Bulgarian ํ
์คํธ๋ฅผ ์์ฑ์ผ๋ก ๋ณํ
tts = gTTS(text=prompt, lang="bg") # 'bg'๋ Bulgarian ์ธ์ด ์ฝ๋์
๋๋ค.
audio_file = "output.mp3"
tts.save(audio_file)
# ํ์ผ ๊ฒฝ๋ก ๋์ ๋ฐ์ด๋๋ฆฌ ๋ฐ์ดํฐ๋ฅผ ๋ฐํํฉ๋๋ค.
with open(audio_file, "rb") as f:
audio_binary = f.read()
# ์์ ํ์ผ ์ญ์
os.remove(audio_file)
return audio_binary
with gr.Blocks() as demo:
gr.Markdown("## Bulgarian Text-to-Speech (TTS)")
with gr.Row():
input_prompt = gr.Textbox(label="Enter a prompt in Bulgarian:")
# gr.Audio์ type์ "binary"๋ก ์ง์ ํ์ฌ ํ์ผ ๊ฒฝ๋ก ๋์ ๋ฐ์ด๋๋ฆฌ ๋ฐ์ดํฐ๋ฅผ ์ฌ์ฉํฉ๋๋ค.
output_audio = gr.Audio(label="Generated Speech", type="binary")
generate_button = gr.Button("Generate Speech")
generate_button.click(text_to_speech, inputs=input_prompt, outputs=output_audio)
if __name__ == "__main__":
demo.launch()
|