Hallo in die Runde,
ich arbeite gerade an einer neuen, nutzerfreundlicheren Version der Sprachausgabe meines Kumpels.
Da er nicht in der Lage ist zu sprechen, hilft ihm die Sprachausgabe im Alltag.
Die neue Version soll das Auswählen der Sprachkategorie und des Sprachbefehls erleichtern.
Wichtig ist hierbei, dass möglichst kein Mausklick notwendig ist.
(Maussteuerung erfolgt via Bluetooth über den Rollstuhl Joystick,
für einen Klick muss ein Button am Rollstuhl für 2 Sekunden gehalten werden)
Meine Idee war daher, mit aktiven Bereichen in einer GUI zu arbeiten.
Sobald der Mauszeiger den linken Balken berührt, wird er in die Mitte des Displays zurück gesetzt und die Kategorie gewechselt.
Durch Berührung des Mauszeigers des oberen und unteren Balken wird durch die Sprachbefehle gescrollt.
Der rechte Balken startet den mplayer der eine WAV Datei mit dem Sprachbefehl abspielt.
Das große Problem ist allerdings, dass auf dem Raspberry eine Berührung des Balken gleich mehrere Events auslöst.
Der Sprachbefehl wird beispielsweise gleich 4x abgespielt.
Öffne ich die GUI am Macbook, funktioniert es einwandfrei....
Daher der meine bitte, ob ihr mal über den Code schauen könntet und
einen Tipp für mich habt
#!/usr/bin/env python
import pygame
from time import strftime
import os
# Speech data
# Gespraech
category1 = ("",
"Hallo",
"Wie gehts",
"Wie geht es ihnen",
"Mir gehts gut",
"und dir",
"Ja",
"Nein",
"Vielleicht",
"Moment",
"Was geht",
"Tschuess",
"Was")
# Pflege
category2 = ("",
"Absaugen",
"Nase",
"Inhalieren",
"Ins Bett",
"Blaest ab",
"Block pruefen",
"Entblocken",
"Blocken")
# Nahrung
category3 = ("",
"Hunger",
"Kroketten",
"Kaese",
"Kartoffelbrei",
"Ei",
"Eis",
"Fisch",
"Fischstaebchen",
"Pizza Tonno",
"Sosse")
# Trinken
category4 = ("",
"Durst",
"Bier",
"Eistee",
"Cola",
"Wasser",
"Schnaps")
# Ausdruecke
category5 = ("",
"Depp",
"Arsch",
"Idiot",
"Du bist zu Dick",
"Ihr seid alle Penner",
"Fuck you",
"Fuck off",
"Bist du behindert",
"Bist du bloed",
"Noob")
# Orte
category6 = ("",
"Weg gehen",
"Wolf",
"Eis",
"Main",
"Daniel",
"Hof",
"Breuburg",
"Oma Gertrud",
"Frankfurt")
# Notfall
category7 = ("",
"Ich heisse")
categoryID = 1
commandID = 1
# Variablen deklaration
# Colors
BLACK = ( 0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = ( 0, 255, 0)
BLUE = ( 0, 0, 255)
CYAN = ( 0, 255, 255)
MAGENTA=(255, 0, 255)
YELLOW =(255, 255, 0)
# Screen
size=[320,240]
#screen=pygame.display.set_mode(size, pygame.FULLSCREEN | pygame.NOFRAME)
screen=pygame.display.set_mode(size)
clock=pygame.time.Clock()
pygame.init()
font = pygame.font.Font(None, 36)
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill(WHITE)
# Draw lines
# Top
lineTop = pygame.draw.rect(background, GREEN,(5, 0, 315, 5))
# Bottom
lineBottom = pygame.draw.rect(background, BLUE, (5, 235, 315, 240))
# Right
lineRight = pygame.draw.rect(background, CYAN, (315, 0, 320, 240))
# Left
lineLeft = pygame.draw.rect(background, MAGENTA, (0, 0, 5, 240))
def drawLines():
# Top
lineTop = pygame.draw.rect(background, GREEN,(5, 0, 315, 5))
# Bottom
lineBottom = pygame.draw.rect(background, BLUE, (5, 235, 315, 240))
# Right
lineRight = pygame.draw.rect(background, CYAN, (315, 0, 320, 240))
# Left
lineLeft = pygame.draw.rect(background, MAGENTA, (0, 0, 5, 240))
def writeSpeechCommands(categoryID,commandID):
entry = 0
# loads the standard font with a size of 36 pixels
font1 = pygame.font.Font(None, 20)
font2 = pygame.font.Font(None, 46)
if categoryID == 1:
category = category1
elif categoryID == 2:
category = category2
elif categoryID == 3:
category = category3
elif categoryID == 4:
category = category4
elif categoryID == 5:
category = category5
elif categoryID == 6:
category = category6
elif categoryID == 7:
category = category7
# create the single menu entries, each entry is center in x
for command in category:
if entry == commandID-1:
text = font1.render(command,1,(BLACK))
textpos = text.get_rect(centerx=160,centery=80)
screen.blit(text, textpos)
if entry == commandID:
text = font2.render(command,1,(BLACK))
textpos = text.get_rect(centerx=160,centery=120)
screen.blit(text, textpos)
if entry == commandID+1:
text = font1.render(command,1,(BLACK))
textpos = text.get_rect(centerx=160,centery=160)
screen.blit(text, textpos)
entry += 1
def playSpeechCommand(categoryID,commandID):
if categoryID == 1:
category = category1
elif categoryID == 2:
category = category2
elif categoryID == 3:
category = category3
elif categoryID == 4:
category = category4
elif categoryID == 5:
category = category5
elif categoryID == 6:
category = category6
elif categoryID == 7:
category = category7
entry = 0
for command in category:
if entry == commandID:
print command
os.system('sudo python /home/pi/python/playSpeechCommand.py ' + command)
break
entry += 1
# Screen vorbereiten
screen.blit(background, (0, 0))
pygame.display.flip()
running = True
writeSpeechCommands(categoryID,commandID)
# Schleife starten
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT: # If user clicked close
running = False # Flag that we are done so we exit this loop
elif event.type == pygame.MOUSEMOTION:
if lineTop.collidepoint(pygame.mouse.get_pos()):
pygame.mouse.set_pos([180,120])
commandID -= 1
if commandID < 1:
commandID = 1
screen.blit(background, (0, 0))
drawLines()
writeSpeechCommands(categoryID,commandID)
elif lineBottom.collidepoint(pygame.mouse.get_pos()):
pygame.mouse.set_pos([180,120])
commandID += 1
screen.blit(background, (0, 0))
drawLines()
writeSpeechCommands(categoryID,commandID)
elif lineLeft.collidepoint(pygame.mouse.get_pos()):
pygame.mouse.set_pos([180,120])
categoryID += 1
commandID = 1
if categoryID >= 8:
categoryID = 1
screen.blit(background, (0, 0))
drawLines()
writeSpeechCommands(categoryID,commandID)
elif lineRight.collidepoint(pygame.mouse.get_pos()):
pygame.mouse.set_pos([180,120])
playSpeechCommand(categoryID,commandID)
elif event.type == pygame.MOUSEBUTTONDOWN:
running = False
elif event.type == pygame.KEYDOWN and event.key == pygame.K_BACKSPACE:
running = False
# Update Display
pygame.display.flip()
# Limit to 20 frames per second
clock.tick(20)
# Close the window and quit.
pygame.quit()
Alles anzeigen
Vielen Dank vorab
lg bigdane