You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
RedditVideoMakerBot/video_creation/voices.py

52 lines
1.4 KiB

from TTS.engine_wrapper import TTSEngine
from TTS.GTTS import GTTS
from TTS.streamlabs_polly import StreamlabsPolly
from TTS.aws_polly import AWSPolly
from TTS.TikTok import TikTok
2 years ago
from utils import settings
from utils.console import print_table, print_step
TTSProviders = {
2 years ago
'GoogleTranslate': GTTS,
'AWSPolly': AWSPolly,
'StreamlabsPolly': StreamlabsPolly,
'TikTok': TikTok,
}
2 years ago
def save_text_to_mp3(
2 years ago
reddit_obj: dict,
) -> list:
"""Saves text to MP3 files.
Args:
reddit_obj (): Reddit object received from reddit API in reddit/subreddit.py
Returns:
2 years ago
The number of comments audio was generated for
"""
2 years ago
voice = settings.config['settings']['tts']['choice']
if voice.casefold() not in map(lambda _: _.casefold(), TTSProviders):
while True:
2 years ago
print_step('Please choose one of the following TTS providers: ')
print_table(TTSProviders)
2 years ago
voice = input('\n')
if voice.casefold() in map(lambda _: _.casefold(), TTSProviders):
break
2 years ago
print('Unknown Choice')
2 years ago
engine_instance = TTSEngine(get_case_insensitive_key_value(TTSProviders, voice), reddit_obj)
return engine_instance.run()
3 years ago
2 years ago
def get_case_insensitive_key_value(
input_dict,
key,
2 years ago
) -> object:
return next(
(value for dict_key, value in input_dict.items() if dict_key.lower() == key.lower()),
None,
)