Skip to content

Commit

Permalink
fix: Fixed Mutagen error issue
Browse files Browse the repository at this point in the history
style: made final_video.py cleaner
  • Loading branch information
JasonLovesDoggo committed Jul 2, 2022
1 parent a5973af commit ce6a87a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 7 additions & 2 deletions TTS/engine_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
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
Expand Down Expand Up @@ -91,8 +94,10 @@ def split_post(self, text: str, idx: int) -> str:

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", "")
Expand Down
4 changes: 1 addition & 3 deletions video_creation/final_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit ce6a87a

Please sign in to comment.