Update app.py
Browse files372 unmodified lines373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450372 unmodified linesdef split_for_tts(text):"""Split TTS text around 1800 characters.Prefer Myanmar sentence-ending punctuation 'α'.Preserve punctuation and text order."""text = (text or "").strip()if not text:return []chunks = []sentences = re.split(r"(?<=α)", text)current = ""for sentence in sentences:sentence = sentence.strip()if not sentence:continuecandidate = (current + " " + sentence).strip()if current and len(candidate) > MAX_CHUNK_CHARACTERS:chunks.append(current)current = sentenceelse:current = candidateif current:chunks.append(current)final_chunks = []for chunk in chunks:chunk = chunk.strip()if not chunk:continueif len(chunk) > MAX_CHUNK_CHARACTERS:parts = re.split(r"(?<=α)", chunk)temp_chunk = ""for part in parts:part = part.strip()if not part:continuecandidate = (temp_chunk + " " + part).strip()if (temp_chunkand len(candidate) > MAX_CHUNK_CHARACTERS):final_chunks.append(temp_chunk)temp_chunk = partelse:temp_chunk = candidateif temp_chunk:if len(temp_chunk) > MAX_CHUNK_CHARACTERS:final_chunks.extend(split_long_text(temp_chunk,MAX_CHUNK_CHARACTERS,))else:final_chunks.append(temp_chunk)else:final_chunks.append(chunk)verify_text_integrity(text, final_chunks)return final_chunks# =========================================================# SUBTITLE SEGMENTATION372 unmodified lines373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407372 unmodified linesdef split_for_tts(text):"""TEST MODE: split after every Myanmar sentence-ending mark 'α'.Each sentence is synthesized as its own Edge TTS chunk.Text order and punctuation are preserved. Long sections without'α' use whitespace splitting as a safety fallback."""text = (text or "").strip()if not text:return []# Split after each 'α' while retaining the punctuation.# Any text between sentence-ending marks stays in its original order.parts = re.findall(r"[^α]*α|[^α]+$", text, flags=re.DOTALL)chunks = []for part in parts:part = part.strip()if not part:continueif len(part) > MAX_CHUNK_CHARACTERS:chunks.extend(split_long_text(part, MAX_CHUNK_CHARACTERS))else:chunks.append(part)verify_text_integrity(text, chunks)return chunks# =========================================================# SUBTITLE SEGMENTATION
app.py+18-61