Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -56,36 +56,36 @@ blends_digraphs_stories = [
|
|
56 |
{"text": "A swan swims in the sweet lake.", "image": f"{image_base_url}38.webp"}
|
57 |
]
|
58 |
|
59 |
-
# π gTTSλ₯Ό μ¬μ©νμ¬ μμ± νμΌ μμ± (κ³ μ ν νμΌλͺ
+ μΊμ± μμ€ν
μΆκ°)
|
60 |
-
cached_audio = {} # κ°μ λ¬Έμ₯μ λν΄ APIλ₯Ό μ¬λ¬ λ² νΈμΆνμ§ μλλ‘ μ μ₯
|
61 |
-
|
62 |
def generate_audio(text):
|
63 |
try:
|
64 |
-
#
|
65 |
if text in cached_audio:
|
66 |
return cached_audio[text]
|
67 |
|
68 |
-
#
|
69 |
-
hash_key = hashlib.md5(text.encode()).hexdigest()[:10]
|
70 |
filename = f"audio_{hash_key}.mp3"
|
71 |
|
72 |
-
#
|
73 |
tts = gTTS(text=text, lang="en")
|
74 |
tts.save(filename)
|
75 |
|
76 |
-
|
|
|
|
|
77 |
|
78 |
-
#
|
79 |
-
cached_audio[text] =
|
80 |
|
81 |
-
#
|
82 |
time.sleep(1.5)
|
83 |
|
84 |
-
return
|
85 |
except Exception as e:
|
86 |
print(f"β οΈ μμ± μμ± μ€ν¨: {e}")
|
87 |
return None
|
88 |
|
|
|
89 |
# π "λ€μ" λ²νΌ ν΄λ¦ μ νΈμΆλλ ν¨μ (HTML ν¬ν¨)
|
90 |
def next_story(current_index, story_list):
|
91 |
new_index = (current_index + 1) % len(story_list)
|
|
|
56 |
{"text": "A swan swims in the sweet lake.", "image": f"{image_base_url}38.webp"}
|
57 |
]
|
58 |
|
|
|
|
|
|
|
59 |
def generate_audio(text):
|
60 |
try:
|
61 |
+
# μ΄λ―Έ μμ±λ μμ±μ΄ μμΌλ©΄ μ¬μ¬μ© (429 μ€λ₯ λ°©μ§)
|
62 |
if text in cached_audio:
|
63 |
return cached_audio[text]
|
64 |
|
65 |
+
# κ³ μ ν νμΌλͺ
μμ± (ν΄μ μ 10μ리 μ¬μ©)
|
66 |
+
hash_key = hashlib.md5(text.encode()).hexdigest()[:10]
|
67 |
filename = f"audio_{hash_key}.mp3"
|
68 |
|
69 |
+
# gTTSλ₯Ό μ¬μ©νμ¬ μμ± μμ±
|
70 |
tts = gTTS(text=text, lang="en")
|
71 |
tts.save(filename)
|
72 |
|
73 |
+
# μ λ κ²½λ‘λ‘ λ³ν
|
74 |
+
abs_filename = os.path.abspath(filename)
|
75 |
+
print(f"β
μμ± νμΌ μμ± μλ£: {abs_filename}")
|
76 |
|
77 |
+
# μμ±λ νμΌ μΊμ±
|
78 |
+
cached_audio[text] = abs_filename
|
79 |
|
80 |
+
# μμ² μ νμ νΌνκΈ° μν΄ 1.5μ΄ λκΈ°
|
81 |
time.sleep(1.5)
|
82 |
|
83 |
+
return abs_filename
|
84 |
except Exception as e:
|
85 |
print(f"β οΈ μμ± μμ± μ€ν¨: {e}")
|
86 |
return None
|
87 |
|
88 |
+
|
89 |
# π "λ€μ" λ²νΌ ν΄λ¦ μ νΈμΆλλ ν¨μ (HTML ν¬ν¨)
|
90 |
def next_story(current_index, story_list):
|
91 |
new_index = (current_index + 1) % len(story_list)
|