public override void Fire() { Init(); //be sure to leave this here if (FindModuleByName("AudibleUKS") is ModuleUKS2 UKS) { SpeakPhrase(UKS); HandlePhonemes(UKS); if (GetNeuronValue("Word") == 1) { PruneWords(UKS); } if (GetNeuronValue("Phrase") == 1) { PrunePhrases(UKS); } if (GetNeuronValue("Stext") == 1) { currentText = UKS.AddThing("txt" + textCount++, UKS.Labeled("Text")); } if (GetNeuronValue("Etext") == 1) { currentText = null; } } }
//TODO add more properties to Stroke public Thing AddStrokeToUKS(PointPlus P1, PointPlus P2) { ModuleUKS uks = (ModuleUKS)FindModuleByType(typeof(ModuleUKS)); if (uks is ModuleUKS UKS) { if (uks.Labeled("AbsStroke") == null) { uks.AddThing("AbsStroke", "Visual"); } Thing t1 = uks.Valued(P1); if (t1 == null) { t1 = UKS.AddThing("p" + pCount++, new Thing[] { UKS.Labeled("Point") }, P1); } Thing t2 = uks.Valued(P2); if (t2 == null) { t2 = UKS.AddThing("p" + pCount++, new Thing[] { UKS.Labeled("Point") }, P2); } Thing newThing = UKS.AddThing("s" + strokeCount++, new Thing[] { UKS.Labeled("AbsStroke") }, null, new Thing[] { t1, t2 }); return(newThing); } return(null); }
public void SpeakThing(string label) { if (FindModuleByName("AudibleUKS") is ModuleUKS2 UKS) { if (UKS.Labeled(label) is Thing t) { SpeakThing(UKS, t); } } }
public void GetSegmentsFromUKS() { ModuleUKSN nmUKS = (ModuleUKSN)FindModuleByType(typeof(ModuleUKSN)); if (nmUKS is ModuleUKS UKS) { UKSSegments = UKS.Labeled("Segment").Children; UKSPoints = new List <Thing>(); if (UKS.Labeled("ModelThing") != null) { UKSPoints = UKS.Labeled("ModelThing").Children; } } }
public Thing AddSegmentToUKS(PointPlus P1, PointPlus P2, int theColor, PointPlus motion = null, bool addToModel = true) { ModuleUKS nmUKS = (ModuleUKSN)FindModuleByType(typeof(ModuleUKSN)); if (nmUKS is ModuleUKS UKS) { Thing t1, t2; Thing t3 = null; t1 = UKS.AddThing("p" + pCount++, new Thing[] { UKS.Labeled("Point") }, P1); t2 = UKS.AddThing("p" + pCount++, new Thing[] { UKS.Labeled("Point") }, P2); if (addToModel) { t1.AddParent(UKS.Labeled("ModelThing")); t2.AddParent(UKS.Labeled("ModelThing")); } if (motion != null) { t3 = UKS.AddThing("m" + mCount++, new Thing[] { UKS.Labeled("Motion") }, motion); } Thing color = UKS.Valued(theColor); if (color == null) { color = UKS.AddThing("c" + cCount++, new Thing[] { UKS.Labeled("Color") }, theColor); } Thing newThing = null; if (motion != null) { newThing = UKS.AddThing("s" + sCount++, new Thing[] { UKS.Labeled("Segment") }, null, new Thing[] { t1, t2, color, t3 }); } else { newThing = UKS.AddThing("s" + sCount++, new Thing[] { UKS.Labeled("Segment") }, null, new Thing[] { t1, t2, color }); } return(newThing); } return(null); }
public override void Fire() { Init(); //be sure to leave this here if (synth == null) { return; } if (GetNeuronValue("Cancel") == 1) { synth.SpeakAsyncCancelAll(); } if (GetNeuronValue("Validate") == 1) { if (!validating) { hitWords.Clear(); missWords.Clear(); missPhrase.Clear(); hit = 0; miss = 0; } validating = true; } else { if (validating) { if (hit + miss == 0) { Debug.WriteLine("No Validation Data"); } else { Debug.WriteLine("Validation: " + hit + " / " + miss + " = " + 100 * hit / (hit + miss)); Debug.WriteLine("Validation: " + hitWords.Count + " / " + missWords.Count + " = " + 100 * hitWords.Count / (hitWords.Count + missWords.Count)); } } validating = false; } bool paused = true; for (int i = 3; i < na.NeuronCount; i++) { Neuron n = na.GetNeuronAt(i); if (n.Fired()) { if (n.Label.Length == 1) { phraseToSpeak += n.Label; paused = false; } if (n.Synapses.Count == 0) { //connect it to the knowledge store //connection to KB //ModuleUKS2 nmKB = (ModuleUKS2)FindModuleByName("AudibleUKS"); if (FindModuleByName("AudibleUKS") is ModuleUKS2 UKS) { string label = "pn" + n.Label; List <Thing> phonemes = UKS.Labeled("Phoneme").Children; Thing pn = UKS.Labeled(label, phonemes); if (pn == null) //this should always be null { pn = UKS.AddThing(label, new Thing[] { UKS.Labeled("Phoneme") }, pn); } Neuron n1 = UKS.GetNeuron(pn); Neuron n2 = UKS.GetNeuron(pn, false); if (n1 != null) { n.AddSynapse(n1.Id, 1); n1.SetValue(1); n2.AddSynapse(n.Id, 1); } } } } } if (phonemesToFire != "") { char c = phonemesToFire[0]; bool fired = false; if (c != ' ') { for (int i = 0; i < na.NeuronCount; i++) { Neuron n = na.GetNeuronAt(i); if (n.Label == c.ToString()) { n.SetValue(1); fired = true; break; } } if (!fired) { Neuron n = AddLabel(c.ToString()); //connect it to the knowledge store //connection to KB //ModuleUKS2 nmKB = (ModuleUKS2)FindModuleByName("AudibleUKS"); if (FindModuleByName("AudibleUKS") is ModuleUKS2 UKS) { string label = "pn" + n.Label; List <Thing> phonemes = UKS.Labeled("Phoneme").Children; Thing pn = UKS.Labeled(label, phonemes); if (pn == null) //this should always be null { pn = UKS.AddThing(label, new Thing[] { UKS.Labeled("Phoneme") }, pn); } Neuron n1 = UKS.GetNeuron(pn); Neuron n2 = UKS.GetNeuron(pn, false); if (n1 != null) { n.AddSynapse(n1.Id, 1); n2.AddSynapse(n.Id, 1); n.SetValue(1); } } } } phonemesToFire = phonemesToFire.Substring(1); } if (paused && phraseToSpeak != "") { if (dlg != null) { ((ModuleSpeakPhonemes2Dlg)dlg).SetLabel(phraseToSpeak); } if (na.GetNeuronAt("Enable").Fired()) { ModuleSpeechIn msi = (ModuleSpeechIn)FindModuleByType(typeof(ModuleSpeechIn)); if (msi != null) { msi.PauseRecognition(); //if there is a recognizer active } //synth.SpeakAsync(phraseToSpeak + "."); //phraseToSpeak = ""; PromptBuilder pb1 = new PromptBuilder(); if (typedIn) { pb1.StartVoice("Microsoft David Desktop"); pb1.StartStyle(new PromptStyle(PromptRate.Medium)); } else { pb1.StartVoice("Microsoft Zira Desktop"); pb1.StartStyle(new PromptStyle(PromptRate.Slow)); } pb1.AppendTextWithPronunciation("not used", phraseToSpeak.Trim()); pb1.EndStyle(); pb1.EndVoice(); string x = pb1.ToXml(); Debug.WriteLine(debugString(phraseToSpeak)); //synth.Speak(pb1); synth.SpeakAsync(pb1); } //string heard = GetPronunciationFromText("", phraseToSpeak); //it would be nice to hear what was said but it doesn't work with this engine phraseToSpeak = ""; typedIn = false; } }