File size: 3,981 Bytes
aa95dd5
bc18a34
 
a2087de
189c85a
 
 
 
 
 
 
 
 
f441359
189c85a
 
 
 
a160271
189c85a
 
 
a160271
 
a2087de
c77f602
d8bb1cb
 
a2087de
 
c77f602
5a96413
c77f602
 
a2087de
 
 
bc18a34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
699ea5d
02665d5
 
 
7d0efdb
bc18a34
699ea5d
 
02665d5
bc18a34
 
2796462
150e1e4
a56731b
189c85a
 
8b95e13
2d9d2d5
2796462
65dcd62
2796462
 
 
a2087de
2796462
 
bc18a34
b3012ac
bc18a34
189c85a
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
import gradio as gr
import requests

def generate_audio(text, voice_name):

 # ๊ฐ ์Œ์„ฑ ์˜ต์…˜์— ๋Œ€ํ•œ ๊ธฐ๋ณธ ํ…์ŠคํŠธ ์˜ˆ์‹œ
    default_examples = {
        "๋‚จ์„ฑAI": "์•ˆ๋…•ํ•˜์„ธ์š”, ๋‚จ์„ฑ AI ํ‘œ์ค€ ์Œ์„ฑ์ž…๋‹ˆ๋‹ค.",
        "์—ฌ์„ฑAI": "์•ˆ๋…•ํ•˜์„ธ์š”, ์—ฌ์„ฑ AI ํ‘œ์ค€ ์Œ์„ฑ์ž…๋‹ˆ๋‹ค.",
        "ํŠธ๋Ÿผํ”„": "Make, America, Great, Again!  , ๋‹ค์‹œ, ์œ„๋Œ€ํ•œ, ๋ฏธ๊ตญ์„, ๋งŒ๋“ญ์‹œ๋‹ค!",        
        "์ฐจ์Šน์›": "์•ˆ๋…•ํ•˜์„ธ์š”, ์ƒˆํ•ด ๋ณต ๋งŽ์ด ๋ฐ›์œผ์‹œ๊ธธ ๊ธฐ์›ํ•ฉ๋‹ˆ๋‹ค.",
        "๊น€์ •์€": "์•ˆ๋…•ํ•˜์„ธ์š”, ์ƒˆํ•ด ๋ณต ๋งŽ์ด ๋ฐ›์œผ์‹œ๊ธธ ๊ธฐ์›ํ•ฉ๋‹ˆ๋‹ค.",
        "๋…ธ๋ฌดํ˜„": "์•ˆ๋…•ํ•˜์„ธ์š”, ์ƒˆํ•ด ๋ณต ๋งŽ์ด ๋ฐ›์œผ์‹œ๊ธธ ๊ธฐ์›ํ•ฉ๋‹ˆ๋‹ค.",
        "๊ณฝ์ฒ ์šฉ": "๋งˆํฌ ๋Œ€๊ต๋Š” ๋ฌด๋„ˆ์กŒ๋ƒ~? , ๋‚ด ์ˆœ์ •์„ ๋ฌป๊ณ , ๋”๋ธ”๋กœ ๊ฐ€~!",        
        "๊ถ์˜ˆ": "์•ˆ๋…•ํ•˜์„ธ์š”, ๋ฏธ๋ฅต์˜ ๊ฐ€๋ฅด์นจ์€, ์˜ด๋งˆ๋‹ˆ ๋ฐ˜๋ฉ”ํ™ˆ์ด๋‹ˆ๋ผ.",
        "์œค์„์—ด": "์•ˆ๋…•ํ•˜์„ธ์š”, ์ƒˆํ•ด ๋ณต ๋งŽ์ด ๋ฐ›์œผ์‹œ๊ธธ ๊ธฐ์›ํ•ฉ๋‹ˆ๋‹ค."
    }

    MAX_CHARS = 100
    if not text:
        text = default_examples[voice_name]  # ์‚ฌ์šฉ์ž ์ž…๋ ฅ์ด ์—†์œผ๋ฉด ๊ธฐ๋ณธ ์˜ˆ์‹œ ์‚ฌ์šฉ
    elif len(text) > MAX_CHARS:
        text = text[:MAX_CHARS]  # ์ตœ๋Œ€ ๊ธ€์ž์ˆ˜๋กœ ํ…์ŠคํŠธ ์ž๋ฅด๊ธฐ
        
    voices = {
        "๋‚จ์„ฑAI": "6uQD2RqeSgIey9LVBafG",
        "์—ฌ์„ฑAI": "jeuEgCxtyEYkC3zsQODy",  
        "ํŠธ๋Ÿผํ”„": "nP4xQZkEwzlvgutdc3xM",         
        "์ฐจ์Šน์›": "SKwm0HLYsVDCM2ruvw2p",
        "๊น€์ •์€": "YPWL3nQPzBN1XaiZF4aj",
        "๋…ธ๋ฌดํ˜„": "6JdivX36i1eJ3LqLmvwH",
        "๊ณฝ์ฒ ์šฉ": "xareIzgmUtHZat32qZIN",             
        "๊ถ์˜ˆ": "4kFrgJPCTjA6DyPM5Gr5",        
        "์œค์„์—ด": "Qrf03Q67kRgpFlj9fto3"        
    }
    voice_id = voices[voice_name]
    url = f"https://api.elevenlabs.io/v1/text-to-speech/{voice_id}"
    model_id = "eleven_multilingual_v2"
    payload = {
        "model_id": model_id,
        "text": text,
        "voice_settings": {
            "similarity_boost": 0.75,
            "stability": 0.5,
            "style": 0,
            "use_speaker_boost": True
        }
    }
    headers = {
        "Content-Type": "application/json",
        "xi-api-key": "c5fb99a2b25402f104d246379bcf819a"
    }

    response = requests.post(url, json=payload, headers=headers, stream=True)

    if response.status_code == 200:
        chunks = []
        for chunk in response.iter_content(chunk_size=CHUNK_SIZE):
            chunks.append(chunk)
        return b''.join(chunks)
    else:
        raise Exception(f"์˜ค๋ฅ˜ ๋ฐœ์ƒ. ์ƒํƒœ ์ฝ”๋“œ: {response.status_code}")

