diff --git a/TTS/engine_wrapper.py b/TTS/engine_wrapper.py index 2dac26d..89e3b7a 100644 --- a/TTS/engine_wrapper.py +++ b/TTS/engine_wrapper.py @@ -104,11 +104,10 @@ class TTSEngine: def split_post(self, text: str, idx): split_files = [] + pattern = r" *(((.|\n){0," + str(self.tts_module.max_chars) + r"})(\.|.$))" split_text = [ x.group().strip() - for x in re.finditer( - r" *(((.|\n){0," + str(self.tts_module.max_chars) + "})(\.|.$))", text - ) + for x in re.finditer(pattern, text) ] self.create_silence_mp3() diff --git a/main.py b/main.py index c6a4ae4..01c2dad 100755 --- a/main.py +++ b/main.py @@ -4,7 +4,7 @@ import sys from os import name from pathlib import Path from subprocess import Popen -from typing import Dict, NoReturn +from typing import Dict, NoReturn, Union from platforms import get_content_object, get_screenshot_fn from utils import settings @@ -46,7 +46,7 @@ print_markdown( checkversion(__VERSION__) reddit_id: str -reddit_object: Dict[str, str | list] +reddit_object: Dict[str, Union[str, list]] def _get_platform_post_id(config: dict, platform: str) -> str: @@ -96,9 +96,9 @@ def shutdown() -> NoReturn: if __name__ == "__main__": - if sys.version_info.major != 3 or sys.version_info.minor not in [10, 11, 12]: + if sys.version_info.major != 3 or sys.version_info.minor < 10: print( - "Hey! Congratulations, you've made it so far (which is pretty rare with no Python 3.10). Unfortunately, this program only works on Python 3.10. Please install Python 3.10 and try again." + "Hey! Congratulations, you've made it so far (which is pretty rare with no Python 3.10). Unfortunately, this program requires Python 3.10 or later. Please install Python 3.10+ and try again." ) sys.exit() ffmpeg_install() diff --git a/requirements.txt b/requirements.txt index 170f90c..606cf11 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,21 +1,21 @@ -boto3==1.36.8 -botocore==1.36.8 +boto3==1.42.94 +botocore==1.42.94 gTTS==2.5.4 moviepy==2.2.1 -playwright==1.49.1 +playwright==1.58.0 praw==7.8.1 -requests==2.32.3 -rich==13.9.4 +requests==2.32.5 +rich==15.0.0 toml==0.10.2 translators==5.9.9 pyttsx3==2.98 -tomlkit==0.13.2 -Flask==3.1.1 +tomlkit==0.14.0 +Flask==3.1.3 clean-text==0.6.0 unidecode==1.4.0 -spacy==3.8.7 -torch==2.7.0 -transformers==4.52.4 +torch==2.11.0 +transformers==4.57.6 +# spacy==3.8.7 # Optional: only for advanced text parsing (not yet Python 3.14 compatible) ffmpeg-python==0.2.0 -elevenlabs==1.57.0 +elevenlabs==2.44.0 yt-dlp==2025.10.14 diff --git a/utils/fonts.py b/utils/fonts.py index 4980f6a..abca8fc 100644 --- a/utils/fonts.py +++ b/utils/fonts.py @@ -1,13 +1,14 @@ +from typing import Union from PIL.ImageFont import FreeTypeFont, ImageFont -def getsize(font: ImageFont | FreeTypeFont, text: str): +def getsize(font: Union[ImageFont, FreeTypeFont], text: str): left, top, right, bottom = font.getbbox(text) width = right - left height = bottom - top return width, height -def getheight(font: ImageFont | FreeTypeFont, text: str): +def getheight(font: Union[ImageFont, FreeTypeFont], text: str): _, height = getsize(font, text) return height diff --git a/utils/posttextparser.py b/utils/posttextparser.py index 2bb930e..b26ab0f 100644 --- a/utils/posttextparser.py +++ b/utils/posttextparser.py @@ -3,15 +3,29 @@ import re import time from typing import List -import spacy +try: + import spacy + SPACY_AVAILABLE = True +except ImportError: + SPACY_AVAILABLE = False from utils.console import print_step from utils.voice import sanitize_text +def _fallback_sentence_split(text: str) -> List[str]: + """Fallback sentence splitter when spacy is not available.""" + sentences = re.split(r'[.!?]+', text) + return [s.strip() for s in sentences if s.strip()] + + # working good def posttextparser(obj, *, tried: bool = False) -> List[str]: text: str = re.sub("\n", " ", obj) + + if not SPACY_AVAILABLE: + return _fallback_sentence_split(text) + try: nlp = spacy.load("en_core_web_sm") except OSError as e: @@ -20,9 +34,9 @@ def posttextparser(obj, *, tried: bool = False) -> List[str]: time.sleep(5) return posttextparser(obj, tried=True) print_step( - "The spacy model can't load. You need to install it with the command \npython -m spacy download en_core_web_sm " + "The spacy model can't load. Falling back to regex-based sentence splitting. Install with: python -m spacy download en_core_web_sm" ) - raise e + return _fallback_sentence_split(text) doc = nlp(text)