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:
30
services.py
30
services.py
@@ -406,3 +406,33 @@ class SpeechHistoryService:
|
|||||||
int: Number of messages in history
|
int: Number of messages in history
|
||||||
"""
|
"""
|
||||||
return len(self.history)
|
return len(self.history)
|
||||||
|
|
||||||
|
def is_at_first(self):
|
||||||
|
"""Check if currently at the first (oldest) message in history.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: True if at the first message
|
||||||
|
"""
|
||||||
|
if not self.history:
|
||||||
|
return False
|
||||||
|
return self.current_index == 0
|
||||||
|
|
||||||
|
def is_at_last(self):
|
||||||
|
"""Check if currently at the last (newest) message in history.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: True if at the last message or viewing most recent
|
||||||
|
"""
|
||||||
|
if not self.history:
|
||||||
|
return False
|
||||||
|
return self.current_index == -1 or self.current_index == len(self.history) - 1
|
||||||
|
|
||||||
|
def get_most_recent(self):
|
||||||
|
"""Get the most recent message (what F2 should always say).
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str or None: Most recent message text, or None if no history
|
||||||
|
"""
|
||||||
|
if not self.history:
|
||||||
|
return None
|
||||||
|
return self.history[-1]['text']
|
||||||
|
51
speech.py
51
speech.py
@@ -61,13 +61,14 @@ class Speech:
|
|||||||
# No speech providers found
|
# No speech providers found
|
||||||
print("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.
|
"""Speak text using the configured speech provider and display on screen.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
text (str): Text to speak and display
|
text (str): Text to speak and display
|
||||||
interrupt (bool): Whether to interrupt current speech (default: True)
|
interrupt (bool): Whether to interrupt current speech (default: True)
|
||||||
priority (str): Speech priority - "important", "normal", or "notification"
|
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:
|
if not self.provider:
|
||||||
return
|
return
|
||||||
@@ -84,12 +85,13 @@ class Speech:
|
|||||||
self.lastSpoken["time"] = currentTime
|
self.lastSpoken["time"] = currentTime
|
||||||
|
|
||||||
# Add to speech history (import here to avoid circular imports)
|
# Add to speech history (import here to avoid circular imports)
|
||||||
try:
|
if add_to_history:
|
||||||
from .services import SpeechHistoryService
|
try:
|
||||||
history_service = SpeechHistoryService.get_instance()
|
from .services import SpeechHistoryService
|
||||||
history_service.add_message(text)
|
history_service = SpeechHistoryService.get_instance()
|
||||||
except ImportError:
|
history_service.add_message(text)
|
||||||
pass
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
# Proceed with speech based on provider and priority
|
# Proceed with speech based on provider and priority
|
||||||
if self.providerName == "speechd":
|
if self.providerName == "speechd":
|
||||||
@@ -154,18 +156,19 @@ class Speech:
|
|||||||
# Global instance for backward compatibility
|
# Global instance for backward compatibility
|
||||||
_speechInstance = None
|
_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.
|
"""Speak text using the global speech instance.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
text (str): Text to speak and display
|
text (str): Text to speak and display
|
||||||
interrupt (bool): Whether to interrupt current speech (default: True)
|
interrupt (bool): Whether to interrupt current speech (default: True)
|
||||||
priority (str): Speech priority - "important", "normal", or "notification"
|
priority (str): Speech priority - "important", "normal", or "notification"
|
||||||
|
add_to_history (bool): Whether to add this message to speech history (default: True)
|
||||||
"""
|
"""
|
||||||
global _speechInstance
|
global _speechInstance
|
||||||
if _speechInstance is None:
|
if _speechInstance is None:
|
||||||
_speechInstance = Speech.get_instance()
|
_speechInstance = Speech.get_instance()
|
||||||
_speechInstance.speak(text, interrupt, priority)
|
_speechInstance.speak(text, interrupt, priority, add_to_history)
|
||||||
|
|
||||||
def messagebox(text, sounds=None):
|
def messagebox(text, sounds=None):
|
||||||
"""Enhanced messagebox with dialog support.
|
"""Enhanced messagebox with dialog support.
|
||||||
@@ -356,25 +359,29 @@ def speak_previous():
|
|||||||
history_service = SpeechHistoryService.get_instance()
|
history_service = SpeechHistoryService.get_instance()
|
||||||
message = history_service.move_previous()
|
message = history_service.move_previous()
|
||||||
if message:
|
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:
|
else:
|
||||||
speak("No previous messages", interrupt=True, priority="important")
|
speak("No previous messages", interrupt=True, priority="important", add_to_history=False)
|
||||||
except ImportError:
|
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():
|
def speak_current():
|
||||||
"""Repeat the current message in speech history."""
|
"""Repeat the most recent message in speech history (F2 always speaks last message)."""
|
||||||
try:
|
try:
|
||||||
from .services import SpeechHistoryService
|
from .services import SpeechHistoryService
|
||||||
history_service = SpeechHistoryService.get_instance()
|
history_service = SpeechHistoryService.get_instance()
|
||||||
message = history_service.get_current()
|
message = history_service.get_most_recent()
|
||||||
if message:
|
if message:
|
||||||
speak(message, interrupt=True, priority="important")
|
speak("Last: " + message, interrupt=True, priority="important", add_to_history=False)
|
||||||
else:
|
else:
|
||||||
speak("No current message", interrupt=True, priority="important")
|
speak("No messages in history", interrupt=True, priority="important", add_to_history=False)
|
||||||
except ImportError:
|
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():
|
def speak_next():
|
||||||
@@ -384,8 +391,12 @@ def speak_next():
|
|||||||
history_service = SpeechHistoryService.get_instance()
|
history_service = SpeechHistoryService.get_instance()
|
||||||
message = history_service.move_next()
|
message = history_service.move_next()
|
||||||
if message:
|
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:
|
else:
|
||||||
speak("No next messages", interrupt=True, priority="important")
|
speak("No next messages", interrupt=True, priority="important", add_to_history=False)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
speak("Speech history not available", interrupt=True, priority="important")
|
speak("Speech history not available", interrupt=True, priority="important", add_to_history=False)
|
||||||
|
5
utils.py
5
utils.py
@@ -156,18 +156,19 @@ class Game:
|
|||||||
# No logo image found, just play audio
|
# No logo image found, just play audio
|
||||||
self.sound.cut_scene(audioKey)
|
self.sound.cut_scene(audioKey)
|
||||||
|
|
||||||
def speak(self, text, interrupt=True, priority="normal"):
|
def speak(self, text, interrupt=True, priority="normal", add_to_history=True):
|
||||||
"""Speak text using the speech system.
|
"""Speak text using the speech system.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
text (str): Text to speak
|
text (str): Text to speak
|
||||||
interrupt (bool): Whether to interrupt current speech
|
interrupt (bool): Whether to interrupt current speech
|
||||||
priority (str): Speech priority - "important", "normal", or "notification"
|
priority (str): Speech priority - "important", "normal", or "notification"
|
||||||
|
add_to_history (bool): Whether to add this message to speech history (default: True)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Game: Self for method chaining
|
Game: Self for method chaining
|
||||||
"""
|
"""
|
||||||
self.speech.speak(text, interrupt, priority)
|
self.speech.speak(text, interrupt, priority, add_to_history)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def speak_previous(self):
|
def speak_previous(self):
|
||||||
|
Reference in New Issue
Block a user