!7 sS keyphrase = "computer"; // bigger number means more tolerance // 1e-40 works pretty well with few false positives // 1e-30 gets no hits // 1e-35 doesn't trigger reliably // Using 1e-39 for now sS threshold = "1e-39"; // seconds to listen after hot word // TODO: keep listening when user said something static int recognitionTimeout = 10; sS icon = /*#1009669*/ #1009667; //#1009662; // milliseconds before starting recognition (time for saying "yep" or "ja") static int delayBeforeRecognition = 300; sO onKeyPhrase; sbool exited; sS python = trim([[ #!/usr/bin/python from subprocess import Popen, PIPE, STDOUT import pty import os import sys cmd = 'pocketsphinx_continuous -inmic yes -keyphrase #KEYPHRASE# -kws_threshold #THRESHOLD#' master, slave = pty.openpty() p = Popen(cmd, shell=True, stdin=PIPE, stdout=slave, stderr=slave, close_fds=True) stdout = os.fdopen(master) while True: sys.stdout.write(stdout.readline()) sys.stdout.flush() ]]); static File fPython; static JButton btnStartStop; sbool paused; p-subst { if (!isLinux()) fail("Get Linux!"); load('paused); //onLeftClick(installTrayIcon(icon, "Computer!"), f jump_blip); TrayIcon trayIcon = onLeftClick( installTrayIcon2(resizeImage(loadImage2(icon), 24), "Computer!", makePopupMenu(menuItem("Computer!", f jump_blip))), f jump_blip); trayIcon.displayMessage( "", "Click on EVE to activate the assistant!", TrayIcon.MessageType.INFO/*NONE*/); makeBot("Hot Word Detection."); unix_killAll("pocketsphinx"); print("Key phrase is: " + keyphrase); onKeyPhrase = voidfunc(S s) { jump() }; swing { showControls(jcenteredline(btnStartStop = jbutton("Listen for hot word", f startStop))); } fPython = getProgramFile("pocketsphinx.py"); makeExecutable(saveTextFile(fPython, python.replace("#THRESHOLD#", threshold).replace("#KEYPHRASE#", bashQuote(keyphrase)))); titleStatus_setBaseTitle(consoleFrame(), "Hot Word Detection"); if (!paused) { infoBox("Say " + quote(keyphrase) + " to activate me!"); start(); } makeBot("Hot Word Detection."); } svoid start { setText(btnStartStop, "Don't listen for hot word"); thread { backtickToConsole_lineBuf(f2s(fPython), voidfunc(S line) { print("Line read: " + quote(line)); if (eq(line, keyphrase)) pcallF(onKeyPhrase, line); else if (startsWith(line, "READY.")) consoleStatus("Ready"); else if (startsWith(line, "Listening.")) consoleStatus("Listening"); }); setAndSave(paused := true); setText(btnStartStop, "Listen for hot word"); consoleStatus("Stopped"); } } svoid cleanMeUp { if (!exited) { exited = true; unix_killAll("pocketsphinx"); } } svoid startStop { if (paused) { setAndSave(paused := false); start(); } else { setAndSave(paused := true); setText(btnStartStop, "Listen for hot word"); unix_killAll("pocketsphinx"); } } svoid jump_blip { thread { infoBox(botAnswerWord()); blipAndWait(); sendOpt("Chrome Speech.", "start recognition timeout " + recognitionTimeout); } } svoid jump { fS response = botAnswerWord(); infoBox(response); thread { sleep(delayBeforeRecognition); sendOpt("Chrome Speech.", "start recognition timeout " + recognitionTimeout); } thread { sendOpt("Mouth.", response); } } answer { if "listen to hot word" { if (paused) startStop(); ret "OK"; } if "don't listen to hot word" { if (!paused) startStop(); ret "OK"; } }