Changed to tts chunk combiner to sox
This helps performance and improves audio quality as movie.py adds a lot of audio glitches also there where a few small mistakes in the old version that I fixed and seem to work.
This commit is contained in:
1 parent
ddd16d25c7
commit
3be00d00d7
3 files changed
+14
-8
No files matched your search
+1
-1
@@ -6,4 +6,4 @@ playwright~=1.22.0
|
||||
python-dotenv==0.20.0
|
||||
typed-ast~=1.5.4
|
||||
requests~=2.27.1
|
||||
yt-dlp
|
||||
typing~=3.10.0.0
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
from typings import List
|
||||
from typing import List
|
||||
import json
|
||||
def get_hottest_undone(submissions: List):
|
||||
"""
|
||||
recursively checks if the top submission in the list was already done.
|
||||
|
||||
@@ -3,8 +3,8 @@ import os
|
||||
import random
|
||||
import re
|
||||
|
||||
import sox
|
||||
import requests
|
||||
from moviepy.editor import AudioFileClip, concatenate_audioclips, CompositeAudioClip
|
||||
from requests.adapters import HTTPAdapter, Retry
|
||||
|
||||
# from profanity_filter import ProfanityFilter
|
||||
@@ -88,6 +88,7 @@ class TTTTSWrapper: # TikTok Text-to-Speech Wrapper
|
||||
]
|
||||
|
||||
audio_clips = []
|
||||
cbn = sox.Combiner()
|
||||
|
||||
chunkId = 0
|
||||
for chunk in chunks:
|
||||
@@ -108,16 +109,20 @@ class TTTTSWrapper: # TikTok Text-to-Speech Wrapper
|
||||
vstr = [r.json()["data"]["v_str"]][0]
|
||||
b64d = base64.b64decode(vstr)
|
||||
|
||||
with open(f"{filename}-{chunkId}", "wb") as out:
|
||||
with open(filename.replace(".mp3", f"-{chunkId}.mp3"), "wb") as out:
|
||||
out.write(b64d)
|
||||
|
||||
audio_clips.append(AudioFileClip(f"{filename}-{chunkId}"))
|
||||
audio_clips.append(filename.replace(".mp3", f"-{chunkId}.mp3"))
|
||||
|
||||
chunkId = chunkId + 1
|
||||
|
||||
audio_concat = concatenate_audioclips(audio_clips)
|
||||
audio_composite = CompositeAudioClip([audio_concat])
|
||||
audio_composite.write_audiofile(filename, 44100, 2, 2000, None)
|
||||
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)
|
||||
|
||||
@staticmethod
|
||||
def randomvoice():
|
||||
|
||||
Reference in new issue
Block a user