From dc5d95668d8125f44c55812dc12cf71804775592 Mon Sep 17 00:00:00 2001 From: anthony lloyd Date: Mon, 11 Jul 2022 16:43:15 +1000 Subject: [PATCH] use ffmpeg for final video audio concat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit since I have my own voice.py profanity filter i cant push changes i make to voice. py. however. i have found these bugs change these lines wouldnt regex the em dash symbol replacing url with blank would make files x-y.mp3 that only contain url bug out, so instead just make the tts read URL instead of nothing regex_expr = r"\s['|’]|['|’]\s|[\^_~@!&;#:\-%— “”‘\"%\*/{}\[\]\(\)\\|<>=+]" result = re.sub(regex_urls, "url", text) --- TTS/engine_wrapper.py | 2 +- video_creation/final_video.py | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/TTS/engine_wrapper.py b/TTS/engine_wrapper.py index f50e29f..f7cd12a 100644 --- a/TTS/engine_wrapper.py +++ b/TTS/engine_wrapper.py @@ -96,7 +96,7 @@ class TTSEngine: idy = None for idy, text_cut in enumerate(split_text): - # print(f"{idx}-{idy}: {text_cut}\n") + print(f"{idx}-{idy}: {text_cut}\n") self.call_tts(f"{idx}-{idy}.part", text_cut) with open(f"{self.path}/list.txt", 'w') as f: diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 7853014..5054576 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -72,10 +72,26 @@ def make_final_video( ) # Gather all audio clips + audio_clips = [AudioFileClip(f"assets/temp/mp3/{i}.mp3") for i in range(number_of_clips)] audio_clips.insert(0, AudioFileClip("assets/temp/mp3/title.mp3")) audio_concat = concatenate_audioclips(audio_clips) audio_composite = CompositeAudioClip([audio_concat]) + audio_composite.write_audiofile(f"assets/temp/mp3/moviepy.mp3", fps=44100, verbose=False, logger=None) + + with open(f"assets/temp/mp3/list2.txt", 'w') as f: + f.write("file " + f"'title.mp3'" + "\n") + for newx in range(0, number_of_clips): + f.write("file " + f"'{newx}.mp3'" + "\n") + + os.system("ffmpeg -f concat -y -hide_banner -loglevel panic -safe 0 " + + "-i " + f"assets/temp/mp3/list2.txt " + + "-c copy " + f"assets/temp/mp3/concat_audio.mp4") + + all_audio = AudioFileClip(f"assets/temp/mp3/concat_audio.mp4") + all_audio = CompositeAudioClip([audio_composite]) + + console.log(f"[bold green] Video Will Be: {length} Seconds Long") # add title to video @@ -110,7 +126,9 @@ def make_final_video( # else: story mode stuff img_clip_pos = background_config[3] image_concat = concatenate_videoclips(image_clips).set_position(img_clip_pos) - image_concat.audio = audio_composite + #image_concat.audio = audio_composite + image_concat.audio = all_audio + final = CompositeVideoClip([background_clip, image_concat]) title = re.sub(r"[^\w\s-]", "", reddit_obj["thread_title"]) idx = re.sub(r"[^\w\s-]", "", reddit_obj["thread_id"]) @@ -132,6 +150,12 @@ def make_final_video( verbose=False, threads=multiprocessing.cpu_count(), ) + + + + + + if settings.config["settings"]["background_audio"]: print("[bold green] Merging background audio with video") if not exists(f"assets/backgrounds/background.mp3"):