!7 cmodule SpeechRecognizer { switchable bool autoStart; //bool hideChromeWindow; // doesn't work transient new Flag flag; switchable bool showHostTrayIcon = true; switchable bool usePassiveLog; 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_watchFieldAndNow usePassiveLog(r { sendOpt(botName, usePassiveLog ? "use passive log" : "use active log"); }); if (autoStart) startListening(); } 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 (sendOpt(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); set(recognizer, onUtterance := voidfunc(S text) { 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 (!dm_osInForeground()) flatInfoBox(text); dm_setAIBarTextAndFireWithInfo(text, "Chrome Speech"); /*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); } }