!7 cmodule SpeechRecognizer { switchable bool autoStart; //bool hideChromeWindow; // doesn't work transient new Flag flag; switchable bool showHostTrayIcon = true; switchable bool nonActionMode; // use "passive log" to prevent normal programs from reacting to speech switchable bool flatInfoBox = true; transient S botName = "Chrome Speech."; start { O[] menuItems = litobjectarray( "Start Listening", rThread startListening, "Stop Listening", rThread stopListening, "Switch to German", rThread switchToGerman, "Switch to English", rThread switchToEnglish); dm_addTrayIcon_left(componentPopupMenuItems(onLeftClick( toolTip(jimage_16(#1101635), "Continuous Speech Recognizer"), rThread startListening), menuItems)); dm_reloadOnFieldChange showHostTrayIcon(); if (showHostTrayIcon) dm_systemTrayIcon(#1101635, "Continuous Speech Recognizer", itemPlusArray(rThread startListening, menuItems)); dm_watchField nonActionMode(r { infoBox(or2(sendOpt(botName, nonActionMode ? "use passive log" : "use active log"), "No response")); updateTitle(); }); updateTitle(); if (autoStart) startListening(); } void updateTitle { setModuleName((nonActionMode ? "[NON ACTION MODE]" : "") + " Speech Recognizer Using Chrome"); } visualize { ret jfullcenter(jButtonWithInset("Start listening", rThread doIt)); } void setLanguage(S language) { if (sendOpt("botName", "language *", language) == null) startRecognizer(true); } void switchToEnglish { setLanguage("en-US"); } void switchToGerman { setLanguage("de-DE"); } void startListening { doIt(false); } void justOnce { doIt(true); } void doIt enter { doIt(false); } void doIt(bool justOnce) enter { if (sendOptQuietly(botName, justOnce ? "just once" : "start recognition") == null) startRecognizer(justOnce); } // only call if it's not running already void startRecognizer(bool justOnce) { print("Starting recognizer"); fO recognizer = hotwireDependent(#1009816); setAll(recognizer, doLog := false/*, +hideChromeWindow*/, usePassiveLog := nonActionMode); set(recognizer, onUtterance := voidfunc(S text) { if (nonActionMode) ret; S corrected = dm_correctRecognizedSpeech(text); if (neq(corrected, text)) { print("Correcting " + quote(text) + " to " + quote(corrected)); vmBus_send('correctedRecognizedSpeech, text, corrected); text = corrected; } else print("Recognized: " + text); if (flatInfoBox && !dm_osInForeground()) flatInfoBox(text); S info = "Chrome Speech"; /*if (!vmBus_anyTrue dontApplyRecognizedSpeech()) dm_setAIBarTextAndFireWithInfo(text, info);*/ dm_rawSpeechRecognized(module(), text, info, null); /*if (ai_isStopListeningCommand(text)) { call(recognizer, 'stopRecognition); playBlip(); }*/ }); set(recognizer, +justOnce); /*if (flag.raise()) dm_putRecognizedSpeechInAIBar();*/ runMain(recognizer); } void stopListening enter { sendOpt(botName, "stop recognition"); } void enhanceFrame(JInternalFrame f) { super.enhanceFrame(f); internalFrameTitleMenuItems(f, "Switch to German", rThread switchToGerman, "Switch to English", rThread switchToEnglish); } }