@ -9,7 +9,7 @@ from TTS.GTTS import GTTS
from TTS . streamlabs_polly import StreamlabsPolly
from TTS . streamlabs_polly import StreamlabsPolly
from TTS . aws_polly import AWSPolly
from TTS . aws_polly import AWSPolly
from TTS . TikTok import TikTok
from TTS . TikTok import TikTok
from TTS . pyttsx import p yttsx
from TTS . pyttsx import P yttsx
from utils import settings
from utils import settings
from utils . console import print_table , print_step
from utils . console import print_table , print_step
@ -21,7 +21,7 @@ TTSProviders = {
" AWSPolly " : AWSPolly ,
" AWSPolly " : AWSPolly ,
" StreamlabsPolly " : StreamlabsPolly ,
" StreamlabsPolly " : StreamlabsPolly ,
" TikTok " : TikTok ,
" TikTok " : TikTok ,
" pyttsx " : p yttsx,
" pyttsx " : P yttsx,
}
}
@ -37,7 +37,9 @@ def save_text_to_mp3(reddit_obj) -> Tuple[int, int]:
voice = settings . config [ " settings " ] [ " tts " ] [ " voice_choice " ]
voice = settings . config [ " settings " ] [ " tts " ] [ " voice_choice " ]
if str ( voice ) . casefold ( ) in map ( lambda _ : _ . casefold ( ) , TTSProviders ) :
if str ( voice ) . casefold ( ) in map ( lambda _ : _ . casefold ( ) , TTSProviders ) :
text_to_mp3 = TTSEngine ( get_case_insensitive_key_value ( TTSProviders , voice ) , reddit_obj )
text_to_mp3 = TTSEngine (
get_case_insensitive_key_value ( TTSProviders , voice ) , reddit_obj
)
else :
else :
while True :
while True :
print_step ( " Please choose one of the following TTS providers: " )
print_step ( " Please choose one of the following TTS providers: " )
@ -46,12 +48,18 @@ def save_text_to_mp3(reddit_obj) -> Tuple[int, int]:
if choice . casefold ( ) in map ( lambda _ : _ . casefold ( ) , TTSProviders ) :
if choice . casefold ( ) in map ( lambda _ : _ . casefold ( ) , TTSProviders ) :
break
break
print ( " Unknown Choice " )
print ( " Unknown Choice " )
text_to_mp3 = TTSEngine ( get_case_insensitive_key_value ( TTSProviders , choice ) , reddit_obj )
text_to_mp3 = TTSEngine (
get_case_insensitive_key_value ( TTSProviders , choice ) , reddit_obj
)
return text_to_mp3 . run ( )
return text_to_mp3 . run ( )
def get_case_insensitive_key_value ( input_dict , key ) :
def get_case_insensitive_key_value ( input_dict , key ) :
return next (
return next (
( value for dict_key , value in input_dict . items ( ) if dict_key . lower ( ) == key . lower ( ) ) ,
(
value
for dict_key , value in input_dict . items ( )
if dict_key . lower ( ) == key . lower ( )
) ,
None ,
None ,
)
)