Skip to content

Commit ce6a87a

Browse files
fix: Fixed Mutagen error issue
style: made final_video.py cleaner
1 parent a5973af commit ce6a87a

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

TTS/engine_wrapper.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
from typing import Tuple
44
import re
55
from os import getenv
6+
7+
import sox
8+
from mutagen import MutagenError
69
from mutagen.mp3 import MP3
710
import translators as ts
811
from rich.progress import track
@@ -91,8 +94,10 @@ def split_post(self, text: str, idx: int) -> str:
9194

9295
def call_tts(self, filename: str, text: str):
9396
self.tts_module.run(text=process_text(text), filepath=f"{self.path}/{filename}.mp3")
94-
self.length += MP3(f"{self.path}/{filename}.mp3").info.length
95-
97+
try:
98+
self.length += MP3(f"{self.path}/{filename}.mp3").info.length
99+
except MutagenError:
100+
self.length += sox.file_info.duration(f"{self.path}/{filename}.mp3")
96101

97102
def process_text(text: str):
98103
lang = getenv("POSTLANG", "")

video_creation/final_video.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict[str]):
4444
)
4545

4646
# Gather all audio clips
47-
audio_clips = []
48-
for i in range(0, number_of_clips):
49-
audio_clips.append(AudioFileClip(f"assets/temp/mp3/{i}.mp3"))
47+
audio_clips = [AudioFileClip(f"assets/mp3/{i}.mp3") for i in range(number_of_clips)]
5048
audio_clips.insert(0, AudioFileClip("assets/temp/mp3/title.mp3"))
5149
audio_concat = concatenate_audioclips(audio_clips)
5250
audio_composite = CompositeAudioClip([audio_concat])

0 commit comments

Comments
 (0)