mr-don88 commited on
Commit
967c2e0
·
verified ·
1 Parent(s): 598dcf8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -36,12 +36,13 @@ def split_text(text, max_len=200):
36
  # ================= TTS (FIX QUAN TRỌNG) =================
37
  def tts(text, api_key, voice_id, model):
38
  time.sleep(random.uniform(0.8, 1.5))
 
39
  r = requests.post(
40
  f"https://api.elevenlabs.io/v1/text-to-speech/{voice_id}",
41
  headers={
42
  "xi-api-key": api_key,
43
  "Content-Type": "application/json",
44
- "Accept": "audio/mpeg" # 🔥 BẮT BUỘC
45
  },
46
  json={
47
  "text": text,
@@ -56,11 +57,14 @@ def tts(text, api_key, voice_id, model):
56
  },
57
  timeout=60
58
  )
59
- if r.status_code == 200 and len(r.content) > 1000:
 
60
  return r.content
 
61
  return None
62
 
63
 
 
64
  # ================= AUDIO + SRT =================
65
  def merge_audio(folder, fmt):
66
  files = natsort.natsorted(f for f in os.listdir(folder) if f.endswith(fmt))
 
36
  # ================= TTS (FIX QUAN TRỌNG) =================
37
  def tts(text, api_key, voice_id, model):
38
  time.sleep(random.uniform(0.8, 1.5))
39
+
40
  r = requests.post(
41
  f"https://api.elevenlabs.io/v1/text-to-speech/{voice_id}",
42
  headers={
43
  "xi-api-key": api_key,
44
  "Content-Type": "application/json",
45
+ "Accept": "audio/mpeg"
46
  },
47
  json={
48
  "text": text,
 
57
  },
58
  timeout=60
59
  )
60
+
61
+ if r.status_code == 200:
62
  return r.content
63
+
64
  return None
65
 
66
 
67
+
68
  # ================= AUDIO + SRT =================
69
  def merge_audio(folder, fmt):
70
  files = natsort.natsorted(f for f in os.listdir(folder) if f.endswith(fmt))