fix: Fixed Mutagen error issue

style: made final_video.py cleaner
pull/803/head 2.2.2
Jason 2 years ago
parent a5973aff76
commit ce6a87aac2

@ -3,6 +3,9 @@ from pathlib import Path
from typing import Tuple
import re
from os import getenv
import sox
from mutagen import MutagenError
from mutagen.mp3 import MP3
import translators as ts
from rich.progress import track
@ -91,8 +94,10 @@ class TTSEngine:
def call_tts(self, filename: str, text: str):
self.tts_module.run(text=process_text(text), filepath=f"{self.path}/{filename}.mp3")
self.length += MP3(f"{self.path}/{filename}.mp3").info.length
try:
self.length += MP3(f"{self.path}/{filename}.mp3").info.length
except MutagenError:
self.length += sox.file_info.duration(f"{self.path}/{filename}.mp3")
def process_text(text: str):
lang = getenv("POSTLANG", "")

@ -44,9 +44,7 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict[str]):
)
# Gather all audio clips
audio_clips = []
for i in range(0, number_of_clips):
audio_clips.append(AudioFileClip(f"assets/temp/mp3/{i}.mp3"))
audio_clips = [AudioFileClip(f"assets/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])

Loading…
Cancel
Save