Spaces:
Running
Running
import gradio as gr | |
from gtts import gTTS | |
from pydub import AudioSegment | |
from io import BytesIO | |
def bulgarian_tts(bulgarian_text): | |
# gTTS를 이용해 불가리아어 텍스트를 음성으로 변환 | |
tts = gTTS(text=bulgarian_text, lang="bg") | |
# 메모리 버퍼에 mp3로 저장 후, pydub 오디오 세그먼트로 로딩 | |
audio_buffer = BytesIO() | |
tts.write_to_fp(audio_buffer) | |
audio_buffer.seek(0) | |
tts_audio = AudioSegment.from_file(audio_buffer, format="mp3") | |
# mp3 파일로 내보내기 | |
output_file = "bulgarian_output.mp3" | |
tts_audio.export(output_file, format="mp3") | |
return output_file | |
with gr.Blocks(css=""" | |
.gradio-container { font-family: 'Arial', sans-serif; } | |
.title { text-align: center; font-size: 24px; font-weight: bold; } | |
.textbox { border-radius: 8px; padding: 10px; } | |
.button { background-color: #4CAF50; color: white; border-radius: 8px; padding: 10px 15px; } | |
.button:hover { background-color: #45a049; } | |
""") as demo: | |
gr.Markdown("<div class='title'>🇧🇬 Bulgarian Text-to-Speech (TTS)</div>") | |
with gr.Row(): | |
bulgarian_input = gr.Textbox(label="Enter Bulgarian Text:", placeholder="Здравейте", elem_classes=["textbox"]) | |
with gr.Row(): | |
generate_button = gr.Button("🎤 Generate Speech", elem_classes=["button"]) | |
output_audio = gr.Audio(label="Generated Speech", type="filepath") | |
generate_button.click(bulgarian_tts, inputs=bulgarian_input, outputs=output_audio) | |
if __name__ == "__main__": | |
demo.launch() |