(self, text: str, idx)
| 103 | return self.length, idx |
| 104 | |
| 105 | def split_post(self, text: str, idx): |
| 106 | split_files = [] |
| 107 | split_text = [ |
| 108 | x.group().strip() |
| 109 | for x in re.finditer( |
| 110 | r" *(((.|\n){0," + str(self.tts_module.max_chars) + "})(\.|.$))", text |
| 111 | ) |
| 112 | ] |
| 113 | self.create_silence_mp3() |
| 114 | |
| 115 | for idy, text_cut in enumerate(split_text): |
| 116 | newtext = process_text(text_cut) |
| 117 | # print(f"{idx}-{idy}: {newtext}\n") |
| 118 | |
| 119 | if not newtext or newtext.isspace(): |
| 120 | print("newtext was blank because sanitized split text resulted in none") |
| 121 | continue |
| 122 | else: |
| 123 | self.call_tts(f"{idx}-{idy}.part", newtext) |
| 124 | with open(f"{self.path}/list.txt", "w") as f: |
| 125 | for idz in range(0, len(split_text)): |
| 126 | f.write("file " + f"'{idx}-{idz}.part.mp3'" + "\n") |
| 127 | split_files.append(str(f"{self.path}/{idx}-{idy}.part.mp3")) |
| 128 | f.write("file " + f"'silence.mp3'" + "\n") |
| 129 | |
| 130 | os.system( |
| 131 | "ffmpeg -f concat -y -hide_banner -loglevel panic -safe 0 " |
| 132 | + "-i " |
| 133 | + f"{self.path}/list.txt " |
| 134 | + "-c copy " |
| 135 | + f"{self.path}/{idx}.mp3" |
| 136 | ) |
| 137 | try: |
| 138 | for i in range(0, len(split_files)): |
| 139 | os.unlink(split_files[i]) |
| 140 | except FileNotFoundError as e: |
| 141 | print("File not found: " + e.filename) |
| 142 | except OSError: |
| 143 | print("OSError") |
| 144 | |
| 145 | def call_tts(self, filename: str, text: str): |
| 146 | if settings.config["settings"]["tts"]["voice_choice"] == "googletranslate": |
no test coverage detected