File size: 3,796 Bytes
ab68a53
 
 
 
 
9a60809
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ab68a53
 
 
 
9a60809
 
ab68a53
9a60809
ab68a53
 
 
 
 
 
9a60809
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ab68a53
 
9a60809
ab68a53
 
 
 
 
 
9a60809
 
 
 
 
 
 
 
 
 
ab68a53
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import gradio as gr
from gtts import gTTS
from pydub import AudioSegment
from io import BytesIO

def multilingual_tts(
    korean_text,
    british_text,        # 기존 영국식 입력란
    american_text,       # 기존 미국식 입력란
    british_text_add1,   # 추가 영국식 입력란 1
    british_text_add2,   # 추가 영국식 입력란 2
    australian_text_add1, # 추가 호주식 입력란 1
    australian_text_add2, # 추가 호주식 입력란 2
    american_text_add1   # 추가 미국식 입력란 1
):
    # 각 음성에 대해 (언어 코드, tld, 텍스트) 튜플을 리스트에 저장합니다.
    voices = [
        ("ko", "com", korean_text),                      # 한국어
        ("en", "co.uk", british_text),                   # 기존 영국식
        ("en", "com", american_text),                    # 기존 미국식
        ("en", "co.uk", british_text_add1),              # 추가 영국식 1
        ("en", "co.uk", british_text_add2),              # 추가 영국식 2
        ("en", "com.au", australian_text_add1),          # 추가 호주식 1
        ("en", "com.au", australian_text_add2),          # 추가 호주식 2
        ("en", "com", american_text_add1)                # 추가 미국식 1
    ]
    
    combined_audio = AudioSegment.silent(duration=0)  # 빈 오디오
    
    for lang, tld, text in voices:
        if text.strip():  # 텍스트가 입력되어 있을 때만 처리
            tts = gTTS(text, lang=lang, tld=tld)
            audio_file = BytesIO()
            tts.write_to_fp(audio_file)
            audio_file.seek(0)
            tts_audio = AudioSegment.from_file(audio_file, format="mp3")
            # 각 음성 사이에 500ms의 침묵 추가
            combined_audio += tts_audio + AudioSegment.silent(duration=500)
    
    # 최종 결합된 오디오를 mp3 파일로 저장
    output_file = "combined_output.mp3"
    combined_audio.export(output_file, format="mp3")
    
    return output_file

with gr.Blocks() as demo:
    gr.Markdown("## Multilingual TTS: Generate a Single Audio File (총 8개 음성)")
    
    # 한국어 입력란
    korean_input = gr.Textbox(label="Enter Korean Text:", placeholder="안녕하세요")
    
    # 기존 영어 입력란 (영국, 미국)
    with gr.Row():
        british_input = gr.Textbox(label="Enter British English Text:", placeholder="Hello (British)")
        american_input = gr.Textbox(label="Enter American English Text:", placeholder="Hello (American)")
    
    # 추가 영어 입력란
    with gr.Row():
        british_input_add1 = gr.Textbox(label="Enter Additional British English Text 1:", placeholder="Hi there (British)")
        british_input_add2 = gr.Textbox(label="Enter Additional British English Text 2:", placeholder="Good day (British)")
    
    with gr.Row():
        australian_input_add1 = gr.Textbox(label="Enter Additional Australian English Text 1:", placeholder="G'day (Australian)")
        australian_input_add2 = gr.Textbox(label="Enter Additional Australian English Text 2:", placeholder="How ya going? (Australian)")
    
    with gr.Row():
        american_input_add1 = gr.Textbox(label="Enter Additional American English Text:", placeholder="Hey (American)")
    
    output_audio = gr.Audio(label="Generated Speech", type="filepath")
    generate_button = gr.Button("Generate Speech")
    
    generate_button.click(
        multilingual_tts, 
        inputs=[
            korean_input, 
            british_input, 
            american_input,
            british_input_add1, 
            british_input_add2, 
            australian_input_add1, 
            australian_input_add2, 
            american_input_add1
        ], 
        outputs=output_audio
    )

if __name__ == "__main__":
    demo.launch()