From ada9b692993df9210622312813b48c2d2500ec2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammed=20Mustafa=20Ak=C5=9Fam?= Date: Mon, 4 Jul 2022 11:06:26 +0300 Subject: [PATCH 1/4] Fixing legacy VOICE variables Fixing legacy VOICE variables that caused lot of issues if TTSCHOICE set to AWS_VOICE or STREAMLABS_VOICE --- TTS/aws_polly.py | 4 ++-- TTS/streamlabs_polly.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/TTS/aws_polly.py b/TTS/aws_polly.py index 703aa6a..6cbe4c5 100644 --- a/TTS/aws_polly.py +++ b/TTS/aws_polly.py @@ -35,9 +35,9 @@ class AWSPolly: if random_voice: voice = self.randomvoice() else: - if not os.getenv("VOICE"): + if not os.getenv("AWS_VOICE"): return ValueError( - f"Please set the environment variable VOICE to a valid voice. options are: {voices}" + f"Please set the environment variable AWS_VOICE to a valid voice. options are: {voices}" ) voice = str(os.getenv("AWS_VOICE")).capitalize() try: diff --git a/TTS/streamlabs_polly.py b/TTS/streamlabs_polly.py index 41fe269..066fa53 100644 --- a/TTS/streamlabs_polly.py +++ b/TTS/streamlabs_polly.py @@ -35,9 +35,9 @@ class StreamlabsPolly: if random_voice: voice = self.randomvoice() else: - if not os.getenv("VOICE"): + if not os.getenv("STREAMLABS_VOICE"): return ValueError( - f"Please set the environment variable VOICE to a valid voice. options are: {voices}" + f"Please set the environment variable STREAMLABS_VOICE to a valid voice. options are: {voices}" ) voice = str(os.getenv("STREAMLABS_VOICE")).capitalize() body = {"voice": voice, "text": text, "service": "polly"} From a335e67c8cec393447067db79e5b88def6078a6a Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Mon, 4 Jul 2022 19:10:22 +0100 Subject: [PATCH 2/4] fix: stop broken typechecking --- TTS/engine_wrapper.py | 2 +- video_creation/background.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/TTS/engine_wrapper.py b/TTS/engine_wrapper.py index 77f6eab..fd2d36b 100644 --- a/TTS/engine_wrapper.py +++ b/TTS/engine_wrapper.py @@ -72,7 +72,7 @@ class TTSEngine: print_substep("Saved Text to MP3 files successfully.", style="bold green") return self.length, idx - def split_post(self, text: str, idx: int) -> str: + def split_post(self, text: str, idx: int): split_files = [] split_text = [ x.group().strip() diff --git a/video_creation/background.py b/video_creation/background.py index 7bf6ae2..2654499 100644 --- a/video_creation/background.py +++ b/video_creation/background.py @@ -2,6 +2,7 @@ import random from os import listdir, environ from pathlib import Path from random import randrange +from typing import Tuple from moviepy.editor import VideoFileClip from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip @@ -10,7 +11,7 @@ from pytube import YouTube from utils.console import print_step, print_substep -def get_start_and_end_times(video_length: int, length_of_clip: int) -> tuple[int, int]: +def get_start_and_end_times(video_length: int, length_of_clip: int) -> Tuple[int, int]: """Generates a random interval of time to be used as the background of the video. Args: From 8365121865d995929df86576eaa75c6d8edd329f Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Mon, 4 Jul 2022 19:59:33 +0100 Subject: [PATCH 3/4] fix: close clip once finished --- TTS/engine_wrapper.py | 1 + 1 file changed, 1 insertion(+) diff --git a/TTS/engine_wrapper.py b/TTS/engine_wrapper.py index fd2d36b..017cf79 100644 --- a/TTS/engine_wrapper.py +++ b/TTS/engine_wrapper.py @@ -100,6 +100,7 @@ class TTSEngine: # self.length += sox.file_info.duration(f"{self.path}/{filename}.mp3") clip = AudioFileClip(f"{self.path}/{filename}.mp3") self.length += clip.duration + clip.close() def process_text(text: str): lang = getenv("POSTLANG", "") From c4da2fa55a4d30e28838a7aa58e0f08f0dc8ea38 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Mon, 4 Jul 2022 20:33:59 +0100 Subject: [PATCH 4/4] fix: close ALL clips when finished --- TTS/engine_wrapper.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/TTS/engine_wrapper.py b/TTS/engine_wrapper.py index 017cf79..13ff850 100644 --- a/TTS/engine_wrapper.py +++ b/TTS/engine_wrapper.py @@ -88,9 +88,15 @@ class TTSEngine: f"{self.path}/{idx}.mp3", fps=44100, verbose=False, logger=None ) - for i in range(0, idy + 1): + for i in split_files: + name = i.filename + i.close() + Path(name).unlink() + + # for i in range(0, idy + 1): # print(f"Cleaning up {self.path}/{idx}-{i}.part.mp3") - Path(f"{self.path}/{idx}-{i}.part.mp3").unlink() + + # Path(f"{self.path}/{idx}-{i}.part.mp3").unlink() def call_tts(self, filename: str, text: str): self.tts_module.run(text=process_text(text), filepath=f"{self.path}/{filename}.mp3")