CHUNK_SIZE = 1024


# Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
with gr.Blocks() as demo:
    gr.Markdown("FakeVoice: AI๊ฐ€ ๋ณต์ œํ•œ ์œ ๋ช…์ธ์˜ ์Œ์„ฑ์œผ๋กœ, ํ…์ŠคํŠธ๋งŒ ์ž…๋ ฅํ•˜๋ฉด ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ํ•ด๋‹น ์ธ๋ฌผ์˜ ์Œ์„ฑ์œผ๋กœ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.")    
    gr.Markdown("์ง€๊ธˆ ์ปค๋ฎค๋‹ˆํ‹ฐ์— ์ฐธ์—ฌํ•˜์‹œ๋ฉด ๋”์šฑ ๋งŽ์€ ์ •๋ณด์™€ ๋‹ค์–‘ํ•œ ๊ธฐํšŒ๋ฅผ ์–ป์œผ์‹ค ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ปค๋ฎค๋‹ˆํ‹ฐ ์ฐธ์—ฌ ๋งํฌ https://open.kakao.com/o/gE6hK9Vf ")
    gr.Markdown("์Œ์„ฑ์„ ๋จผ์ € ์„ ํƒํ•œ ํ›„ ์›ํ•˜์‹œ๋Š” ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”. ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜์ง€ ์•Š๊ณ  ์ƒ์„ฑ์„ ๋ˆ„๋ฅด๋ฉด ์˜ˆ์‹œ ๋Œ€์‚ฌ๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.")    
    gr.Markdown("์ƒ์„ฑ๋œ ์˜ค๋””์˜ค๋ฅผ ๋‹ค์šด๋กœ๋“œ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์šด๋กœ๋“œ ๋ฐ›์œผ์‹  ํ›„ ๋‹ค์šด๋กœ๋“œ ๋ฐ›์€ ํŒŒ์ผ์˜ ํ™•์žฅ์ž๋ฅผ mp3๋กœ ๋ณ€๊ฒฝํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ")        
    voice_choice = gr.Dropdown(choices=["๋‚จ์„ฑAI", "์—ฌ์„ฑAI", "ํŠธ๋Ÿผํ”„", "์ฐจ์Šน์›", "๊น€์ •์€", "๋…ธ๋ฌดํ˜„", "๊ณฝ์ฒ ์šฉ", "๊ถ์˜ˆ", "์œค์„์—ด"], label="์Œ์„ฑ ์„ ํƒ")    
    text_input = gr.Textbox(label="์Œ์„ฑ์œผ๋กœ ์ƒ์„ฑํ•  ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”.(100๊ธ€์ž ์ด๋‚ด ์ œํ•œ ์„ค์ •๋˜์–ด, ์ดˆ๊ณผ์‹œ ์Œ์„ฑ ์ƒ์„ฑ์ด ์ œํ•œ๋ฉ๋‹ˆ๋‹ค.)")
    submit_button = gr.Button("์ƒ์„ฑ")
    audio_output = gr.Audio(label="์ƒ์„ฑ๋œ ์˜ค๋””์˜ค")

    submit_button.click(
        fn=generate_audio,
        inputs=[text_input, voice_choice],
        outputs=audio_output
    )


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