@ -1,9 +1,11 @@
from gtts import gTTS
from pathlib import Path
from pathlib import Path
from gtts import gTTS
from mutagen . mp3 import MP3
from mutagen . mp3 import MP3
from utils . console import print_step , print_substep
from rich . progress import track
from rich . progress import track
from utils . console import print_step , print_substep
def save_text_to_mp3 ( reddit_obj ) :
def save_text_to_mp3 ( reddit_obj ) :
""" Saves Text to MP3 files.
""" Saves Text to MP3 files.
@ -11,15 +13,16 @@ def save_text_to_mp3(reddit_obj):
Args :
Args :
reddit_obj : The reddit object you received from the reddit API in the askreddit . py file .
reddit_obj : The reddit object you received from the reddit API in the askreddit . py file .
"""
"""
print_step ( " Saving Text to MP3 files... " )
length = 0
length = 0
print_step ( " Saving Text to MP3 files... " )
# Create a folder for the mp3 files.
# Create a folder for the mp3 files.
Path ( " assets/mp3 " ) . mkdir ( parents = True , exist_ok = True )
Path ( " assets/mp3 " ) . mkdir ( parents = True , exist_ok = True )
tts = gTTS ( text = reddit_obj [ " thread_title " ] , lang = " en " , slow = False )
tts = gTTS ( text = reddit_obj [ " thread_title " ] , lang = " en " , slow = False )
tts . save ( f " assets/mp3/title.mp3 " )
tts . save ( " assets/mp3/title.mp3 " )
length + = MP3 ( f " assets/mp3/title.mp3 " ) . info . length
length + = MP3 ( " assets/mp3/title.mp3 " ) . info . length
for idx , comment in track ( enumerate ( reddit_obj [ " comments " ] ) , " Saving... " ) :
for idx , comment in track ( enumerate ( reddit_obj [ " comments " ] ) , " Saving... " ) :
# ! 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