fixes with attrs.attrib mostly

pull/963/head
Drugsosos 2 years ago
parent 6a2b448c73
commit 720511168c
No known key found for this signature in database
GPG Key ID: 8E35176FE617E28D

@ -3,6 +3,7 @@ import requests
from requests.adapters import HTTPAdapter, Retry
from attr import attrs, attrib
from attr.validators import instance_of
from TTS.common import BaseApiTTS, get_random_voice
@ -62,15 +63,15 @@ voices['non_eng'] = [
# more or less: en_us_rocket, en_us_ghostface
@attrs(auto_attribs=True)
@attrs
class TikTok(BaseApiTTS): # TikTok Text-to-Speech Wrapper
random_voice: bool = False
uri_base: str = attrib(
default='https://api16-normal-useast5.us.tiktokv.com/media/api/text/speech/invoke/',
kw_only=True,
random_voice: bool = attrib(
validator=instance_of(bool),
default=False
)
max_chars = 300
decode_base64 = True
uri_base: str = 'https://api16-normal-useast5.us.tiktokv.com/media/api/text/speech/invoke/'
max_chars: int = 300
decode_base64: bool = True
def make_request(
self,

@ -4,7 +4,8 @@ from botocore.exceptions import BotoCoreError, ClientError, ProfileNotFound
import sys
from utils import settings
from attr import attrs
from attr import attrs, attrib
from attr.validators import instance_of
from TTS.common import get_random_voice
@ -28,9 +29,12 @@ voices = [
]
@attrs(auto_attribs=True)
@attrs
class AWSPolly:
random_voice: bool = False
random_voice: bool = attrib(
validator=instance_of(bool),
default=False
)
max_chars: int = 0
def run(

@ -17,26 +17,21 @@ from TTS.TikTok import TikTok
from TTS.aws_polly import AWSPolly
@attrs(auto_attribs=True)
@attrs
class TTSEngine:
"""Calls the given TTS engine to reduce code duplication and allow multiple TTS engines.
Args:
tts_module : The TTS module. Your module should handle the TTS itself and saving to the given path under the run method.
reddit_object : The reddit object that contains the posts to read.
path (Optional) : The unix style path to save the mp3 files to. This must not have leading or trailing slashes.
max_length (Optional) : The maximum length of the mp3 files in total.
Notes:
tts_module must take the arguments text and filepath.
"""
tts_module: Union[GTTS, StreamlabsPolly, TikTok, AWSPolly]
reddit_object: dict
path: str = 'assets/temp/mp3'
__total_length: int = attrib(
default=0,
kw_only=True
)
tts_module: Union[GTTS, StreamlabsPolly, TikTok, AWSPolly] = attrib()
reddit_object: dict = attrib()
__path: str = 'assets/temp/mp3'
__total_length: int = 0
def __attrs_post_init__(self):
# Calls an instance of the tts_module class
@ -59,12 +54,12 @@ class TTSEngine:
Returns:
Indexes of comments to be used in the final video
"""
Path(self.path).mkdir(parents=True, exist_ok=True)
Path(self.__path).mkdir(parents=True, exist_ok=True)
# This file needs to be removed in case this post does not use post text
# so that it won't appear in the final video
try:
Path(f'{self.path}/posttext.mp3').unlink()
Path(f'{self.__path}/posttext.mp3').unlink()
except OSError:
pass
@ -109,10 +104,10 @@ class TTSEngine:
self.tts_module.run(
text=self.process_text(text),
filepath=f'{self.path}/{filename}.mp3'
filepath=f'{self.__path}/{filename}.mp3'
)
clip_length = audio_length(f'{self.path}/{filename}.mp3')
clip_length = audio_length(f'{self.__path}/{filename}.mp3')
clip_offset = self.time_between_pictures + self.time_before_tts * 2
if clip_length and self.__total_length + clip_length + clip_offset <= self.max_length:

@ -2,6 +2,7 @@ import requests
from requests.exceptions import JSONDecodeError
from utils import settings
from attr import attrs, attrib
from attr.validators import instance_of
from TTS.common import BaseApiTTS, get_random_voice
from utils.voice import check_ratelimit
@ -28,15 +29,14 @@ voices = [
# valid voices https://lazypy.ro/tts/
@attrs(auto_attribs=True)
@attrs
class StreamlabsPolly(BaseApiTTS):
random_voice: bool = False
url: str = attrib(
default='https://streamlabs.com/polly/speak',
kw_only=True,
random_voice: bool = attrib(
validator=instance_of(bool),
default=False
)
max_chars = 550
url: str = 'https://streamlabs.com/polly/speak',
max_chars: int = 550
def make_request(
self,

@ -9,7 +9,6 @@ from moviepy.editor import (
VideoFileClip,
AudioFileClip,
ImageClip,
concatenate_videoclips,
CompositeAudioClip,
CompositeVideoClip,
)
@ -35,7 +34,7 @@ def name_normalize(
name = re.sub(r'(\d+)\s?\/\s?(\d+)', r'\1 of \2', name)
name = re.sub(r'(\w+)\s?\/\s?(\w+)', r'\1 or \2', name)
name = re.sub(r'\/', '', name)
name[:30] # the hell this little guy does?
# name[:30] # the hell this little guy does? commented until explained
lang = settings.config['reddit']['thread']['post_lang']
if lang:
@ -44,9 +43,7 @@ def name_normalize(
print_substep('Translating filename...')
translated_name = ts.google(name, to_language=lang)
return translated_name
else:
return name
return name
def make_final_video(

@ -46,7 +46,7 @@ class ExceptionDecorator:
import logging
logger = logging.getLogger('webdriver_log')
logger.setLevel(logging.DEBUG)
logger.setLevel(logging.ERROR)
handler = logging.FileHandler('.webdriver.log', mode='a+', encoding='utf-8')
logger.addHandler(handler)

Loading…
Cancel
Save