|
|
@ -81,74 +81,77 @@ class TTSEngine:
|
|
|
|
return self.length, idx
|
|
|
|
return self.length, idx
|
|
|
|
|
|
|
|
|
|
|
|
def split_post(self, text: str, idx: int):
|
|
|
|
def split_post(self, text: str, idx: int):
|
|
|
|
|
|
|
|
split_files = []
|
|
|
|
split_text = [
|
|
|
|
split_text = [
|
|
|
|
x.group().strip()
|
|
|
|
x.group().strip()
|
|
|
|
for x in re.finditer(rf"*(((.| \n){self.tts_module.max_chars})(\.|.$))", text)
|
|
|
|
for x in re.finditer(
|
|
|
|
|
|
|
|
r" *(((.|\n){0," + str(self.tts_module.max_chars) + "})(\.|.$))", text
|
|
|
|
|
|
|
|
)
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
silence_duration = settings.config["settings"]["tts"]["silence_duration"]
|
|
|
|
silence_duration = settings.config["settings"]["tts"]["silence_duration"]
|
|
|
|
except ValueError:
|
|
|
|
except ValueError:
|
|
|
|
silence_duration = 0.3
|
|
|
|
silence_duration = 0.3
|
|
|
|
|
|
|
|
|
|
|
|
silence_long = AudioClip(make_frame=lambda t: np.sin(440 * 2 * np.pi * t), duration=silence_duration, fps=44100)
|
|
|
|
silence_long = AudioClip(make_frame=lambda t: np.sin(440 * 2 * np.pi * t), duration=silence_duration, fps=44100)
|
|
|
|
silence_long_new = volumex(silence_long, 0)
|
|
|
|
silence_long_new = volumex(silence_long, 0)
|
|
|
|
silence_long_new.write_audiofile(f"{self.path}/long_silence.mp3", fps=44100, verbose=False, logger=None)
|
|
|
|
silence_long_new.write_audiofile(f"{self.path}/long_silence.mp3", fps=44100, verbose=False, logger=None)
|
|
|
|
|
|
|
|
|
|
|
|
idy = None
|
|
|
|
idy = None
|
|
|
|
for idy, text_cut in enumerate(split_text):
|
|
|
|
for idy, text_cut in enumerate(split_text):
|
|
|
|
print(f"{idx}-{idy}: {text_cut}\n")
|
|
|
|
#print(f"{idx}-{idy}: {text_cut}\n")
|
|
|
|
newtext = process_text(text_cut)
|
|
|
|
newtext = process_text(text_cut)
|
|
|
|
#print(newtext)
|
|
|
|
|
|
|
|
if not newtext or newtext.isspace():
|
|
|
|
if not newtext or newtext.isspace():
|
|
|
|
print("fuck you")
|
|
|
|
print("somehow newtext was blank")
|
|
|
|
break
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
self.call_tts(f"{idx}-{idy}.part", newtext)
|
|
|
|
self.call_tts(f"{idx}-{idy}.part", newtext)
|
|
|
|
with open(f"{self.path}/list.txt", 'w') as f:
|
|
|
|
with open(f"{self.path}/list.txt", 'w') as f:
|
|
|
|
for newy in range(0, len(split_text)):
|
|
|
|
for newy in range(0, len(split_text)):
|
|
|
|
f.write("file " + f"'{idx}-{newy}.part.mp3'" + "\n")
|
|
|
|
f.write("file " + f"'{idx}-{newy}.part.mp3'" + "\n")
|
|
|
|
|
|
|
|
split_files.append(str(f"{self.path}/{idx}-{idy}.part.mp3"))
|
|
|
|
f.write("file " + f"'long_silence.mp3'" + "\n")
|
|
|
|
f.write("file " + f"'long_silence.mp3'" + "\n")
|
|
|
|
|
|
|
|
|
|
|
|
os.system("ffmpeg -f concat -y -hide_banner -loglevel panic -safe 0 " +
|
|
|
|
os.system("ffmpeg -f concat -y -hide_banner -loglevel panic -safe 0 " +
|
|
|
|
"-i " + f"{self.path}/list.txt " +
|
|
|
|
"-i " + f"{self.path}/list.txt " +
|
|
|
|
"-c copy " + f"{self.path}/{idx}.mp3")
|
|
|
|
"-c copy " + f"{self.path}/{idx}.mp3")
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
for i in range(0, idy + 1):
|
|
|
|
name = rf"{self.path}/{idx}-{newy}.part.mp3"
|
|
|
|
# print(f"Cleaning up {self.path}/{idx}-{i}.part.mp3")
|
|
|
|
print(name)
|
|
|
|
Path(f"{self.path}/{idx}-{i}.part.mp3").unlink()
|
|
|
|
os.unlink(name)
|
|
|
|
except FileNotFoundError:
|
|
|
|
except FileNotFoundError:
|
|
|
|
print("file not found error")
|
|
|
|
print("file not found error")
|
|
|
|
|
|
|
|
except OSError:
|
|
|
|
|
|
|
|
print("OSError")
|
|
|
|
|
|
|
|
|
|
|
|
def call_tts(self, filename: str, text: str):
|
|
|
|
def call_tts(self, filename: str, text: str):
|
|
|
|
|
|
|
|
|
|
|
|
if filename == "title":
|
|
|
|
if filename == "title":
|
|
|
|
self.tts_module.run(text, filepath=f"{self.path}/title_nosilence.mp3")
|
|
|
|
try:
|
|
|
|
|
|
|
|
self.tts_module.run(text, filepath=f"{self.path}/title_nosilence.mp3")
|
|
|
|
|
|
|
|
silence_long = AudioClip(make_frame=lambda t: np.sin(440 * 2 * np.pi * t),
|
|
|
|
silence_long = AudioClip(make_frame=lambda t: np.sin(440 * 2 * np.pi * t), duration=0.3,
|
|
|
|
duration=0.3,fps=44100)
|
|
|
|
fps=44100)
|
|
|
|
silence_long_new = volumex(silence_long, 0)
|
|
|
|
silence_long_new = volumex(silence_long, 0)
|
|
|
|
silence_long_new.write_audiofile(f"{self.path}/title_silence.mp3", fps=44100, verbose=False, logger=None)
|
|
|
|
silence_long_new.write_audiofile(f"{self.path}/title_silence.mp3", fps=44100, verbose=False, logger=None)
|
|
|
|
|
|
|
|
|
|
|
|
with open(f"{self.path}/title.txt", 'w') as f:
|
|
|
|
with open(f"{self.path}/title.txt", 'w') as f:
|
|
|
|
f.write("file " + f"'title_nosilence.mp3'"+"\n")
|
|
|
|
f.write("file " + f"'title_nosilence.mp3'"+"\n")
|
|
|
|
f.write("file " + f"'title_silence.mp3'"+"\n")
|
|
|
|
f.write("file " + f"'title_silence.mp3'"+"\n")
|
|
|
|
os.system("ffmpeg -f concat -y -hide_banner -loglevel panic -safe 0 " +
|
|
|
|
|
|
|
|
"-i " + f"{self.path}/title.txt " +
|
|
|
|
os.system("ffmpeg -f concat -y -hide_banner -loglevel panic -safe 0 " +
|
|
|
|
"-c copy " + f"{self.path}/title.mp3")
|
|
|
|
"-i " + f"{self.path}/title.txt " +
|
|
|
|
clip = AudioFileClip(f"{self.path}/title.mp3")
|
|
|
|
"-c copy " + f"{self.path}/title.mp3")
|
|
|
|
self.length += clip.duration
|
|
|
|
|
|
|
|
clip.close()
|
|
|
|
|
|
|
|
except :
|
|
|
|
clip = AudioFileClip(f"{self.path}/title.mp3")
|
|
|
|
self.length = 0
|
|
|
|
self.length += clip.duration
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
self.tts_module.run(text=process_text(text), filepath=f"{self.path}/{filename}.mp3")
|
|
|
|
try:
|
|
|
|
clip = AudioFileClip(f"{self.path}/{filename}.mp3")
|
|
|
|
self.tts_module.run(text=process_text(text), filepath=f"{self.path}/{filename}.mp3")
|
|
|
|
self.length += clip.duration
|
|
|
|
clip = AudioFileClip(f"{self.path}/{filename}.mp3")
|
|
|
|
clip.close()
|
|
|
|
self.length += clip.duration
|
|
|
|
|
|
|
|
clip.close()
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
self.length = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def process_text(text: str):
|
|
|
|
def process_text(text: str):
|
|
|
|