From aeafb53da3368a2b1975ed93fc7376074b9b45c0 Mon Sep 17 00:00:00 2001 From: Jason Date: Sun, 10 Jul 2022 11:44:40 -0400 Subject: [PATCH] background audio implementation p2. removed debug calls and testing rn style: removed useless comment imports --- TTS/streamlabs_polly.py | 2 -- main.py | 1 - video_creation/final_video.py | 27 +++++++++++++++++++-------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/TTS/streamlabs_polly.py b/TTS/streamlabs_polly.py index a5fda6a..bcfa175 100644 --- a/TTS/streamlabs_polly.py +++ b/TTS/streamlabs_polly.py @@ -48,8 +48,6 @@ class StreamlabsPolly: else: try: - print(body) - print(response.json()) voice_data = requests.get(response.json()["speak_url"]) with open(filepath, "wb") as f: f.write(voice_data.content) diff --git a/main.py b/main.py index 63e4e84..41ae8e1 100755 --- a/main.py +++ b/main.py @@ -7,7 +7,6 @@ from utils.cleanup import cleanup from utils.console import print_markdown, print_step from utils import settings -# from utils.checker import envUpdate from video_creation.background import ( download_background, chop_background_video, diff --git a/video_creation/final_video.py b/video_creation/final_video.py index bccbd0a..2e774c4 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -4,11 +4,15 @@ import os import re from os.path import exists from typing import Tuple, Any -import translators as ts - -from moviepy.editor import (VideoFileClip, AudioFileClip, ImageClip, concatenate_videoclips, concatenate_audioclips, - CompositeAudioClip, CompositeVideoClip, ) -from moviepy.video.io.ffmpeg_tools import ffmpeg_merge_video_audio, ffmpeg_extract_subclip +from moviepy import * +from moviepy.audio.AudioClip import concatenate_audioclips, CompositeAudioClip +from moviepy.audio.fx.audio_normalize import audio_normalize +from moviepy.audio.io.AudioFileClip import AudioFileClip +from moviepy.video.VideoClip import ImageClip +from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip +from moviepy.video.compositing.concatenate import concatenate_videoclips +from moviepy.video.io.VideoFileClip import VideoFileClip +from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip from rich.console import Console import moviepy.editor as mpe @@ -18,7 +22,10 @@ from utils.videos import save_data from utils import settings console = Console() -VOLUME_MULTIPLIER = settings.config["settings"]['background']["background_audio_volume"] +try: + VOLUME_MULTIPLIER = settings.config["settings"]['background']["background_audio_volume"] +except (TypeError, KeyError): + VOLUME_MULTIPLIER = 1 W, H = 1080, 1920 @@ -32,6 +39,7 @@ def name_normalize(name: str) -> str: lang = settings.config["reddit"]["thread"]["post_lang"] if lang: + import translators as ts print_substep("Translating filename...") translated_name = ts.google(name, to_language=lang) return translated_name @@ -110,8 +118,11 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict, backgr print('Merging background audio with video') my_clip = mpe.VideoFileClip('assets/temp/temp.mp4') audio_background = AudioFileClip("assets/backgrounds/background.mp3") - lowered_audio = audio_background.multiply_volume( - VOLUME_MULTIPLIER) # lower volume by background_audio_volume, use with fx + lowered_audio = audio_background.fl(lambda gf, t: VOLUME_MULTIPLIER * gf(t), + keep_duration=True) # to testr + #lowered_audio = audio_normalize(audio_background) + # lowered_audio = audio_background.multiply_volume( # todo get this to work + # VOLUME_MULTIPLIER) # lower volume by background_audio_volume, use with fx lowered_audio = lowered_audio.subclip(0, my_clip.duration) # trim the audio to the length of the video lowered_audio.set_duration(my_clip.duration) # set the duration of the audio to the length of the video final_audio = mpe.CompositeAudioClip([my_clip.audio, lowered_audio])