MCPcopy Create free account
hub / github.com/RobotTelevision/CrowAssistant / wintts

Function wintts

CrowAssistant.py:170–206  ·  view source on GitHub ↗
(text, model)

Source from the content-addressed store, hash-verified

168
169
170def 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
208def play_and_delete_wav():
209 global stopplayback

Callers 3

test_voiceFunction · 0.85
CrowAssistant.pyFile · 0.85

Calls 1

contains_wordFunction · 0.85

Tested by 1

test_voiceFunction · 0.68