tts will no longer read aloud link

There is an often issue where when commentators link to another site the tts will read out the link in its entirety. This PR uses Regex to filter that stuff out.
pull/311/head
null3000 3 years ago committed by GitHub
parent 718b005d07
commit f55dda166a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,6 +3,7 @@ from pathlib import Path
from mutagen.mp3 import MP3 from mutagen.mp3 import MP3
from utils.console import print_step, print_substep from utils.console import print_step, print_substep
from rich.progress import track from rich.progress import track
import re
def save_text_to_mp3(reddit_obj): def save_text_to_mp3(reddit_obj):
@ -25,7 +26,9 @@ def save_text_to_mp3(reddit_obj):
# ! Stop creating mp3 files if the length is greater than 50 seconds. This can be longer, but this is just a good starting point # ! Stop creating mp3 files if the length is greater than 50 seconds. This can be longer, but this is just a good starting point
if length > 50: if length > 50:
break break
tts = gTTS(text=comment["comment_body"], lang="en", slow=False) comment=comment["comment_body"]
text=re.sub('((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z]){2,6}([a-zA-Z0-9\.\&\/\?\:@\-_=#])*', '', comment)
tts = gTTS(text, lang="en", slow=False)
tts.save(f"assets/mp3/{idx}.mp3") tts.save(f"assets/mp3/{idx}.mp3")
length += MP3(f"assets/mp3/{idx}.mp3").info.length length += MP3(f"assets/mp3/{idx}.mp3").info.length

Loading…
Cancel
Save