!7 module TalkingSmiley > DynModule { transient JLabel lbl; transient int interval = 100; transient F0 rand; transient S code; transient volatile bool talking; transient S baseEmotion = "07"; int width = 300; enhanceFrame { dm_intFieldMenuItem(f, 'width, onSet := r refreshImage); } start { rand = f0_randomLL_differentEveryTime("01", "02", "03", "05"); dm_vmBus_onMessage('talking, r { talking = true; print("Talking"); }); dm_vmBus_onMessage('doneTalking, r { talking = false; print("Done talking"); }); } visualize { lbl = jimage(keriyo_resized_cached(code = baseEmotion, width)); componentPopupMenuItems(lbl, "Say something...", rThread { inputText("What should I say", f dm_say) }, "Select voice...", rThread { dm_showModule(dm_voiceOutputModule()) }); awtCalcEvery(lbl, interval, r { S newCode = talking ? rand! : baseEmotion; if (neq(newCode, code)) setImage(lbl, keriyo_resized_cached(code = newCode, width)); }); ret lbl; } void refreshImage enter { if (code != null && lbl != null) setImage(lbl, keriyo_resized_cached(code, width)); } }