| 168 | |
| 169 | |
| 170 | def wintts(text, model): |
| 171 | global config |
| 172 | global saidname |
| 173 | global stopplayback |
| 174 | stopplayback=False |
| 175 | saidname = contains_word(text, config.config['name']) |
| 176 | |
| 177 | # Clean up the text |
| 178 | text = re.sub(r"\'", "", text) |
| 179 | text = re.sub(r"\*", "", text) |
| 180 | text = text.strip() |
| 181 | remove_chars = "&<>[]|^%:\"" |
| 182 | text = "".join(char for char in text if char not in remove_chars) |
| 183 | |
| 184 | # Split the text into sentences or lines |
| 185 | sentences = re.split(r'(?<=[.!?])\s+|\n', text) |
| 186 | |
| 187 | # Process each non-empty sentence |
| 188 | for sentence in sentences: |
| 189 | sentence = sentence.strip() |
| 190 | if not sentence: |
| 191 | continue |
| 192 | |
| 193 | print(sentence) |
| 194 | |
| 195 | # Generate a random filename |
| 196 | random_filename = ''.join(random.choices(string.ascii_letters + string.digits, k=10)) + ".wav" |
| 197 | random_filename = os.path.join("wav", random_filename) |
| 198 | |
| 199 | # Use shell escaping for the sentence to handle special characters |
| 200 | safe_sentence = shlex.quote(sentence) |
| 201 | |
| 202 | command = f"echo {safe_sentence} | piper -m {model} -f {random_filename}" |
| 203 | os.system(command) |
| 204 | |
| 205 | # Add the file to the queue |
| 206 | tts_queue.put(random_filename) |
| 207 | |
| 208 | def play_and_delete_wav(): |
| 209 | global stopplayback |