Skip to content

Commit

Permalink
added delete story and go home to intent_server.py
Browse files Browse the repository at this point in the history
  • Loading branch information
hbarnard committed Mar 2, 2023
1 parent 705b67c commit ac7a14c
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 16 deletions.
Binary file modified __pycache__/intent_server.cpython-39.pyc
Binary file not shown.
Binary file modified db/memories.db
Binary file not shown.
2 changes: 1 addition & 1 deletion etc/mema.ini
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ done = Done_and_dusted
what_kind = What_kind_of_pie_would_you_like?
ok_going = OK_here_we_go
say_please = say_please_why_dont_you
delete = Deleting_memory_now
#FIXME: should be [literals][en] as above
[en_literals]
Expand Down
4 changes: 3 additions & 1 deletion etc/mema_laptop.ini
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ keyword_slot_file = ~/.config/rhasspy/profiles/en/slots/keywords

intent_server = http://localhost:8000

# voice recognition confidence
# voice recognition confidence, move this down for noisy rooms, but risk of garbled transcription
confidence = 0.98

rhasspy_main = http://localhost:12101
Expand All @@ -83,6 +83,7 @@ language = en

#FIXME: some small prompts within the intent server, should be [prompts][en] to give full multilingual addressability
# with Mimic3 we can have voice ssml too, prosody speed
#FIXME: should be [prompts][en] can routine this as language + '_' + 'prompts' though
[en_prompts]
sorry = I_cannot_find_that_sorry
not_understood = Sorry_I_cannot_understand_that
Expand All @@ -103,6 +104,7 @@ ok_going = OK_here_we_go
wait_a_moment = Please_wait_a_moment
say_please = Say_please_please
bye_bye = Bye_bye_come_back_soon
delete = Deleting_memory_now
#FIXME: should be [literals][en] as above
Expand Down
4 changes: 2 additions & 2 deletions etc/mema_pi.ini
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ done = Done_and_dusted
what_kind = What_kind_of_pie_would_you_like?
ok_going = OK_here_we_go
say_please = say_please_why_dont_you
delete = Deleting_memory_now
#FIXME: should be [literals][en] as above
#FIXME: should be [literals][en] as above, but means running search and replace right through the application
[en_literals]
unlabelled_video = unlabelled video recording
unlabelled_picture = unlabelled still image
Expand Down
57 changes: 45 additions & 12 deletions intent_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

from configobj import ConfigObj

sqlite3.enable_callback_tracebacks(True)

app = FastAPI(debug=True)
app.mount("/static", StaticFiles(directory="static"), name="static")
app.mount("/media", StaticFiles(directory="static/media", html=True), name="media")
Expand Down Expand Up @@ -94,15 +96,23 @@ async def info(info : Request):
raw_speech = req_info['input']
intent = req_info['intent']['intentName']

#FIXME: parse numbers and courtesy, tidy this up and extend for privacy declarations
#FIXME: parse numbers, courtesy and unlock for delete, tidy this up and extend for privacy declarations
number = None
polite = None
sesame = None

match = re.search(r'\b\d+\b', raw_speech)
if match:
number = match.group(0)

match = re.search(r'\bplease\b', raw_speech)
if match:
polite = match.group(0)

match = re.search(r'\bsesame\b', raw_speech)
if match:
sesame = match.group(0)


# confidence level too low or garbled intent
if not len(intent) or (req_info['asrConfidence'] < float(config['main']['confidence'])) :
Expand All @@ -116,28 +126,28 @@ async def info(info : Request):
#FIXME one or two, such as redirects can't be handled in the intent table, via switch in node-red?
if intent == "GetStory" and (number[0] in number):
url = config['main']['intent_server'] + "/memory/" + str(number[0]) + "/speak"
return RedirectResponse(url)
return RedirectResponse(url)

if intent == "DeleteStory" and (number[0] in number) and (sesame[0] in sesame):
run_delete_command(number[0],polite,config)
url = config['main']['intent_server'] + "/memories.html/"
return RedirectResponse(url)


# intents are the options see: https://stackoverflow.com/questions/17881409/whats-an-alternative-to-if-elif-statements-in-python
intents = {

'TakePhoto' : run_photo_command,
# 'GetTime' : run_time_command,
# 'Associate' : print("associate photo and story found"),
'RecordStory' : run_record_command,
'RecordVideo' : run_video_command,
'KillVideo' : run_kill_video_command,
'LabelVideo' : run_label_video_command,
'SlicePie' : run_pie,
'SearchPage' : run_search_command,
'LetsGo' : run_front_page,
# 'SearchMemories' : run_search_memories,
'Mosaic' : run_mosaic_command,
# moved to face_unlock.py face unlock sign in as a registered user
# 'Unlock' : run_face_unlock,
# sign out, actuall sign in signs out anyone else
# 'Lock' : run_sign_out

'GoHome' : go_home,
}

if intent in intents:
Expand All @@ -153,7 +163,30 @@ async def info(info : Request):

logging.debug('<---is when this event returns.')

# take a photo and store it

# delete a record

def run_delete_command(number,polite,config):
logging.debug('in delete record ' + number)
mu.curl_speak(config['en_prompts']['delete'])
try:
cur = con.cursor()
cur.execute("DELETE from memories where memory_id = ?", number)
con.commit()
mu.curl_speak(config['en_prompts']['done'])
except:
raise RuntimeError("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output))
#logging.debug('deleted record ' + number)
return

# go back to top

def go_home(number,polite,config, response_class=HTMLResponse):
logging.debug('in go home')
mu.open_url('memories.html',config)
return

# take a photo

def run_photo_command(number,polite,config):

Expand Down Expand Up @@ -205,7 +238,7 @@ def run_record_command(number,please,config):

def run_video_command(number,please,config):

print("record video found") if config['main']['debug'] else None
#print("record video found") if config['main']['debug'] else None

result = subprocess.check_output(config['main']['video_program'], stderr=subprocess.STDOUT)
result_string = result.decode('utf-8')
Expand All @@ -230,7 +263,7 @@ def run_video_command(number,please,config):

def run_kill_video_command(number,please,config):

print("kill video record found") if config['main']['debug'] else None
#print("kill video record found") if config['main']['debug'] else None
com_array = config['main']['kill_video_command'].split()
subprocess.call(com_array,stdout=subprocess.DEVNULL,stderr=subprocess.STDOUT)
return
Expand Down

0 comments on commit ac7a14c

Please sign in to comment.