From 63d04a302e59f1b99c9387d55e7c07941e1bd2c6 Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 8 Jun 2022 18:13:35 -0400 Subject: [PATCH] fix: i think --- video_creation/TTSwrapper.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/video_creation/TTSwrapper.py b/video_creation/TTSwrapper.py index 62201cb..a17eb8f 100644 --- a/video_creation/TTSwrapper.py +++ b/video_creation/TTSwrapper.py @@ -5,6 +5,7 @@ import re import sox import requests +from moviepy.audio.AudioClip import concatenate_audioclips, CompositeAudioClip from requests.adapters import HTTPAdapter, Retry # from profanity_filter import ProfanityFilter @@ -115,12 +116,16 @@ class TTTTSWrapper: # TikTok Text-to-Speech Wrapper audio_clips.append(filename.replace(".mp3", f"-{chunkId}.mp3")) chunkId = chunkId + 1 - - if len(audio_clips) > 1: - cbn.convert(samplerate=44100, n_channels=2) - cbn.build(audio_clips, filename, "concatenate") - else: - os.rename(audio_clips[0], filename) + try: + if len(audio_clips) > 1: + cbn.convert(samplerate=44100, n_channels=2) + cbn.build(audio_clips, filename, "concatenate") + else: + os.rename(audio_clips[0], filename) + except sox.core.SoxError: + audio_concat = concatenate_audioclips(audio_clips) + audio_composite = CompositeAudioClip([audio_concat]) + audio_composite.write_audiofile(filename, 44100, 2, 2000, None) @staticmethod def randomvoice():