englissi commited on
Commit
0733e62
Β·
verified Β·
1 Parent(s): a318156

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
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
- # 🎡 이미 μƒμ„±λœ μŒμ„±μ΄ 있으면 μž¬μ‚¬μš© (429 였λ₯˜ λ°©μ§€)
65
  if text in cached_audio:
66
  return cached_audio[text]
67
 
68
- # 🎡 κ³ μœ ν•œ 파일λͺ… 생성
69
- hash_key = hashlib.md5(text.encode()).hexdigest()[:10] # ν•΄μ‹œ μ•ž 10자리 μ‚¬μš©
70
  filename = f"audio_{hash_key}.mp3"
71
 
72
- # 🎡 gTTSλ₯Ό μ‚¬μš©ν•˜μ—¬ μŒμ„± 생성
73
  tts = gTTS(text=text, lang="en")
74
  tts.save(filename)
75
 
76
- print(f"βœ… μŒμ„± 파일 생성 μ™„λ£Œ: {filename}")
 
 
77
 
78
- # 🎡 μƒμ„±λœ 파일 캐싱
79
- cached_audio[text] = filename
80
 
81
- # 🎡 μš”μ²­ μ œν•œμ„ ν”Όν•˜κΈ° μœ„ν•΄ 1.5초 λŒ€κΈ°
82
  time.sleep(1.5)
83
 
84
- return filename
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)