chore: reformatted

docs: added better comment documentation
pull/418/head
Jason 2 years ago
parent a3dddd1b4b
commit 7728c472e9

@ -3,8 +3,8 @@ import os
import random import random
import re import re
import sox
import requests import requests
import sox
from moviepy.audio.AudioClip import concatenate_audioclips, CompositeAudioClip from moviepy.audio.AudioClip import concatenate_audioclips, CompositeAudioClip
from moviepy.audio.io.AudioFileClip import AudioFileClip from moviepy.audio.io.AudioFileClip import AudioFileClip
from requests.adapters import HTTPAdapter, Retry from requests.adapters import HTTPAdapter, Retry
@ -69,11 +69,11 @@ class TTTTSWrapper: # TikTok Text-to-Speech Wrapper
self.URI_BASE = "https://api16-normal-useast5.us.tiktokv.com/media/api/text/speech/invoke/?text_speaker=" self.URI_BASE = "https://api16-normal-useast5.us.tiktokv.com/media/api/text/speech/invoke/?text_speaker="
def tts( def tts(
self, self,
req_text: str = "TikTok Text To Speech", req_text: str = "TikTok Text To Speech",
filename: str = "title.mp3", filename: str = "title.mp3",
random_speaker: bool = False, random_speaker: bool = False,
censer=False, censer=False,
): ):
req_text = req_text.replace("+", "plus").replace(" ", "+").replace("&", "and") req_text = req_text.replace("+", "plus").replace(" ", "+").replace("&", "and")
if censer: if censer:
@ -91,7 +91,7 @@ class TTTTSWrapper: # TikTok Text-to-Speech Wrapper
audio_clips = [] audio_clips = []
cbn = sox.Combiner() cbn = sox.Combiner()
cbn.set_input_format(file_type=['mp3']) cbn.set_input_format(file_type=["mp3"])
chunkId = 0 chunkId = 0
for chunk in chunks: for chunk in chunks:
@ -124,11 +124,13 @@ class TTTTSWrapper: # TikTok Text-to-Speech Wrapper
cbn.build(audio_clips, filename, "concatenate") cbn.build(audio_clips, filename, "concatenate")
else: else:
os.rename(audio_clips[0], filename) os.rename(audio_clips[0], filename)
except sox.core.SoxError:
except sox.core.SoxError: # https://github.com/JasonLovesDoggo/RedditVideoMakerBot/issues/67#issuecomment-1150466339
for clip in audio_clips: for clip in audio_clips:
i = audio_clips.index(clip) # get the index of the clip i = audio_clips.index(clip) # get the index of the clip
audio_clips = audio_clips[:i] + [AudioFileClip(clip)] + audio_clips[ audio_clips = (
i + 1:] # replace the clip with an AudioFileClip audio_clips[:i] + [AudioFileClip(clip)] + audio_clips[i + 1 :]
) # replace the clip with an AudioFileClip
audio_concat = concatenate_audioclips(audio_clips) audio_concat = concatenate_audioclips(audio_clips)
audio_composite = CompositeAudioClip([audio_concat]) audio_composite = CompositeAudioClip([audio_concat])
audio_composite.write_audiofile(filename, 44100, 2, 2000, None) audio_composite.write_audiofile(filename, 44100, 2, 2000, None)

Loading…
Cancel
Save