From a8fef580159f47f855d449d9df3ca61dd25f8b4f Mon Sep 17 00:00:00 2001 From: MrSco Date: Thu, 1 Aug 2024 10:55:18 -0400 Subject: [PATCH] refactor: Update file paths for chatlogs and uploads directories fix: emoji speak ignoring --- main.py | 4 ++-- tts_service.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 8f17d2c..b1d647b 100644 --- a/main.py +++ b/main.py @@ -77,7 +77,7 @@ def is_running_on_raspberry_pi(): assistant_name = assistant["name"] assistant_acronym = assistant["acronym"] today = str(date.today()) -chatlog_filename = os.path.join("chatlogs", f"{config['assistant']}_chatlog-{today}.txt") +chatlog_filename = os.path.join(script_dir, "chatlogs", f"{config['assistant']}_chatlog-{today}.txt") if not os.path.exists("chatlogs"): os.makedirs("chatlogs") @@ -422,7 +422,7 @@ def handle_file_chunk(data): print(f"Received all chunks for file {file_id}.") if not use_imgur: file_data = b"".join(file_chunks[file_id]) - upload_path = config['upload_folder'] + upload_path = os.path.join(script_dir, config['upload_folder']) if not os.path.exists(upload_path): os.makedirs(upload_path) diff --git a/tts_service.py b/tts_service.py index 3e76752..81833df 100644 --- a/tts_service.py +++ b/tts_service.py @@ -1,3 +1,4 @@ +import re import time from elevenlabs import VoiceSettings from elevenlabs import stream @@ -23,11 +24,15 @@ def __init__(self, config): self.start_time = None self.end_time = None + def remove_non_ascii(self, text): + return re.sub(r'[^\x00-\x7F]+', '', text) + def speak(self, text): + textToSpeak = text self.start_time = time.time() try: # strip out emojis so we don't try to speak them - textToSpeak = text.encode('ascii', 'ignore').decode('ascii') + textToSpeak = self.remove_non_ascii(text) if not self.use_elevenlabs: if self.use_gtts: self.speak_with_gtts(textToSpeak)