!7 module SpeechRecognizer { bool autoStart; //bool hideChromeWindow; // doesn't work transient new Flag flag; start { if (autoStart) startListening(); } visualize { ret jfullcenter(jButtonWithInset("Start listening", rThread doIt)); } S switchableFields() { ret "autoStart"; } void startListening { doIt(false); } void justOnce { doIt(true); } void doIt enter { doIt(false); } void doIt(bool justOnce) enter { if (sendOpt("Chrome Speech.", justOnce ? "just once" : "start recognition") == null) { print("Starting recognizer"); fO recognizer = hotwireDependent(#1009816); setAll(recognizer, doLog := false/*, +hideChromeWindow*/); 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("Chrome Speech.", "stop recognition"); } }