It didn't occur to me for some reason that reviewing messages would also add those messages to history lol. Hopefully fixed now.
This commit is contained in:
51
speech.py
51
speech.py
@@ -61,13 +61,14 @@ class Speech:
|
||||
# No speech providers found
|
||||
print("No speech providers found.")
|
||||
|
||||
def speak(self, text, interrupt=True, priority="normal"):
|
||||
def speak(self, text, interrupt=True, priority="normal", add_to_history=True):
|
||||
"""Speak text using the configured speech provider and display on screen.
|
||||
|
||||
Args:
|
||||
text (str): Text to speak and display
|
||||
interrupt (bool): Whether to interrupt current speech (default: True)
|
||||
priority (str): Speech priority - "important", "normal", or "notification"
|
||||
add_to_history (bool): Whether to add this message to speech history (default: True)
|
||||
"""
|
||||
if not self.provider:
|
||||
return
|
||||
@@ -84,12 +85,13 @@ class Speech:
|
||||
self.lastSpoken["time"] = currentTime
|
||||
|
||||
# Add to speech history (import here to avoid circular imports)
|
||||
try:
|
||||
from .services import SpeechHistoryService
|
||||
history_service = SpeechHistoryService.get_instance()
|
||||
history_service.add_message(text)
|
||||
except ImportError:
|
||||
pass
|
||||
if add_to_history:
|
||||
try:
|
||||
from .services import SpeechHistoryService
|
||||
history_service = SpeechHistoryService.get_instance()
|
||||
history_service.add_message(text)
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
# Proceed with speech based on provider and priority
|
||||
if self.providerName == "speechd":
|
||||
@@ -154,18 +156,19 @@ class Speech:
|
||||
# Global instance for backward compatibility
|
||||
_speechInstance = None
|
||||
|
||||
def speak(text, interrupt=True, priority="normal"):
|
||||
def speak(text, interrupt=True, priority="normal", add_to_history=True):
|
||||
"""Speak text using the global speech instance.
|
||||
|
||||
Args:
|
||||
text (str): Text to speak and display
|
||||
interrupt (bool): Whether to interrupt current speech (default: True)
|
||||
priority (str): Speech priority - "important", "normal", or "notification"
|
||||
add_to_history (bool): Whether to add this message to speech history (default: True)
|
||||
"""
|
||||
global _speechInstance
|
||||
if _speechInstance is None:
|
||||
_speechInstance = Speech.get_instance()
|
||||
_speechInstance.speak(text, interrupt, priority)
|
||||
_speechInstance.speak(text, interrupt, priority, add_to_history)
|
||||
|
||||
def messagebox(text, sounds=None):
|
||||
"""Enhanced messagebox with dialog support.
|
||||
@@ -356,25 +359,29 @@ def speak_previous():
|
||||
history_service = SpeechHistoryService.get_instance()
|
||||
message = history_service.move_previous()
|
||||
if message:
|
||||
speak(message, interrupt=True, priority="important")
|
||||
# Add position indicator
|
||||
prefix = ""
|
||||
if history_service.is_at_first():
|
||||
prefix = "First: "
|
||||
speak(prefix + message, interrupt=True, priority="important", add_to_history=False)
|
||||
else:
|
||||
speak("No previous messages", interrupt=True, priority="important")
|
||||
speak("No previous messages", interrupt=True, priority="important", add_to_history=False)
|
||||
except ImportError:
|
||||
speak("Speech history not available", interrupt=True, priority="important")
|
||||
speak("Speech history not available", interrupt=True, priority="important", add_to_history=False)
|
||||
|
||||
|
||||
def speak_current():
|
||||
"""Repeat the current message in speech history."""
|
||||
"""Repeat the most recent message in speech history (F2 always speaks last message)."""
|
||||
try:
|
||||
from .services import SpeechHistoryService
|
||||
history_service = SpeechHistoryService.get_instance()
|
||||
message = history_service.get_current()
|
||||
message = history_service.get_most_recent()
|
||||
if message:
|
||||
speak(message, interrupt=True, priority="important")
|
||||
speak("Last: " + message, interrupt=True, priority="important", add_to_history=False)
|
||||
else:
|
||||
speak("No current message", interrupt=True, priority="important")
|
||||
speak("No messages in history", interrupt=True, priority="important", add_to_history=False)
|
||||
except ImportError:
|
||||
speak("Speech history not available", interrupt=True, priority="important")
|
||||
speak("Speech history not available", interrupt=True, priority="important", add_to_history=False)
|
||||
|
||||
|
||||
def speak_next():
|
||||
@@ -384,8 +391,12 @@ def speak_next():
|
||||
history_service = SpeechHistoryService.get_instance()
|
||||
message = history_service.move_next()
|
||||
if message:
|
||||
speak(message, interrupt=True, priority="important")
|
||||
# Add position indicator
|
||||
prefix = ""
|
||||
if history_service.is_at_last():
|
||||
prefix = "Last: "
|
||||
speak(prefix + message, interrupt=True, priority="important", add_to_history=False)
|
||||
else:
|
||||
speak("No next messages", interrupt=True, priority="important")
|
||||
speak("No next messages", interrupt=True, priority="important", add_to_history=False)
|
||||
except ImportError:
|
||||
speak("Speech history not available", interrupt=True, priority="important")
|
||||
speak("Speech history not available", interrupt=True, priority="important", add_to_history=False)
|
||||
|
Reference in New Issue
Block a user