INNER CODE UNIT · Python
bot_text_to_speech_queue_func
shakedzy/companion · companion.py:482
def bot_text_to_speech_queue_func():
"""
This function is meant to run on a parallel thread.
It is responsible to send texts to the TTS service, and then place the filename in a different queue,
in order to be played
"""
global config, memory, app_cache
while not app_cache.stop_threads_event.is_set():
try:
item = app_cache.text2speech_queue.get(timeout=1) # Wait for 1 second to get an item
idx = item["message_index"]
filename = utils.bot_text_to_speech(text=item['text'], message_index=idx, counter=item['counter'])
if item.get('skip_cache', False):
memory.update(idx, recording=[filename])
else:
app_cache.bot_recordings.append(filename)
memory.update(idx, recording=app_cache.bot_recordings)
put_in_audio_queue(filename)