Sound manager added. Pitch controls for menu voice bound to { and }.
This commit is contained in:
@@ -47,6 +47,7 @@ class VoicedMenu:
|
||||
|
||||
# Default settings
|
||||
self.speechRate = 0 # Normal speech rate (0 is default in speechd)
|
||||
self.speechPitch = 0 # Normal speech pitch
|
||||
self.volume = 50 # Default volume level
|
||||
|
||||
# Load settings
|
||||
@@ -97,8 +98,9 @@ class VoicedMenu:
|
||||
self.speechClient.set_priority(speechd.Priority.IMPORTANT)
|
||||
self.speechClient.set_punctuation(speechd.PunctuationMode.SOME)
|
||||
|
||||
# Apply speech rate from settings
|
||||
# Apply speech settings from saved values
|
||||
self.speechClient.set_rate(self.speechRate)
|
||||
self.speechClient.set_pitch(self.speechPitch)
|
||||
except Exception as e:
|
||||
print(f"Could not initialize speech: {e}")
|
||||
# Fallback to None - the speak method will handle this
|
||||
@@ -116,6 +118,7 @@ class VoicedMenu:
|
||||
# Load speech settings
|
||||
if 'Speech' in self.config:
|
||||
self.speechRate = self.config.getint('Speech', 'rate', fallback=0)
|
||||
self.speechPitch = self.config.getint('Speech', 'pitch', fallback=0)
|
||||
|
||||
# Load volume settings
|
||||
if 'Volume' in self.config:
|
||||
@@ -134,6 +137,7 @@ class VoicedMenu:
|
||||
self.config['Speech'] = {}
|
||||
|
||||
self.config['Speech']['rate'] = str(self.speechRate)
|
||||
self.config['Speech']['pitch'] = str(self.speechPitch)
|
||||
|
||||
# Save volume settings
|
||||
if 'Volume' not in self.config:
|
||||
@@ -174,6 +178,32 @@ class VoicedMenu:
|
||||
# Save the new setting
|
||||
self.save_settings()
|
||||
|
||||
def increase_speech_pitch(self):
|
||||
"""Increase speech pitch"""
|
||||
self.speechPitch = min(100, self.speechPitch + 10) # Max is 100
|
||||
if self.speechClient:
|
||||
try:
|
||||
self.speechClient.set_pitch(self.speechPitch)
|
||||
self.speak(f"Speech pitch: {self.speechPitch}")
|
||||
except Exception as e:
|
||||
print(f"Error adjusting speech pitch: {e}")
|
||||
|
||||
# Save the new setting
|
||||
self.save_settings()
|
||||
|
||||
def decrease_speech_pitch(self):
|
||||
"""Decrease speech pitch"""
|
||||
self.speechPitch = max(-100, self.speechPitch - 10) # Min is -100
|
||||
if self.speechClient:
|
||||
try:
|
||||
self.speechClient.set_pitch(self.speechPitch)
|
||||
self.speak(f"Speech pitch: {self.speechPitch}")
|
||||
except Exception as e:
|
||||
print(f"Error adjusting speech pitch: {e}")
|
||||
|
||||
# Save the new setting
|
||||
self.save_settings()
|
||||
|
||||
def get_current_volume(self):
|
||||
"""Get the current system volume percentage"""
|
||||
try:
|
||||
@@ -774,6 +804,8 @@ class VoicedMenu:
|
||||
B key: Report battery status.
|
||||
Left bracket: Decrease speech rate.
|
||||
Right bracket: Increase speech rate.
|
||||
Left brace: Decrease speech pitch.
|
||||
Right brace: Increase speech pitch.
|
||||
9 key: Decrease volume.
|
||||
0 key: Increase volume.
|
||||
Escape: Refresh the menu.
|
||||
@@ -793,7 +825,7 @@ class VoicedMenu:
|
||||
self.stdscr.addstr(1, x, title, curses.A_BOLD)
|
||||
|
||||
# Draw help line
|
||||
helpText = "Ãvigate | Enter: Select | H: Help | [ ] Rate | 9 0 Volume | Esc: Refresh"
|
||||
helpText = "Navigate | Enter: Select | H: Help | [ ] Rate | { } Pitch | 9 0 Volume | Esc: Refresh"
|
||||
x = max(0, w // 2 - len(helpText) // 2)
|
||||
self.stdscr.addstr(3, x, helpText)
|
||||
|
||||
@@ -826,6 +858,11 @@ class VoicedMenu:
|
||||
rateText = f"Speech Rate: {self.speechRate}"
|
||||
self.stdscr.addstr(h-2, 2, rateText)
|
||||
|
||||
# Draw speech pitch indicator
|
||||
pitchText = f"Pitch: {self.speechPitch}"
|
||||
pitchX = max(0, w // 2 - len(pitchText) // 2)
|
||||
self.stdscr.addstr(h-2, pitchX, pitchText)
|
||||
|
||||
# Draw volume indicator
|
||||
volumeText = f"Volume: {self.get_current_volume()}%"
|
||||
self.stdscr.addstr(h-2, w-len(volumeText)-2, volumeText)
|
||||
@@ -965,6 +1002,14 @@ class VoicedMenu:
|
||||
self.increase_speech_rate()
|
||||
self.draw_menu()
|
||||
|
||||
elif key == ord('{'): # Decrease speech pitch
|
||||
self.decrease_speech_pitch()
|
||||
self.draw_menu()
|
||||
|
||||
elif key == ord('}'): # Increase speech pitch
|
||||
self.increase_speech_pitch()
|
||||
self.draw_menu()
|
||||
|
||||
elif key == ord('9'): # Decrease volume
|
||||
self.decrease_volume()
|
||||
|
||||
@@ -1147,6 +1192,7 @@ if __name__ == "__main__":
|
||||
menu.add_section("Accessories")
|
||||
menu.add_item("Accessories", "Local IP Address", "/usr/local/bin/ip_info.py local")
|
||||
menu.add_item("Accessories", "Remote IP Address", "/usr/local/bin/ip_info.py remote")
|
||||
menu.add_item("Accessories", "Sound and Volume", "/usr/local/bin/audio_manager.py")
|
||||
menu.add_item("Accessories", "Web Browser", "GAME=Brave startx")
|
||||
menu.add_item("Accessories", "LibreOffice", lambda: menu.install_and_launch("libreoffice", "gui"))
|
||||
menu.add_item("Accessories", "Thunderbird", lambda: menu.install_and_launch("thunderbird", "gui"))
|
||||
|
||||
Reference in New Issue
Block a user