Directory names were not speaking. Hopefully fixed it.
This commit is contained in:
parent
5e926fa7eb
commit
3b01662d98
37
menu.py
37
menu.py
@ -330,32 +330,32 @@ def learn_sounds(sounds):
|
|||||||
|
|
||||||
# Track last spoken to avoid repetition
|
# Track last spoken to avoid repetition
|
||||||
lastSpoken = -1
|
lastSpoken = -1
|
||||||
lastDir = None
|
directoryChanged = True # Flag to track if directory just changed
|
||||||
|
|
||||||
# Flag to track when to exit the loop
|
# Flag to track when to exit the loop
|
||||||
returnToMenu = False
|
returnToMenu = False
|
||||||
|
|
||||||
while not returnToMenu:
|
while not returnToMenu:
|
||||||
# Announce directory change
|
|
||||||
if lastDir != currentDir:
|
|
||||||
if currentDir == 'root':
|
|
||||||
speech.speak(f"Root directory sounds. {len(currentSoundKeys)} sounds available.")
|
|
||||||
else:
|
|
||||||
speech.speak(f"{currentDir} sounds. {len(currentSoundKeys)} sounds available.")
|
|
||||||
lastDir = currentDir
|
|
||||||
lastSpoken = -1 # Reset to announce current sound
|
|
||||||
|
|
||||||
# Announce current sound
|
# Announce current sound
|
||||||
if currentSoundIndex != lastSpoken:
|
if currentSoundIndex != lastSpoken:
|
||||||
totalSounds = len(currentSoundKeys)
|
totalSounds = len(currentSoundKeys)
|
||||||
soundName = currentSoundKeys[currentSoundIndex]
|
soundName = currentSoundKeys[currentSoundIndex]
|
||||||
|
|
||||||
# Remove directory prefix if present
|
# Remove directory prefix if present
|
||||||
if '/' in soundName:
|
if '/' in soundName:
|
||||||
displayName = '/'.join(soundName.split('/')[1:])
|
displayName = '/'.join(soundName.split('/')[1:])
|
||||||
else:
|
else:
|
||||||
displayName = soundName
|
displayName = soundName
|
||||||
|
|
||||||
speech.speak(f"{displayName}, {currentSoundIndex + 1} of {totalSounds}")
|
# If directory just changed, include directory name in announcement
|
||||||
|
if directoryChanged:
|
||||||
|
dirDescription = "Root directory" if currentDir == 'root' else currentDir
|
||||||
|
announcement = f"{dirDescription}: {displayName}, {currentSoundIndex + 1} of {totalSounds}"
|
||||||
|
directoryChanged = False # Reset flag after announcement
|
||||||
|
else:
|
||||||
|
announcement = f"{displayName}, {currentSoundIndex + 1} of {totalSounds}"
|
||||||
|
|
||||||
|
speech.speak(announcement)
|
||||||
lastSpoken = currentSoundIndex
|
lastSpoken = currentSoundIndex
|
||||||
|
|
||||||
event = pygame.event.wait()
|
event = pygame.event.wait()
|
||||||
@ -366,26 +366,30 @@ def learn_sounds(sounds):
|
|||||||
# Sound navigation
|
# Sound navigation
|
||||||
elif event.key in [pygame.K_DOWN, pygame.K_s] and currentSoundIndex < len(currentSoundKeys) - 1:
|
elif event.key in [pygame.K_DOWN, pygame.K_s] and currentSoundIndex < len(currentSoundKeys) - 1:
|
||||||
pygame.mixer.stop()
|
pygame.mixer.stop()
|
||||||
currentSoundIndex += 1 # Fixed: Was decreasing instead of increasing
|
currentSoundIndex += 1
|
||||||
|
|
||||||
elif event.key in [pygame.K_UP, pygame.K_w] and currentSoundIndex > 0:
|
elif event.key in [pygame.K_UP, pygame.K_w] and currentSoundIndex > 0:
|
||||||
pygame.mixer.stop()
|
pygame.mixer.stop()
|
||||||
currentSoundIndex -= 1
|
currentSoundIndex -= 1
|
||||||
|
|
||||||
# Directory navigation
|
# Directory navigation
|
||||||
elif event.key in [pygame.K_PAGEDOWN, pygame.K_RIGHT] and currentDirIndex < len(directories) - 1: # Fixed: Right moves forward
|
elif event.key in [pygame.K_PAGEDOWN, pygame.K_RIGHT] and currentDirIndex < len(directories) - 1:
|
||||||
pygame.mixer.stop()
|
pygame.mixer.stop()
|
||||||
currentDirIndex += 1
|
currentDirIndex += 1
|
||||||
currentDir = directories[currentDirIndex]
|
currentDir = directories[currentDirIndex]
|
||||||
currentSoundKeys = soundsByDir[currentDir]
|
currentSoundKeys = soundsByDir[currentDir]
|
||||||
currentSoundIndex = 0
|
currentSoundIndex = 0
|
||||||
|
directoryChanged = True # Set flag on directory change
|
||||||
|
lastSpoken = -1 # Force announcement
|
||||||
|
|
||||||
elif event.key in [pygame.K_PAGEUP, pygame.K_LEFT] and currentDirIndex > 0: # Fixed: Left moves backward
|
elif event.key in [pygame.K_PAGEUP, pygame.K_LEFT] and currentDirIndex > 0:
|
||||||
pygame.mixer.stop()
|
pygame.mixer.stop()
|
||||||
currentDirIndex -= 1 # Fixed: Was incrementing instead of decrementing
|
currentDirIndex -= 1
|
||||||
currentDir = directories[currentDirIndex]
|
currentDir = directories[currentDirIndex]
|
||||||
currentSoundKeys = soundsByDir[currentDir]
|
currentSoundKeys = soundsByDir[currentDir]
|
||||||
currentSoundIndex = 0
|
currentSoundIndex = 0
|
||||||
|
directoryChanged = True # Set flag on directory change
|
||||||
|
lastSpoken = -1 # Force announcement
|
||||||
|
|
||||||
# Play sound
|
# Play sound
|
||||||
elif event.key == pygame.K_RETURN:
|
elif event.key == pygame.K_RETURN:
|
||||||
@ -393,7 +397,8 @@ def learn_sounds(sounds):
|
|||||||
soundName = currentSoundKeys[currentSoundIndex]
|
soundName = currentSoundKeys[currentSoundIndex]
|
||||||
pygame.mixer.stop()
|
pygame.mixer.stop()
|
||||||
sounds[soundName].play()
|
sounds[soundName].play()
|
||||||
except:
|
except Exception as e:
|
||||||
|
print(f"Error playing sound: {e}")
|
||||||
speech.speak("Could not play sound.")
|
speech.speak("Could not play sound.")
|
||||||
|
|
||||||
event = pygame.event.clear()
|
event = pygame.event.clear()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user