ginipick commited on
Commit
df2ed54
Β·
verified Β·
1 Parent(s): eefe610

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -56
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
- if __name__ == '__main__':
64
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
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)