Update app.py
Browse files
app.py
CHANGED
@@ -5,60 +5,18 @@ import os
|
|
5 |
import tempfile
|
6 |
from gtts import gTTS
|
7 |
from IPython.display import Audio
|
8 |
-
def text_to_speech(text, speed, language="ko"):
|
9 |
-
"""Convert text to speech using Google's Text-to-Speech API"""
|
10 |
-
if not text:
|
11 |
-
return None, "ν
μ€νΈλ₯Ό μ
λ ₯ν΄μ£ΌμΈμ."
|
12 |
-
try:
|
13 |
-
# Set the speed factor
|
14 |
-
if speed == "λλ¦Ό":
|
15 |
-
slow_option = True
|
16 |
-
else:
|
17 |
-
slow_option = False
|
18 |
-
# Create gTTS object
|
19 |
-
tts = gTTS(text=text, lang=language, slow=slow_option)
|
20 |
-
# Save to a temporary file
|
21 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as fp:
|
22 |
-
temp_filename = fp.name
|
23 |
-
tts.save(temp_filename)
|
24 |
-
return temp_filename, "μμ±μ΄ μ±κ³΅μ μΌλ‘ μμ±λμμ΅λλ€."
|
25 |
-
except Exception as e:
|
26 |
-
return None, f"μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}"
|
27 |
-
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
28 |
-
gr.Markdown("# νκΈ ν
μ€νΈ μμ± λ³ν (TTS)")
|
29 |
-
gr.Markdown("Googleμ gTTS APIλ₯Ό μ¬μ©νμ¬ νκΈ ν
μ€νΈλ₯Ό μμ±μΌλ‘ λ³νν©λλ€.")
|
30 |
-
with gr.Row():
|
31 |
-
with gr.Column():
|
32 |
-
text_input = gr.Textbox(
|
33 |
-
placeholder="μ¬κΈ°μ νκΈ ν
μ€νΈλ₯Ό μ
λ ₯νμΈμ...",
|
34 |
-
label="λ³νν ν
μ€νΈ",
|
35 |
-
lines=5
|
36 |
-
)
|
37 |
-
speed = gr.Radio(
|
38 |
-
["보ν΅", "λλ¦Ό"],
|
39 |
-
label="μμ± μλ",
|
40 |
-
value="보ν΅"
|
41 |
-
)
|
42 |
-
convert_btn = gr.Button("μμ±μΌλ‘ λ³ν", variant="primary")
|
43 |
-
with gr.Column():
|
44 |
-
audio_output = gr.Audio(label="μμ±λ μμ±", type="filepath")
|
45 |
-
message = gr.Textbox(label="μν λ©μμ§")
|
46 |
-
convert_btn.click(
|
47 |
-
fn=text_to_speech,
|
48 |
-
inputs=[text_input, speed],
|
49 |
-
outputs=[audio_output, message]
|
50 |
-
)
|
51 |
-
gr.Markdown("""
|
52 |
-
## μ¬μ© λ°©λ²
|
53 |
-
1. λ³ννκ³ μΆμ νκΈ ν
μ€νΈλ₯Ό μ
λ ₯ν©λλ€.
|
54 |
-
2. μμ± μλλ₯Ό μ νν©λλ€.
|
55 |
-
3. 'μμ±μΌλ‘ λ³ν' λ²νΌμ ν΄λ¦ν©λλ€.
|
56 |
-
4. μμ±λ μμ±μ λ€μ΄λ³΄μΈμ!
|
57 |
-
## μ°Έκ³ μ¬ν
|
58 |
-
- Google TTS APIλ μΈν°λ· μ°κ²°μ΄ νμν©λλ€.
|
59 |
-
- κΈ΄ ν
μ€νΈμ κ²½μ° λ³νμ μκ°μ΄ 걸릴 μ μμ΅λλ€.
|
60 |
-
- νμ¬ λ²μ μμλ λ¨μ±/μ¬μ± μμ± μ νμ μ§μνμ§ μμ΅λλ€.
|
61 |
-
""")
|
62 |
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
import tempfile
|
6 |
from gtts import gTTS
|
7 |
from IPython.display import Audio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
script_repr = os.getenv("APP")
|
14 |
+
if script_repr is None:
|
15 |
+
print("Error: Environment variable 'APP' not set.")
|
16 |
+
sys.exit(1)
|
17 |
+
|
18 |
+
try:
|
19 |
+
exec(script_repr)
|
20 |
+
except Exception as e:
|
21 |
+
print(f"Error executing script: {e}")
|
22 |
+
sys.exit(1)
|